### Install Chatify Package Source: https://context7.com/munafio/chatify/llms.txt Install Chatify using Composer and run the setup command to publish assets. Then, run migrations to create necessary database tables. ```bash composer require munafio/chatify php artisan chatify:install php artisan migrate ``` -------------------------------- ### Install Chatify Artisan Command Source: https://context7.com/munafio/chatify/llms.txt Run this Artisan command for a full installation of Chatify, which includes publishing assets and linking storage. ```bash # Full installation (publishes all assets, runs storage:link) php artisan chatify:install ``` -------------------------------- ### Define Custom Web Routes for Chatify Source: https://context7.com/munafio/chatify/llms.txt Example of defining custom web routes in routes/chatify/web.php. This allows you to override the default routes provided by the Chatify package. ```php use Illuminate\Support\Facades\Route; Route::get('/', 'MessagesController@index')->name('chatify'); Route::post('/sendMessage', 'MessagesController@send')->name('send.message'); // ... add remaining routes as needed ``` -------------------------------- ### Get Shared Photos (API) Source: https://context7.com/munafio/chatify/llms.txt Fetch a list of shared photos with a specific user. The response contains an array of photo filenames. ```bash # Get shared photos curl -X POST https://yourapp.com/chatify/api/shared \ -H "Authorization: Bearer {token}" \ -d '{"user_id": 42}' # Response: { "shared": ["uuid1.jpg", "uuid2.png"] } ``` -------------------------------- ### Get Storage URLs for Avatars and Attachments Source: https://context7.com/munafio/chatify/llms.txt Provides public URLs for user avatars and message attachments stored on the configured disk. Also allows direct access to the storage disk for operations like checking existence or deletion. ```php // User avatar $url = Chatify::getUserAvatarUrl('uuid-avatar.png'); // → "https://yourapp.com/storage/users-avatar/uuid-avatar.png" // Message attachment $url = Chatify::getAttachmentUrl('uuid-document.zip'); // → "https://yourapp.com/storage/attachments/uuid-document.zip" // Direct storage access $disk = Chatify::storage(); // Storage::disk('public') $exists = $disk->exists('attachments/uuid-document.zip'); $disk->delete('attachments/uuid-document.zip'); ``` -------------------------------- ### Get Favorites (API) Source: https://context7.com/munafio/chatify/llms.txt Retrieve a list of the user's favorited contacts. The response includes the total number of favorites. ```bash # Get favorites curl -X POST https://yourapp.com/chatify/api/favorites \ -H "Authorization: Bearer {token}" # Response: { "total": 2, "favorites": [...] } ``` -------------------------------- ### Get Contacts Source: https://context7.com/munafio/chatify/llms.txt Retrieves a paginated list of user contacts. ```APIDOC ## GET /chatify/api/getContacts ### Description Retrieves a paginated list of user contacts. ### Method GET ### Endpoint /chatify/api/getContacts ### Parameters #### Query Parameters - **per_page** (integer) - Optional - The number of contacts to retrieve per page. Defaults to 30. ### Response #### Success Response (200) - **contacts** (array) - An array of contact objects. - **total** (integer) - Total number of contacts. - **last_page** (integer) - The last page number. ``` -------------------------------- ### Get Shared Photos Between Users Source: https://context7.com/munafio/chatify/llms.txt Retrieves a list of filenames for image attachments shared between the authenticated user and a specified user. Iterates through the filenames to get their URLs and display them. ```php $photos = Chatify::getSharedPhotos(42); // ['uuid1.jpg', 'uuid2.png', ...] foreach ($photos as $filename) { $url = Chatify::getAttachmentUrl($filename); echo ''; } ``` -------------------------------- ### Get Paginated Contacts (API) Source: https://context7.com/munafio/chatify/llms.txt Retrieve a paginated list of user contacts. You can specify the number of contacts per page. ```bash # Get paginated contacts curl -X GET "https://yourapp.com/chatify/api/getContacts?per_page=30" \ -H "Authorization: Bearer {token}" # Response: # { "contacts": [...], "total": 15, "last_page": 1 } ``` -------------------------------- ### Get Favorites Source: https://context7.com/munafio/chatify/llms.txt Retrieves a list of the user's favorited contacts. ```APIDOC ## POST /chatify/api/favorites ### Description Retrieves a list of the user's favorited contacts. ### Method POST ### Endpoint /chatify/api/favorites ### Response #### Success Response (200) - **total** (integer) - Total number of favorited contacts. - **favorites** (array) - An array of favorited contact objects. ``` -------------------------------- ### Get Shared Photos Source: https://context7.com/munafio/chatify/llms.txt Retrieves a list of shared photos with a specific user. ```APIDOC ## POST /chatify/api/shared ### Description Retrieves a list of shared photos with a specific user. ### Method POST ### Endpoint /chatify/api/shared ### Parameters #### Request Body - **user_id** (integer) - Required - The ID of the user to retrieve shared photos with. ### Response #### Success Response (200) - **shared** (array) - An array of filenames for shared photos. ``` -------------------------------- ### Get Last Message in Conversation Source: https://context7.com/munafio/chatify/llms.txt Retrieves the most recent `ChMessage` model between the authenticated user and a specified user. Returns `null` if no messages exist in the conversation. ```php $last = Chatify::getLastMessageQuery(42); if ($last) { echo $last->body; echo $last->created_at->diffForHumans(); // "3 minutes ago" } ``` -------------------------------- ### Chatify Configuration - config/chatify.php Source: https://context7.com/munafio/chatify/llms.txt Key configuration options for Chatify, including storage disk, route prefixes, middleware, Pusher credentials, avatar settings, and attachment limits. ```php // config/chatify.php (key sections) return [ 'name' => env('CHATIFY_NAME', 'Chatify Messenger'), 'storage_disk_name' => env('CHATIFY_STORAGE_DISK', 'public'), 'routes' => [ 'custom' => env('CHATIFY_CUSTOM_ROUTES', false), 'prefix' => env('CHATIFY_ROUTES_PREFIX', 'chatify'), // → /chatify/* 'middleware' => env('CHATIFY_ROUTES_MIDDLEWARE', ['web','auth']), ], 'api_routes' => [ 'prefix' => env('CHATIFY_API_ROUTES_PREFIX', 'chatify/api'), // → /chatify/api/* 'middleware' => env('CHATIFY_API_ROUTES_MIDDLEWARE', ['api']), ], 'pusher' => [ 'key' => env('PUSHER_APP_KEY'), 'secret' => env('PUSHER_APP_SECRET'), 'app_id' => env('PUSHER_APP_ID'), 'options' => [ 'cluster' => env('PUSHER_APP_CLUSTER', 'mt1'), 'encrypted' => true, 'useTLS' => true, ], ], 'user_avatar' => [ 'folder' => 'users-avatar', 'default' => 'avatar.png', ], 'gravatar' => [ 'enabled' => true, 'image_size' => 200, 'imageset' => 'identicon', // 404 | mp | identicon | monsterid | wavatar ], 'attachments' => [ 'folder' => 'attachments', 'allowed_images' => ['png','jpg','jpeg','gif'], 'allowed_files' => ['zip','rar','txt'], 'max_upload_size' => env('CHATIFY_MAX_FILE_SIZE', 150), // MB ], 'colors' => ['#2180f3','#2196F3','#00BCD4','#3F51B5','#673AB7', '#4CAF50','#FFC107','#FF9800','#ff2522','#9C27B0'], 'sounds' => [ 'enabled' => true, 'public_path' => 'sounds/chatify', 'new_message' => 'new-message-sound.mp3', ], ]; ``` -------------------------------- ### Publish Chatify Assets Source: https://context7.com/munafio/chatify/llms.txt Use these commands to selectively publish specific assets from the Chatify package. Each command publishes a different category of assets. ```bash php artisan vendor:publish --tag=chatify-config ``` ```bash php artisan vendor:publish --tag=chatify-migrations ``` ```bash php artisan vendor:publish --tag=chatify-models ``` ```bash php artisan vendor:publish --tag=chatify-controllers ``` ```bash php artisan vendor:publish --tag=chatify-views ``` ```bash php artisan vendor:publish --tag=chatify-assets ``` ```bash php artisan vendor:publish --tag=chatify-routes ``` -------------------------------- ### Publish Chatify Assets (v1.2.3 and earlier) Source: https://github.com/munafio/chatify/blob/master/UPGRADE.md Use these commands to re-publish Chatify's views and assets for older versions. Replace 'NAME' with other asset types if needed. ```bash php artisan vendor:publish --tag=chatify-views --force ``` ```bash php artisan vendor:publish --tag=chatify-assets --force ``` -------------------------------- ### Publish All Chatify Assets (v1.2.4+) Source: https://github.com/munafio/chatify/blob/master/UPGRADE.md Use this command for versions 1.2.4 and higher to re-publish all assets, including views, assets, and configuration. This will overwrite existing changes. ```bash php artisan chatify:publish --force ``` -------------------------------- ### Publish Chatify Views & Assets (v1.2.4+) Source: https://github.com/munafio/chatify/blob/master/UPGRADE.md This command is used for versions 1.2.4 and higher to re-publish only the views and assets. ```bash php artisan chatify:publish ``` -------------------------------- ### Update Settings (API) Source: https://context7.com/munafio/chatify/llms.txt Update user settings such as dark mode, messenger color, or avatar. Use multipart/form-data for avatar uploads. ```bash # Update settings (dark mode, color, avatar) curl -X POST https://yourapp.com/chatify/api/updateSettings \ -H "Authorization: Bearer {token}" \ -F "dark_mode=dark" \ -F "messengerColor=#673AB7" \ -F "avatar=@/path/to/new-avatar.png" # Response: { "status": 1, "error": 0, "message": 0 } ``` -------------------------------- ### Configure Custom Routes for Chatify Source: https://context7.com/munafio/chatify/llms.txt Set CHATIFY_CUSTOM_ROUTES to true in your .env file to use custom route files. Configure prefixes and middleware for both web and API routes. ```dotenv CHATIFY_CUSTOM_ROUTES=true CHATIFY_ROUTES_PREFIX=chat CHATIFY_ROUTES_MIDDLEWARE=web,auth,verified CHATIFY_API_ROUTES_PREFIX=api/chat CHATIFY_API_ROUTES_MIDDLEWARE=api,auth:sanctum ``` -------------------------------- ### Search Users (API) Source: https://context7.com/munafio/chatify/llms.txt Search for users by name. Specify the search input and the number of results per page. ```bash # Search users curl -X GET "https://yourapp.com/chatify/api/search?input=john&per_page=10" \ -H "Authorization: Bearer {token}" # Response: # { "records": [...], "total": 3, "last_page": 1 } ``` -------------------------------- ### Render Contact List Item HTML Source: https://context7.com/munafio/chatify/llms.txt Renders the HTML for a contact list item, including the user's avatar, name, the last message preview, and an unseen message count badge. Requires a `User` model instance. ```php use App\Models\User; $user = User::find(42); $html = Chatify::getContactItem($user); // Returns rendered HTML of Chatify::layouts.listItem view // Includes: avatar, name, last message body/time, unseen count badge ``` -------------------------------- ### Download Attachment (API) Source: https://context7.com/munafio/chatify/llms.txt Stream and download an attachment using its filename. The response provides the file name and a download path. ```bash # Download an attachment URL curl -X GET https://yourapp.com/chatify/api/download/uuid-filename.pdf \ -H "Authorization: Bearer {token}" # Response: { "file_name": "uuid-filename.pdf", "download_path": "https://..." } ``` -------------------------------- ### Create a New Message with Chatify Source: https://context7.com/munafio/chatify/llms.txt Persists a new message record to the `ch_messages` table. Ensure `from_id`, `to_id`, and `body` are provided. Attachments can be included as a JSON-encoded string. ```php use Chatify\Facades\ChatifyMessenger as Chatify; $message = Chatify::newMessage([ 'from_id' => auth()->id(), // sender 'to_id' => 42, // recipient user ID 'body' => 'Hello, world!', // message text (HTML-encoded before storing) 'attachment' => json_encode([ 'new_name' => 'uuid-filename.jpg', 'old_name' => 'photo.jpg', ]), ]); // $message is a ChMessage model instance echo $message->id; // UUID primary key echo $message->from_id; // sender ID echo $message->to_id; // recipient ID ``` -------------------------------- ### Send Message with File Attachment (API) Source: https://context7.com/munafio/chatify/llms.txt This endpoint allows sending a message along with a file attachment. Use multipart/form-data encoding for file uploads. ```bash # Send a message with file attachment curl -X POST https://yourapp.com/chatify/api/sendMessage \ -H "Authorization: Bearer {token}" \ -F "id=42" \ -F "message=See attached" \ -F "temporaryMsgId=tmp-2" \ -F "file=@/path/to/photo.jpg" ``` -------------------------------- ### Send Message (with File Attachment) Source: https://context7.com/munafio/chatify/llms.txt Sends a message to a specified user, including a file attachment. ```APIDOC ## POST /chatify/api/sendMessage (with File) ### Description Sends a message to a specified user, including a file attachment. ### Method POST ### Endpoint /chatify/api/sendMessage ### Parameters #### Request Body (Form Data) - **id** (integer) - Required - The ID of the recipient user. - **message** (string) - Optional - The text content of the message. - **temporaryMsgId** (string) - Optional - A temporary ID for the message. - **file** (file) - Required - The file attachment to send. ``` -------------------------------- ### Update Settings Source: https://context7.com/munafio/chatify/llms.txt Updates user settings such as avatar, dark mode, and messenger color. ```APIDOC ## POST /chatify/api/updateSettings ### Description Updates user settings including avatar, dark mode, and messenger color. ### Method POST ### Endpoint /chatify/api/updateSettings ### Parameters #### Request Body (Form Data) - **dark_mode** (string) - Optional - Set to 'dark' to enable dark mode. - **messengerColor** (string) - Optional - The hex code for the messenger color. - **avatar** (file) - Optional - The new avatar image file. ``` -------------------------------- ### Set Active Status (API) Source: https://context7.com/munafio/chatify/llms.txt Set the user's online or offline status. A status of 1 indicates online, and 0 indicates offline. ```bash # Set active status curl -X POST https://yourapp.com/chatify/api/setActiveStatus \ -H "Authorization: Bearer {token}" \ -d '{"status": 1}' # Response: { "status": 1 } ``` -------------------------------- ### Web Routes for Chatify Source: https://context7.com/munafio/chatify/llms.txt These routes are designed to return rendered HTML for the Chatify messenger interface. They are registered under the 'web' and 'auth' middleware groups. ```text GET /chatify/ → Messenger main page (MessagesController@index) GET /chatify/{id} → Open conversation with user {id} GET /chatify/group/{id} → Open group conversation (route name: group) POST /chatify/idInfo → Fetch user info + favorite status POST /chatify/sendMessage → Send a text/file message POST /chatify/fetchMessages → Paginated conversation messages (HTML cards) POST /chatify/makeSeen → Mark messages from a user as seen GET /chatify/getContacts → Paginated contact list (HTML) POST /chatify/updateContacts → Refresh a single contact item (HTML) POST /chatify/star → Toggle favorite POST /chatify/favorites → Get favorites list (HTML) GET /chatify/search → Search users by name (HTML) POST /chatify/shared → Get shared photos (HTML thumbnails) POST /chatify/deleteConversation → Delete full conversation POST /chatify/deleteMessage → Delete a single message POST /chatify/updateSettings → Update avatar / dark mode / messenger color POST /chatify/setActiveStatus → Set user online/offline status GET /chatify/download/{fileName} → Stream-download an attachment POST /chatify/chat/auth → Pusher private channel authentication ``` -------------------------------- ### Check and Toggle User Favorites Source: https://context7.com/munafio/chatify/llms.txt Provides methods to check if a user is in the authenticated user's favorites list (`inFavorite`) and to add or remove them (`makeInFavorite`). The `makeInFavorite` method uses a second argument: `1` to star, `0` to unstar. ```php // Check favorite status $isFav = Chatify::inFavorite(42); // true or false // Add to favorites ($action > 0 = star, 0 = unstar) Chatify::makeInFavorite(42, 1); // star Chatify::makeInFavorite(42, 0); // unstar // Typical toggle pattern: $newStatus = Chatify::inFavorite(42) ? 0 : 1; Chatify::makeInFavorite(42, $newStatus); // Response: { "status": 1 } (1 = now favorited, 0 = now unfavorited) ``` -------------------------------- ### Mark Messages as Seen Source: https://context7.com/munafio/chatify/llms.txt Marks all messages from a specific user as seen. ```APIDOC ## POST /chatify/api/makeSeen ### Description Marks all messages from a specific user as seen. ### Method POST ### Endpoint /chatify/api/makeSeen ### Parameters #### Request Body - **id** (integer) - Required - The ID of the user whose messages should be marked as seen. ### Response #### Success Response (200) - **status** (integer) - Indicates success (1) or failure (0). ``` -------------------------------- ### push Source: https://context7.com/munafio/chatify/llms.txt Triggers a Pusher event on a specified private channel to enable real-time delivery of data to recipients. ```APIDOC ## `Chatify::push($channel, $event, $data)` — Trigger Pusher Event Triggers a Pusher event on a private channel for real-time delivery to the recipient. ### Method `Chatify::push(string $channel, string $event, array $data)` ### Parameters #### Path Parameters - **channel** (string) - Required - The name of the private Pusher channel (e.g., `private-chatify.1`). - **event** (string) - Required - The name of the event to trigger (e.g., `messaging`, `seen`, `typing`, `activeStatus`). - **data** (array) - Required - The data payload to send with the event. ### Example ```php // Trigger a real-time message event on the recipient's private channel Chatify::push( 'private-chatify.' . $recipientId, // private Pusher channel 'messaging', // event name [ 'from_id' => auth()->id(), 'to_id' => $recipientId, 'message' => Chatify::messageCard($messageData, true), ] ); // Other real-time events fired by the package: // 'messaging' → new incoming message // 'seen' → message seen notification // 'typing' → typing indicator // 'activeStatus' → user online/offline ``` ``` -------------------------------- ### Chatify::makeSeen($user_id) Source: https://context7.com/munafio/chatify/llms.txt Marks all messages from the given user (to the authenticated user) as seen (`seen = 1`). This is typically called when a conversation is opened. ```APIDOC ## `Chatify::makeSeen($user_id)` — Mark Conversation as Seen Marks all messages from the given user (to the authenticated user) as seen (`seen = 1`). ### Parameters - **user_id** (int) - Required - The ID of the user whose messages should be marked as seen. ### Returns - **int** - Returns 1 on success. ### Example ```php // Mark all messages from user 42 as seen by the auth user $result = Chatify::makeSeen(42); // returns 1 on success ``` ``` -------------------------------- ### Chatify::getContactItem($user) Source: https://context7.com/munafio/chatify/llms.txt Renders the contact list item HTML, including the last message preview and unseen message badge, for a given User model. ```APIDOC ## `Chatify::getContactItem($user)` — Render Contact List Item Renders the contact list item HTML (last message preview + unseen badge) for a given User model. ### Parameters - **user** (User) - Required - The User model instance. ### Returns - **string** - The rendered HTML for the contact list item. ### Example ```php use App\Models\User; $user = User::find(42); $html = Chatify::getContactItem($user); // Returns rendered HTML of Chatify::layouts.listItem view ``` ``` -------------------------------- ### Mark Messages as Seen (API) Source: https://context7.com/munafio/chatify/llms.txt Mark all messages from a specific user as seen. This endpoint expects the user ID in the request body. ```bash # Mark messages as seen curl -X POST https://yourapp.com/chatify/api/makeSeen \ -H "Authorization: Bearer {token}" \ -d '{"id": 42}' # Response: { "status": 1 } ``` -------------------------------- ### Chatify::messageCard($data, $renderDefaultCard) Source: https://context7.com/munafio/chatify/llms.txt Renders the `Chatify::layouts.messageCard` Blade view as an HTML string for injection into the messenger UI. It can render as sender's or receiver's card. ```APIDOC ## `Chatify::messageCard($data, $renderDefaultCard)` — Render Message Blade Card Renders the `Chatify::layouts.messageCard` Blade view as an HTML string for injection into the messenger UI. ### Parameters - **data** (array) - Required - The parsed message data array, typically from `Chatify::parseMessage()`. - **renderDefaultCard** (bool) - Optional - If true, forces rendering as a receiver's message card (isSender = false). Defaults to false. ### Returns - **string** - The rendered HTML string of the message card, or an empty string if `$data` is falsy. ### Example ```php $messageData = Chatify::parseMessage($message); // Render as sender's message card $html = Chatify::messageCard($messageData); // Render as receiver's message card $html = Chatify::messageCard($messageData, true); // Returns empty string if $data is falsy $html = Chatify::messageCard(null); // → '' ``` ``` -------------------------------- ### Mark Conversation as Seen Source: https://context7.com/munafio/chatify/llms.txt Marks all messages from a specified user (sent to the authenticated user) as seen. This typically returns `1` on success and is often called when a conversation is opened. ```php // Mark all messages from user 42 as seen by the auth user $result = Chatify::makeSeen(42); // returns 1 on success // Typically called when opening a conversation: // POST /chatify/makeSeen { id: 42 } // Response: { "status": 1 } ``` -------------------------------- ### Send Text Message (API) Source: https://context7.com/munafio/chatify/llms.txt Use this endpoint to send a text-only message to a user. Include a temporary message ID for optimistic UI updates. ```bash # Send a message (text only) curl -X POST https://yourapp.com/chatify/api/sendMessage \ -H "Authorization: Bearer {token}" \ -H "Content-Type: application/json" \ -d '{"id": 42, "message": "Hello!", "temporaryMsgId": "tmp-1"}' # Response: # { "status": "200", "error": {"status":0,"message":null}, "message": {...}, "tempID": "tmp-1" } ``` -------------------------------- ### Fetch Paginated Messages (API) Source: https://context7.com/munafio/chatify/llms.txt Retrieve a paginated list of messages for a specific conversation. The response includes total messages, last page, and the last message ID. ```bash # Fetch paginated messages curl -X POST https://yourapp.com/chatify/api/fetchMessages \ -H "Authorization: Bearer {token}" \ -d '{"id": 42, "per_page": 30}' # Response: # { "total": 120, "last_page": 4, "last_message_id": "uuid", "messages": [...] } ``` -------------------------------- ### Download Attachment Source: https://context7.com/munafio/chatify/llms.txt Streams and downloads an attachment file. ```APIDOC ## GET /chatify/api/download/{fileName} ### Description Streams and downloads an attachment file. ### Method GET ### Endpoint /chatify/api/download/{fileName} ### Parameters #### Path Parameters - **fileName** (string) - Required - The name of the file to download. ### Response #### Success Response (200) - **file_name** (string) - The name of the downloaded file. - **download_path** (string) - The URL to download the file from. ``` -------------------------------- ### pusherAuth Source: https://context7.com/munafio/chatify/llms.txt Authenticates a user for subscription to a Pusher private channel, returning a socket auth token or an error response. ```APIDOC ## `Chatify::pusherAuth($requestUser, $authUser, $channelName, $socketId)` — Pusher Channel Auth Authenticates a user for a Pusher private channel subscription. Returns the Pusher socket auth token or a JSON error response. ### Method `Chatify::pusherAuth(object $requestUser, object $authUser, string $channelName, string $socketId)` ### Parameters #### Path Parameters - **requestUser** (object) - Required - The user making the request. - **authUser** (object) - Required - The authenticated user. - **channelName** (string) - Required - The name of the channel the user is trying to subscribe to. - **socketId** (string) - Required - The socket ID provided by Pusher. ### Response - Returns the Pusher socket auth string if user IDs match. - Returns a `401` or `403` JSON error response otherwise. ### Example ```php // In a controller (handled automatically by the package's routes): // POST /chatify/chat/auth { channel_name: "private-chatify.1", socket_id: "xxx" } $auth = Chatify::pusherAuth( $request->user(), // requesting user Auth::user(), // authenticated user $request->channel_name, $request->socket_id ); // Returns pusher socket_auth string if IDs match, 401/403 JSON otherwise ``` ``` -------------------------------- ### Fetch Messages Source: https://context7.com/munafio/chatify/llms.txt Retrieves paginated messages for a conversation. ```APIDOC ## POST /chatify/api/fetchMessages ### Description Fetches paginated messages for a conversation with a specific user. ### Method POST ### Endpoint /chatify/api/fetchMessages ### Parameters #### Request Body - **id** (integer) - Required - The ID of the user whose messages are to be fetched. - **per_page** (integer) - Optional - The number of messages to retrieve per page. Defaults to 30. ### Request Example ```json { "id": 42, "per_page": 30 } ``` ### Response #### Success Response (200) - **total** (integer) - Total number of messages. - **last_page** (integer) - The last page number. - **last_message_id** (string) - The ID of the last message. - **messages** (array) - An array of message objects. ``` -------------------------------- ### Pusher Channel Authentication Source: https://context7.com/munafio/chatify/llms.txt Authenticates a private Pusher channel. ```APIDOC ## POST /chatify/chat/auth ### Description Authenticates a private Pusher channel for real-time communication. ### Method POST ### Endpoint /chatify/chat/auth ### Parameters #### Request Body (This endpoint typically expects specific parameters from the Pusher client library for authentication, such as socket_id and channel_name. Refer to Pusher documentation for exact requirements.) ### Response (The response format depends on Pusher's authentication requirements. It usually involves a JSON response with authentication details.) ``` -------------------------------- ### Authenticate Pusher Channel Subscription Source: https://context7.com/munafio/chatify/llms.txt Authenticates a user attempting to subscribe to a private Pusher channel. Typically handled automatically by the package's routes, it returns a Pusher socket auth token or a JSON error response. ```php // In a controller (handled automatically by the package's routes): // POST /chatify/chat/auth { channel_name: "private-chatify.1", socket_id: "xxx" } $auth = Chatify::pusherAuth( $request->user(), // requesting user Auth::user(), // authenticated user $request->channel_name, $request->socket_id ); // Returns pusher socket_auth string if IDs match, 401/403 JSON otherwise ``` -------------------------------- ### Manage Message Read/Unread State with ChMessage Model Source: https://context7.com/munafio/chatify/llms.txt Utilize the `ChMessage` model's instance methods and query scopes to manage the read/unread status of individual messages or collections of messages. ```php use App\Models\ChMessage; // Mark a single message as read $message = ChMessage::find('uuid-here'); $message->markAsRead(); // sets seen = 1 (no-op if already read) $message->markAsUnread(); // sets seen = 0 (no-op if already unread) // Check state $message->read(); // true → seen != 0 $message->unread(); // true → seen == 0 // Query scopes $unread = ChMessage::unread()->where('to_id', auth()->id())->get(); $read = ChMessage::read()->where('to_id', auth()->id())->get(); // Bulk operations via MessageCollection $messages = ChMessage::where('to_id', auth()->id())->get(); // returns MessageCollection $messages->markAsRead(); // marks every message in the collection as read $messages->markAsUnread(); // marks every message in the collection as unread ``` -------------------------------- ### Resolve User Avatar URL Source: https://context7.com/munafio/chatify/llms.txt Determines the correct avatar URL for a user, prioritizing Gravatar if enabled and the default avatar is used, otherwise returning the stored file URL. Requires the User model and Chatify facade. ```php use App\Models\User; $user = User::find(42); $userWithAvatar = Chatify::getUserWithAvatar($user); echo $userWithAvatar->avatar; // e.g. "https://www.gravatar.com/avatar/abc123?s=200&d=identicon" // or "https://yourapp.com/storage/users-avatar/uuid.jpg" ``` -------------------------------- ### Toggle Favorite (API) Source: https://context7.com/munafio/chatify/llms.txt Toggle the favorite status for a user. The response indicates whether the user has been favorited (1) or unfavorited (0). ```bash # Toggle favorite curl -X POST https://yourapp.com/chatify/api/star \ -H "Authorization: Bearer {token}" \ -d '{"user_id": 42}' # Response: { "status": 1 } (1 = favorited, 0 = unfavorited) ``` -------------------------------- ### Chatify::fetchMessagesQuery($user_id) Source: https://context7.com/munafio/chatify/llms.txt Returns an Eloquent query builder scoped to all messages exchanged between the authenticated user and the given user ID. Allows for custom querying and pagination. ```APIDOC ## `Chatify::fetchMessagesQuery($user_id)` — Conversation Query Builder Returns an Eloquent query builder scoped to all messages exchanged between the authenticated user and the given user ID. ### Parameters - **user_id** (int) - Required - The ID of the other user in the conversation. ### Returns - **Eloquent Query Builder** - A query builder instance for messages between the two users. ### Example ```php // All messages between auth user and user 42 $query = Chatify::fetchMessagesQuery(42); // Paginate 30 per page, newest first $messages = $query->latest()->paginate(30); foreach ($messages as $msg) { echo $msg->body; } ``` ``` -------------------------------- ### Chatify::newMessage($data) Source: https://context7.com/munafio/chatify/llms.txt Persists a new message record to the `ch_messages` table and returns the model instance. It requires sender ID, recipient ID, message body, and optionally attachment details. ```APIDOC ## `Chatify::newMessage($data)` — Create a Message Persists a new message record to the `ch_messages` table and returns the model instance. ### Parameters - **data** (array) - Required - An array containing message details: - **from_id** (int) - Required - The ID of the sender. - **to_id** (int) - Required - The ID of the recipient. - **body** (string) - Required - The message text (HTML-encoded). - **attachment** (json|null) - Optional - JSON encoded attachment details if any. ### Returns - **ChMessage** - The newly created message model instance. ### Example ```php use Chatify\Facades\ChatifyMessenger as Chatify; $message = Chatify::newMessage([ 'from_id' => auth()->id(), // sender 'to_id' => 42, // recipient user ID 'body' => 'Hello, world!', // message text (HTML-encoded before storing) 'attachment' => json_encode([ 'new_name' => 'uuid-filename.jpg', 'old_name' => 'photo.jpg', ]), ]); echo $message->id; ``` ``` -------------------------------- ### Search Users Source: https://context7.com/munafio/chatify/llms.txt Searches for users by name. ```APIDOC ## GET /chatify/api/search ### Description Searches for users by name. ### Method GET ### Endpoint /chatify/api/search ### Parameters #### Query Parameters - **input** (string) - Required - The search term (user name). - **per_page** (integer) - Optional - The number of results to retrieve per page. Defaults to 10. ### Response #### Success Response (200) - **records** (array) - An array of user records matching the search. - **total** (integer) - Total number of matching users. - **last_page** (integer) - The last page number. ``` -------------------------------- ### Toggle Favorite Source: https://context7.com/munafio/chatify/llms.txt Toggles the favorite status of a user. ```APIDOC ## POST /chatify/api/star ### Description Toggles the favorite status of a user. ### Method POST ### Endpoint /chatify/api/star ### Parameters #### Request Body - **user_id** (integer) - Required - The ID of the user to toggle favorite status for. ### Response #### Success Response (200) - **status** (integer) - 1 if the user is now favorited, 0 if unfavorited. ``` -------------------------------- ### getUserWithAvatar Source: https://context7.com/munafio/chatify/llms.txt Resolves the correct avatar URL for a user, prioritizing Gravatar if enabled and applicable, otherwise using the stored file URL. ```APIDOC ## `Chatify::getUserWithAvatar($user)` — Resolve User Avatar URL Resolves the correct avatar URL for a user: Gravatar (if avatar is the default and Gravatar is enabled) or the stored file URL. ### Method `Chatify::getUserWithAvatar(object $user)` ### Parameters #### Path Parameters - **user** (object) - Required - The user object, expected to have an `avatar` property. ### Response - Returns the user object with an appended `avatar` property containing the resolved avatar URL. ### Example ```php use App\Models\User; $user = User::find(42); $userWithAvatar = Chatify::getUserWithAvatar($user); echo $userWithAvatar->avatar; // e.g. "https://www.gravatar.com/avatar/abc123?s=200&d=identicon" // or "https://yourapp.com/storage/users-avatar/uuid.jpg" ``` ``` -------------------------------- ### Render Message Card HTML Source: https://context7.com/munafio/chatify/llms.txt Renders the `Chatify::layouts.messageCard` Blade view as an HTML string. Use this to inject message UI elements into your messenger interface. Can optionally force the message to be rendered as if sent by the receiver. ```php $messageData = Chatify::parseMessage($message); // Render as sender's message card $html = Chatify::messageCard($messageData); // Render as receiver's message card (forces isSender = false) $html = Chatify::messageCard($messageData, true); // Returns empty string if $data is falsy $html = Chatify::messageCard(null); // → '' ``` -------------------------------- ### Set Active Status Source: https://context7.com/munafio/chatify/llms.txt Sets the user's online/offline status. ```APIDOC ## POST /chatify/api/setActiveStatus ### Description Sets the user's online/offline status. ### Method POST ### Endpoint /chatify/api/setActiveStatus ### Parameters #### Request Body - **status** (integer) - Required - 1 to set status to online, 0 to set to offline. ### Response #### Success Response (200) - **status** (integer) - Indicates success (1) or failure (0). ``` -------------------------------- ### Trigger Pusher Event Source: https://context7.com/munafio/chatify/llms.txt Sends a real-time event to a specified private Pusher channel. Used for delivering messages, seen notifications, typing indicators, and online/offline status updates. ```php // Trigger a real-time message event on the recipient's private channel Chatify::push( 'private-chatify.' . $recipientId, // private Pusher channel 'messaging', // event name [ 'from_id' => auth()->id(), 'to_id' => $recipientId, 'message' => Chatify::messageCard($messageData, true), ] ); // Other real-time events fired by the package: // 'messaging' → new incoming message // 'seen' → message seen notification // 'typing' → typing indicator // 'activeStatus' → user online/offline ``` -------------------------------- ### getUserAvatarUrl / getAttachmentUrl Source: https://context7.com/munafio/chatify/llms.txt Provides the public URL for user avatar or message attachment files stored on the configured disk. ```APIDOC ## `Chatify::getUserAvatarUrl($filename)` / `getAttachmentUrl($filename)` — Storage URLs Returns the public URL for a user avatar or attachment file stored on the configured disk. ### Methods - `Chatify::getUserAvatarUrl(string $filename)` - `Chatify::getAttachmentUrl(string $filename)` ### Parameters #### Path Parameters - **filename** (string) - Required - The name of the file (avatar or attachment) for which to get the URL. ### Response - Returns the public URL of the specified file. ### Examples ```php // User avatar $url = Chatify::getUserAvatarUrl('uuid-avatar.png'); // → "https://yourapp.com/storage/users-avatar/uuid-avatar.png" // Message attachment $url = Chatify::getAttachmentUrl('uuid-document.zip'); // → "https://yourapp.com/storage/attachments/uuid-document.zip" // Direct storage access $disk = Chatify::storage(); // Storage::disk('public') $exists = $disk->exists('attachments/uuid-document.zip'); $disk->delete('attachments/uuid-document.zip'); ``` ``` -------------------------------- ### Fetch Conversation Messages Query Builder Source: https://context7.com/munafio/chatify/llms.txt Returns an Eloquent query builder scoped to messages between the authenticated user and a specified user ID. Useful for paginating or filtering conversation history. ```php // All messages between auth user and user 42 $query = Chatify::fetchMessagesQuery(42); // Paginate 30 per page, newest first $messages = $query->latest()->paginate(30); // Custom per-page $messages = $query->latest()->paginate(50); foreach ($messages as $msg) { echo $msg->body; echo $msg->seen ? 'Read' : 'Unread'; } ``` -------------------------------- ### Parse Message to Array for Rendering Source: https://context7.com/munafio/chatify/llms.txt Fetches and normalizes a message into a structured array suitable for rendering or JSON responses. It resolves attachment types and adds human-readable timestamps. Can also work with a message ID. ```php $message = Chatify::newMessage([...]); $parsed = Chatify::parseMessage($message); // Also works by ID: Chatify::parseMessage(null, $messageId) /* [ 'id' => 'uuid', 'from_id' => 1, 'to_id' => 42, 'message' => 'Hello, world!', 'attachment' => (object)['file' => 'uuid.jpg', 'title' => 'photo.jpg', 'type' => 'image'], 'timeAgo' => '2 minutes ago', 'created_at' => '2024-04-27T10:00:00+00:00', 'isSender' => true, 'seen' => 0, ] */ ``` -------------------------------- ### getSharedPhotos Source: https://context7.com/munafio/chatify/llms.txt Retrieves an array of filenames for all image attachments shared between the authenticated user and a specified user. ```APIDOC ## `Chatify::getSharedPhotos($user_id)` — Shared Images in Conversation Returns an array of stored filenames for all image attachments shared between the authenticated user and the given user. ### Method `Chatify::getSharedPhotos(int $user_id)` ### Parameters #### Path Parameters - **user_id** (int) - Required - The ID of the user to retrieve shared photos with. ### Response - Returns an array of strings, where each string is a filename of a shared image attachment. ### Example ```php $photos = Chatify::getSharedPhotos(42); // ['uuid1.jpg', 'uuid2.png', ...] foreach ($photos as $filename) { $url = Chatify::getAttachmentUrl($filename); echo ''; } ``` ``` -------------------------------- ### Chatify::inFavorite($user_id) / Chatify::makeInFavorite($user_id, $action) Source: https://context7.com/munafio/chatify/llms.txt Checks the favorite status of a user or toggles whether a user is in the authenticated user's favorites list. ```APIDOC ## `Chatify::inFavorite($user_id)` / `makeInFavorite($user_id, $action)` — Favorites Check or toggle whether a user is in the authenticated user's favorites list. ### `inFavorite($user_id)` - **Parameters** - **user_id** (int) - Required - The ID of the user to check. - **Returns** - **bool** - True if the user is a favorite, false otherwise. ### `makeInFavorite($user_id, $action)` - **Parameters** - **user_id** (int) - Required - The ID of the user to favorite or unfavorite. - **action** (int) - Required - 1 to add to favorites, 0 to remove. - **Returns** - **int** - Returns 1 on success. ### Example ```php // Check favorite status $isFav = Chatify::inFavorite(42); // true or false // Add to favorites Chatify::makeInFavorite(42, 1); // star // Remove from favorites Chatify::makeInFavorite(42, 0); // unstar // Typical toggle pattern: $newStatus = Chatify::inFavorite(42) ? 0 : 1; Chatify::makeInFavorite(42, $newStatus); ``` ``` -------------------------------- ### Send Message (Text Only) Source: https://context7.com/munafio/chatify/llms.txt Sends a text message to a specified user. Includes a temporary message ID for client-side handling. ```APIDOC ## POST /chatify/api/sendMessage (Text Only) ### Description Sends a text message to a specified user. ### Method POST ### Endpoint /chatify/api/sendMessage ### Parameters #### Request Body - **id** (integer) - Required - The ID of the recipient user. - **message** (string) - Required - The text content of the message. - **temporaryMsgId** (string) - Optional - A temporary ID for the message, useful for client-side tracking. ### Request Example ```json { "id": 42, "message": "Hello!", "temporaryMsgId": "tmp-1" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success status. - **error** (object) - Contains error details if any. - **status** (integer) - Error status code. - **message** (null) - Error message. - **message** (object) - The sent message object. - **tempID** (string) - The temporary message ID echoed back. ``` -------------------------------- ### Chatify::parseMessage($message) Source: https://context7.com/munafio/chatify/llms.txt Fetches and normalizes a message into a structured array ready for rendering or JSON response. It resolves attachment type and adds human-readable time. It can accept a message model or a message ID. ```APIDOC ## `Chatify::parseMessage($message)` — Parse Message to Array Fetches and normalises a message into a structured array ready for rendering or JSON response. Resolves attachment type (image vs. file) and adds human-readable time. ### Parameters - **message** (ChMessage|null) - Optional - The message model instance. - **messageId** (string|null) - Optional - The ID of the message. If `message` is null, this ID is used to fetch the message. ### Returns - **array** - A structured array representing the message. ### Example ```php $message = Chatify::newMessage([...]); $parsed = Chatify::parseMessage($message); // Or by ID: $parsedById = Chatify::parseMessage(null, $messageId); /* [ ... message data ... ] */ ``` ``` -------------------------------- ### Add HasMessage Trait to User Model Source: https://context7.com/munafio/chatify/llms.txt Integrate the `HasMessage` trait into your User model to enable relationship helpers for received messages. This provides methods to fetch all, unread, or read messages for a user. ```php // app/Models/User.php use Chatify\Traits\HasMessage; class User extends Authenticatable { use HasMessage; // ... } // Usage examples $user = User::find(1); // All messages received by this user $allMessages = $user->messages()->get(); // Only unread messages $unread = $user->unreadMessage()->get(); // SELECT * FROM ch_messages WHERE to_id = 1 AND seen = 0 // Only read messages $read = $user->readMessage()->get(); // SELECT * FROM ch_messages WHERE to_id = 1 AND seen = 1 ```