### Install Dependencies and Slack Client Source: https://github.com/jolicode/slack-php-api/blob/main/docs/1-get-started.md Installs the required PSR-18 HTTP client, PSR-7 message factory, and the JoliCode Slack API library using Composer. ```bash composer require symfony/http-client nyholm/psr7 composer require jolicode/slack-php-api ``` -------------------------------- ### Initialize Slack Client and Fetch User Info Source: https://github.com/jolicode/slack-php-api/blob/main/docs/1-get-started.md Demonstrates how to instantiate the Slack client using a token and perform a basic API call to retrieve user information. ```php $client = JoliCode\Slack\ClientFactory::create($yourSlackToken); $user = $client->usersInfo(['user' => 'U123AZER'])->getUser(); ``` -------------------------------- ### Quick Start: Interact with Slack API using PHP Source: https://github.com/jolicode/slack-php-api/blob/main/README.md Demonstrates how to create a Slack client instance using a token and make a basic API call to retrieve user information. This example utilizes the JoliCode\Slack\ClientFactory to instantiate the client. ```php // $client contains all the methods to interact with the API $client = JoliCode\Slack\ClientFactory::create($yourSlackToken); $user = $client->usersInfo(['user' => 'U123AZER'])->getUser(); ``` -------------------------------- ### Install Slack PHP API Client Source: https://github.com/jolicode/slack-php-api/blob/main/README.md Installs the Slack PHP API client using Composer. This command assumes you have already installed PSR-7 and PSR-18 implementations like symfony/http-client and nyholm/psr7. ```bash composer require jolicode/slack-php-api ``` -------------------------------- ### Install Slack PHP API Client Source: https://context7.com/jolicode/slack-php-api/llms.txt Installs the Slack PHP API client and its PSR-7/PSR-18 dependencies using Composer. Ensure you have a compatible HTTP client and PSR-7 implementation installed. ```bash # Install PSR-7/PSR-18 dependencies (if not already present) composer require symfony/http-client nyholm/psr7 # Install the Slack PHP API client composer require jolicode/slack-php-api ``` -------------------------------- ### Iterate Over Paginated Users List - PHP Source: https://github.com/jolicode/slack-php-api/blob/main/docs/2-usage.md Provides an example of iterating over a paginated list of users using the `iterateUsersList` method. This method simplifies handling cursor-based pagination, abstracting away the manual cursor management for cleaner code. ```php $userNames = []; /** @var JoliCode\Slack\Api\Model\ObjsUser $user */ foreach ($client->iterateUsersList() as $user) { $userNames[] = $user->getName(); } ``` -------------------------------- ### Install PSR-7 and PSR-18 Implementations for Slack PHP API Source: https://github.com/jolicode/slack-php-api/blob/main/README.md Installs necessary PSR-7 and PSR-18 client implementations required by the Slack PHP API library. This command uses Composer to add symfony/http-client and nyholm/psr7 to your project dependencies. ```bash composer require symfony/http-client nyholm/psr7 ``` -------------------------------- ### Send Ephemeral Messages in Slack using PHP Source: https://context7.com/jolicode/slack-php-api/llms.txt Provides examples of sending ephemeral messages, which are visible only to a specific user in a channel, using the `chatPostEphemeral` method. It shows how to send plain text messages and messages formatted with Slack blocks. This requires a bot token and handles potential API errors. ```php chatPostEphemeral([ 'channel' => 'C1234567890', 'user' => 'U9876543210', // Only this user will see the message 'text' => 'This message is only visible to you!', ]); echo "Ephemeral message sent: {$response->getMessageTs()}\n"; // Send ephemeral message with blocks $blocks = [ [ 'type' => 'section', 'text' => [ 'type' => 'mrkdwn', 'text' => 'Your request is being processed...', ], ], ]; $client->chatPostEphemeral([ 'channel' => 'C1234567890', 'user' => 'U9876543210', 'text' => 'Processing request', 'blocks' => json_encode($blocks), ]); } catch (SlackErrorResponse $e) { echo "Error: " . $e->getErrorCode() . "\n"; } ``` -------------------------------- ### Run project test suite Source: https://github.com/jolicode/slack-php-api/blob/main/CONTRIBUTING.md Executes the project's unit tests using the make utility. Requires a valid Slack OAuth token to be configured. ```shell make test ``` -------------------------------- ### Create Slack API Client with Token - PHP Source: https://github.com/jolicode/slack-php-api/blob/main/docs/2-usage.md Demonstrates how to create a Slack API client instance using the ClientFactory. This is the primary method for initializing the client with your Slack API token, enabling subsequent interactions with the Slack API. ```php authTest(); echo "Connected as: " . $response->getUser() . "\n"; echo "Team: " . $response->getTeam() . "\n"; echo "User ID: " . $response->getUserId() . "\n"; } catch (SlackErrorResponse $e) { echo "Authentication failed: " . $e->getErrorCode() . "\n"; } ``` ### Response #### Success Response (200) Returns an authenticated client object. #### Response Example N/A (returns an object) #### Error Handling - `SlackErrorResponse`: Thrown for authentication failures or API errors. ``` -------------------------------- ### Create Slack API Client with ClientFactory::create Source: https://context7.com/jolicode/slack-php-api/llms.txt Demonstrates how to create a configured Slack API client using `ClientFactory::create`. This method handles Bearer token authentication and sets up necessary HTTP plugins. It requires a Slack OAuth token and outputs connection details or an error message. ```php authTest(); echo "Connected as: " . $response->getUser() . "\n"; echo "Team: " . $response->getTeam() . "\n"; echo "User ID: " . $response->getUserId() . "\n"; } catch (SlackErrorResponse $e) { echo "Authentication failed: " . $e->getErrorCode() . "\n"; } ``` -------------------------------- ### Create and list Slack reminders with PHP Source: https://context7.com/jolicode/slack-php-api/llms.txt Shows how to create one-time or recurring reminders for yourself or other users, and how to list existing reminders. Uses the remindersAdd and remindersList methods. ```php remindersAdd([ 'text' => 'Review the pull request', 'time' => 'in 2 hours', ]); $client->remindersAdd([ 'text' => 'Submit your timesheet', 'time' => strtotime('Friday 5pm'), 'user' => 'U1234567890', ]); $listResponse = $client->remindersList(); foreach ($listResponse->getReminders() as $reminder) { echo "- {$reminder->getText()} (at {$reminder->getTime()})\n"; } } catch (SlackErrorResponse $e) { echo "Error: " . $e->getErrorCode() . "\n"; } ``` -------------------------------- ### Configure Docsify for slack-php-api Source: https://github.com/jolicode/slack-php-api/blob/main/docs/index.html This JavaScript code configures the Docsify documentation generator for the jolicode/slack-php-api project. It sets the repository URL, enables automatic scrolling to the top, and defines aliases for routing. ```javascript window.$docsify = { name: 'slack-php-api', repo: 'jolicode/slack-php-api', relativePath: true, loadSidebar: 'navigation.md', homepage: 'index.md', themeColor: '#ecb22e', auto2top: true, alias: { '/docs/(.*)': '/$1.md', '/changelog': 'https://raw.githubusercontent.com/jolicode/slack-php-api/main/CHANGELOG.md', }, }; ``` -------------------------------- ### Manual Pagination Handling for Users List - PHP Source: https://github.com/jolicode/slack-php-api/blob/main/docs/2-usage.md Illustrates the manual process of handling cursor-based pagination for the `usersList` API endpoint. This involves explicitly managing the cursor to fetch subsequent pages of results until all data is retrieved. ```php $userNames = []; $cursor = ''; do { $response = $client->usersList([ 'limit' => 200, 'cursor' => $cursor, ]); /** @var JoliCode\Slack\Api\Model\ObjsUser $user */ foreach ($response->getUsers() as $user) { $userNames[] = $user->getName(); } $cursor = $response->getResponseMetadata() ? $response->getResponseMetadata()->getNextCursor() : ''; } while (!empty($cursor)); ``` -------------------------------- ### Fetch User Info using Slack API Client - PHP Source: https://github.com/jolicode/slack-php-api/blob/main/docs/2-usage.md Shows how to use the created Slack API client to fetch user information. It calls the `usersInfo` method with a user ID and retrieves the user object from the response. This illustrates a basic API interaction for retrieving specific data. ```php usersInfo(['user' => 'U123AZER'])->getUser(); dump($user); ``` -------------------------------- ### Create and Update User Groups in Slack using PHP Source: https://context7.com/jolicode/slack-php-api/llms.txt Illustrates the creation of a User Group (mention group) with a name, handle, description, and default channels using `usergroupsCreate`. It then demonstrates updating the members of this group using `usergroupsUsersUpdate`. This requires a bot token and handles potential Slack API errors. ```php usergroupsCreate([ 'name' => 'Engineering Team', 'handle' => 'engineering', // @engineering mention 'description' => 'All software engineers', 'channels' => 'C111111111,C222222222', // Default channels ]); $group = $response->getUsergroup(); echo "Created group: {$group->getName()}\n"; echo "Handle: @{$group->getHandle()}\n"; echo "ID: {$group->getId()}\n"; // Update the user group members $client->usergroupsUsersUpdate([ 'usergroup' => $group->getId(), 'users' => 'U111111111,U222222222,U333333333', ]); echo "Members updated!\n"; } catch (SlackErrorResponse $e) { echo "Error: " . $e->getErrorCode() . "\n"; } ``` -------------------------------- ### Create Slack Channels with PHP Source: https://context7.com/jolicode/slack-php-api/llms.txt Demonstrates how to programmatically create public or private Slack channels. The function returns channel metadata including the unique channel ID upon success. ```php conversationsCreate([ 'name' => 'project-alpha', ]); $channel = $response->getChannel(); echo "Created channel: #{$channel->getName()}\n"; $response = $client->conversationsCreate([ 'name' => 'secret-project', 'is_private' => true, ]); echo "Created private channel: {$response->getChannel()->getId()}\n"; } catch (SlackErrorResponse $e) { echo "Failed to create channel: " . $e->getErrorCode() . "\n"; } ``` -------------------------------- ### Synchronize fork with upstream repository Source: https://github.com/jolicode/slack-php-api/blob/main/CONTRIBUTING.md Commands to add the upstream remote, fetch changes, rebase the local branch, and push updates to the contributor's fork. ```shell git remote add upstream https://github.com/jolicode/slack-php-api.git git checkout main git pull --rebase origin main git pull --rebase upstream main git checkout git rebase main git push -f origin ``` -------------------------------- ### conversationsCreate Source: https://context7.com/jolicode/slack-php-api/llms.txt Creates a new public or private channel. ```APIDOC ## POST /conversationsCreate ### Description Creates a new public or private channel. ### Method POST ### Endpoint /conversationsCreate ### Parameters #### Request Body - **name** (string) - Required - The name of the channel to create. - **is_private** (boolean) - Optional - Set to true to create a private channel. Defaults to false (public). ### Request Example ```php // Create a public channel $response = $client->conversationsCreate([ 'name' => 'project-alpha', ]); // Create a private channel $response = $client->conversationsCreate([ 'name' => 'secret-project', 'is_private' => true, ]); ``` ### Response #### Success Response (200) - **channel** (object) - An object containing details of the created channel. - **id** (string) - The ID of the created channel. - **name** (string) - The name of the created channel. #### Response Example ```json { "channel": { "id": "C0123456789", "name": "project-alpha" } } ``` ### Error Handling - **SlackErrorResponse** - Thrown on API errors (e.g., `name_taken`, `invalid_name_specials`, `restricted_action`). ``` -------------------------------- ### Handle Slack API Errors with PHP Source: https://context7.com/jolicode/slack-php-api/llms.txt Demonstrates how to catch and handle SlackErrorResponse exceptions thrown by the SDK for API errors. It shows how to retrieve error codes, metadata like rate limits, and implement specific error handling logic. ```php chatPostMessage([ 'channel' => 'invalid-channel', 'text' => 'Hello!', ]); } catch (SlackErrorResponse $e) { // Get the Slack error code $errorCode = $e->getErrorCode(); echo "Error code: {$errorCode}\n"; // Get additional metadata (rate limits, etc.) $metadata = $e->getResponseMetadata(); if ($metadata) { print_r($metadata); } // Handle specific errors switch ($errorCode) { case 'channel_not_found': echo "The specified channel does not exist.\n"; break; case 'not_in_channel': echo "The bot is not a member of this channel.\n"; break; case 'ratelimited': echo "Rate limited. Retry after: " . ($metadata['retry_after'] ?? 'unknown') . " seconds\n"; break; case 'invalid_auth': case 'account_inactive': echo "Authentication failed. Check your token.\n"; break; default: echo "Unexpected error: {$errorCode}\n"; } } ``` -------------------------------- ### Iterate Workspace Users with Slack PHP API Source: https://context7.com/jolicode/slack-php-api/llms.txt Demonstrates how to traverse all users in a workspace using automatic cursor-based pagination. Includes logic for filtering deleted users and categorizing users as bots or active humans. ```php iterateUsersList() as $user) { if ($user->getDeleted()) { continue; } $userNames[] = $user->getName(); if ($user->getIsBot()) { $botUsers[] = $user->getName(); } else { $activeUsers[] = [ 'id' => $user->getId(), 'name' => $user->getName(), 'real_name' => $user->getRealName(), 'email' => $user->getProfile()->getEmail(), ]; } } echo "Total users: " . count($userNames) . "\n"; echo "Active human users: " . count($activeUsers) . "\n"; echo "Bot users: " . count($botUsers) . "\n"; $users = iterator_to_array($client->iterateUsersList()); } catch (SlackErrorResponse $e) { echo "Failed to list users: " . $e->getErrorCode() . "\n"; } ``` -------------------------------- ### Apply coding standards Source: https://github.com/jolicode/slack-php-api/blob/main/CONTRIBUTING.md Runs the PHP CS Fixer tool to ensure the codebase adheres to the project's defined coding standards. ```shell make cs ``` -------------------------------- ### usergroupsCreate Source: https://context7.com/jolicode/slack-php-api/llms.txt Creates a User Group (also known as a team or mention group). ```APIDOC ## POST /usergroups.create ### Description Creates a User Group (also known as a team or mention group). ### Method POST ### Endpoint /usergroups.create ### Parameters #### Request Body - **name** (string) - Required - The name of the user group. - **handle** (string) - Required - The handle for the user group (e.g., '@engineering'). - **description** (string) - Optional - A description for the user group. - **channels** (string) - Optional - A comma-separated list of default channel IDs for the user group. ### Request Example ```json { "name": "Engineering Team", "handle": "engineering", "description": "All software engineers", "channels": "C111111111,C222222222" } ``` ### Response #### Success Response (200) - **usergroup** (object) - Information about the created user group. #### Response Example ```json { "usergroup": { "id": "S1234567890", "name": "Engineering Team", "handle": "engineering" } } ``` ``` -------------------------------- ### Upload Files to Slack V2 using PHP Source: https://context7.com/jolicode/slack-php-api/llms.txt Demonstrates how to upload single or multiple files to Slack using the `filesUploadV2` method. This method supports various options like file titles, descriptions, alt text, snippet types, and uploading to specific threads. It requires a Slack bot token and handles potential `SlackErrorResponse` and `RuntimeException`. ```php filesUploadV2( files: [ ['path' => '/tmp/report.pdf', 'title' => 'Monthly Report'], ], channelId: 'C1234567890', initialComment: 'Here is the monthly report!', ); echo "File uploaded!\n"; // Upload multiple files at once $response = $client->filesUploadV2( files: [ ['path' => '/tmp/image.png', 'title' => 'Screenshot', 'alt_text' => 'Application screenshot'], ['path' => '/tmp/script.js', 'title' => 'Source Code', 'snippet_type' => 'javascript'], ['path' => '/tmp/data.csv', 'title' => 'Export Data'], ], channelId: 'C1234567890', initialComment: 'Attached files for review', ); echo "Multiple files uploaded!\n"; // Upload file to a thread $response = $client->filesUploadV2( files: [ ['path' => '/tmp/logs.txt', 'title' => 'Debug Logs'], ], channelId: 'C1234567890', threadTs: '1234567890.123456', // Parent message timestamp ); } catch (SlackErrorResponse $e) { echo "Upload failed: " . $e->getErrorCode() . "\n"; } catch (\RuntimeException $e) { echo "Upload error: " . $e->getMessage() . "\n"; } ``` -------------------------------- ### Configure Slack OAuth token for testing Source: https://github.com/jolicode/slack-php-api/blob/main/CONTRIBUTING.md Sets the required Slack API token in the PHPUnit configuration file to allow tests to authenticate with the Slack API. ```xml ``` -------------------------------- ### Schedule and manage Slack messages with PHP Source: https://context7.com/jolicode/slack-php-api/llms.txt Demonstrates how to schedule a message for a future time, list scheduled messages, and delete them using the Slack API client. Requires a valid bot token and channel ID. ```php chatScheduleMessage([ 'channel' => 'C1234567890', 'text' => 'Good morning! Here is your daily standup reminder.', 'post_at' => $sendAt, ]); echo "Message scheduled!\n"; echo "Scheduled Message ID: {$response->getScheduledMessageId()}\n"; $listResponse = $client->chatScheduledMessagesList([ 'channel' => 'C1234567890', ]); foreach ($listResponse->getScheduledMessages() as $scheduled) { echo "ID: {$scheduled->getId()}, Post at: {$scheduled->getPostAt()}\n"; } $client->chatDeleteScheduledMessage([ 'channel' => 'C1234567890', 'scheduled_message_id' => $response->getScheduledMessageId(), ]); } catch (SlackErrorResponse $e) { echo "Error: " . $e->getErrorCode() . "\n"; } ``` -------------------------------- ### Invite Users to Channels with PHP Source: https://context7.com/jolicode/slack-php-api/llms.txt Adds one or more users to a specified Slack channel. It accepts a channel ID and a comma-separated string of user IDs. ```php conversationsInvite([ 'channel' => 'C1234567890', 'users' => 'U9876543210', ]); echo "Invited user to #{$response->getChannel()->getName()}\n"; $response = $client->conversationsInvite([ 'channel' => 'C1234567890', 'users' => 'U111111111,U222222222,U333333333', ]); } catch (SlackErrorResponse $e) { echo "Error: " . $e->getErrorCode() . "\n"; } ``` -------------------------------- ### Pin and unpin messages in Slack with PHP Source: https://context7.com/jolicode/slack-php-api/llms.txt Demonstrates pinning a message to a channel, listing all pinned items, and removing a pin. Requires a channel ID and the message timestamp. ```php pinsAdd([ 'channel' => 'C1234567890', 'timestamp' => '1234567890.123456', ]); $response = $client->pinsList(['channel' => 'C1234567890']); foreach ($response['items'] ?? [] as $item) { if ($item['type'] === 'message') { echo "Pinned: {$item['message']['text']}\n"; } } $client->pinsRemove([ 'channel' => 'C1234567890', 'timestamp' => '1234567890.123456', ]); } catch (SlackErrorResponse $e) { echo "Error: " . $e->getErrorCode() . "\n"; } ``` -------------------------------- ### Search Messages in Slack using PHP Source: https://context7.com/jolicode/slack-php-api/llms.txt Shows how to search for messages across accessible channels using the `searchMessages` method. This requires a user token and allows specifying search queries, sorting options, and the number of results. The response format needs careful handling to access message details. ```php searchMessages([ 'query' => 'from:@john deployment', 'sort' => 'timestamp', 'sort_dir' => 'desc', 'count' => 20, ]); echo "Found {$response->getMessages()['total']} messages\n"; // Note: searchMessages returns data in a different format // Access via array syntax for unmapped properties foreach ($response['messages']['matches'] as $match) { echo "Channel: {$match['channel']['name']}\n"; echo "Text: {$match['text']}\n"; echo "Permalink: {$match['permalink']}\n\n"; } } catch (SlackErrorResponse $e) { echo "Search failed: " . $e->getErrorCode() . "\n"; } ``` -------------------------------- ### conversationsInvite Source: https://context7.com/jolicode/slack-php-api/llms.txt Invites users to a public or private channel. ```APIDOC ## POST /conversationsInvite ### Description Invites users to a public or private channel. ### Method POST ### Endpoint /conversationsInvite ### Parameters #### Request Body - **channel** (string) - Required - The ID of the channel to invite users to. - **users** (string) - Required - A comma-separated list of user IDs to invite (up to 1000). ### Request Example ```php // Invite a single user $response = $client->conversationsInvite([ 'channel' => 'C1234567890', 'users' => 'U9876543210', ]); // Invite multiple users $response = $client->conversationsInvite([ 'channel' => 'C1234567890', 'users' => 'U111111111,U222222222,U333333333', ]); ``` ### Response #### Success Response (200) - **channel** (object) - An object containing details of the channel. - **name** (string) - The name of the channel. #### Response Example ```json { "channel": { "name": "general" } } ``` ### Error Handling - **SlackErrorResponse** - Thrown on API errors (e.g., `already_in_channel`, `channel_not_found`, `user_not_found`). ``` -------------------------------- ### Send Slack Message with chatPostMessage Source: https://context7.com/jolicode/slack-php-api/llms.txt Shows how to send messages to Slack channels using the `chatPostMessage` method. Supports plain text, Block Kit, custom usernames, icons, and threaded replies. Requires a valid Slack client and channel ID. Outputs the message timestamp and channel or an error code. ```php chatPostMessage([ 'channel' => 'C1234567890', // Channel ID or name like 'general' 'text' => 'Hello from Slack PHP API!', ]); echo "Message sent! Timestamp: " . $result->getTs() . "\n"; echo "Channel: " . $result->getChannel() . "\n"; // Message with custom username and emoji icon $result = $client->chatPostMessage([ 'channel' => 'general', 'text' => 'Deployment completed successfully!', 'username' => 'DeployBot', 'icon_emoji' => ':rocket:', ]); // Message with Block Kit blocks $blocks = [ [ 'type' => 'section', 'text' => [ 'type' => 'mrkdwn', 'text' => '*New Pull Request*\n', ], ], [ 'type' => 'section', 'fields' => [ ['type' => 'mrkdwn', 'text' => '*Author:*\n@john'], ['type' => 'mrkdwn', 'text' => '*Status:* Open'], ], ], [ 'type' => 'actions', 'elements' => [ [ 'type' => 'button', 'text' => ['type' => 'plain_text', 'text' => 'Review'], 'url' => 'https://github.com/org/repo/pull/123', ], ], ], ]; $result = $client->chatPostMessage([ 'channel' => 'dev-team', 'text' => 'New PR ready for review', // Fallback text 'blocks' => json_encode($blocks), ]); // Reply in a thread $result = $client->chatPostMessage([ 'channel' => 'C1234567890', 'text' => 'This is a threaded reply', 'thread_ts' => '1234567890.123456', // Parent message timestamp ]); } catch (SlackErrorResponse $e) { echo "Failed to send message: " . $e->getErrorCode() . "\n"; // Common errors: channel_not_found, not_in_channel, invalid_blocks } ``` -------------------------------- ### Accessing unmapped API response data in PHP Source: https://github.com/jolicode/slack-php-api/blob/main/docs/3-troubleshoots.md Demonstrates how to access fields that are not explicitly defined in the DTO by utilizing the ArrayObject base class functionality. This allows developers to retrieve data returned by the Slack API even if the OpenAPI mapping is incomplete. ```php $results = $client->searchMessages([ 'query' => 'test' ]); var_dump($results->getOk()); // ok property is mapped var_dump($results['messages']); // messages property is not mapped but still readable ``` -------------------------------- ### searchMessages Source: https://context7.com/jolicode/slack-php-api/llms.txt Searches for messages matching a query across channels the user has access to. Requires a user token. ```APIDOC ## GET /search.messages ### Description Searches for messages matching a query across channels the user has access to. ### Method GET ### Endpoint /search.messages ### Parameters #### Query Parameters - **query** (string) - Required - The search query string. - **sort** (string) - Optional - The sort order for results (e.g., 'timestamp'). - **sort_dir** (string) - Optional - The direction of sorting ('asc' or 'desc'). - **count** (integer) - Optional - The number of results to return per page. ### Request Example ```json { "query": "from:@john deployment", "sort": "timestamp", "sort_dir": "desc", "count": 20 } ``` ### Response #### Success Response (200) - **messages** (object) - Contains search results, including 'total' count and 'matches' array. - **matches** (array) - An array of message objects matching the query. #### Response Example ```json { "messages": { "total": 5, "matches": [ { "channel": {"name": "general"}, "text": "Deployment successful!", "permalink": "https://your-workspace.slack.com/archives/general/p1234567890" } ] } } ``` ``` -------------------------------- ### reactionsAdd Source: https://context7.com/jolicode/slack-php-api/llms.txt Adds a reaction (emoji) to a message. ```APIDOC ## POST /reactionsAdd ### Description Adds a reaction (emoji) to a message. ### Method POST ### Endpoint /reactionsAdd ### Parameters #### Request Body - **channel** (string) - Required - The ID of the channel where the message is located. - **timestamp** (string) - Required - The timestamp of the message to react to (e.g., '1234567890.123456'). - **name** (string) - Required - The name of the emoji to use as a reaction (without colons). ### Request Example ```php // Add a single reaction $client->reactionsAdd([ 'channel' => 'C1234567890', 'timestamp' => '1234567890.123456', 'name' => 'thumbsup', ]); // Add multiple reactions $reactions = ['eyes', 'rocket', 'white_check_mark']; foreach ($reactions as $emoji) { $client->reactionsAdd([ 'channel' => 'C1234567890', 'timestamp' => '1234567890.123456', 'name' => $emoji, ]); } ``` ### Response #### Success Response (200) - **ok** (boolean) - Indicates if the reaction was added successfully. #### Response Example ```json { "ok": true } ``` ### Error Handling - **SlackErrorResponse** - Thrown on API errors (e.g., `already_reacted`, `invalid_name`, `message_not_found`). ``` -------------------------------- ### filesUploadV2 Source: https://context7.com/jolicode/slack-php-api/llms.txt Uploads files to Slack using the modern external upload flow. Supports multiple files in a single upload and can be sent to a thread. ```APIDOC ## POST /files.uploadV2 ### Description Uploads files to Slack using the modern external upload flow. Supports multiple files in a single upload. ### Method POST ### Endpoint /files.uploadV2 ### Parameters #### Query Parameters - **files** (array) - Required - An array of file objects, each with 'path', 'title', and optional 'alt_text' or 'snippet_type'. - **channelId** (string) - Required - The ID of the channel to upload the file to. - **initialComment** (string) - Optional - The initial comment to post with the file. - **threadTs** (string) - Optional - The timestamp of the parent message to post the file to a thread. ### Request Example ```php [ ['path' => '/tmp/report.pdf', 'title' => 'Monthly Report'], ] ``` ### Response #### Success Response (200) - **file** (object) - Information about the uploaded file. #### Response Example ```json { "file": { "id": "F1234567890", "name": "report.pdf", "title": "Monthly Report" } } ``` ``` -------------------------------- ### List Conversations with Slack PHP API Source: https://context7.com/jolicode/slack-php-api/llms.txt Retrieves and iterates through various channel types including public, private, and direct messages. Shows how to configure list parameters and handle pagination for large conversation sets. ```php conversationsList([ 'types' => 'public_channel', 'exclude_archived' => true, 'limit' => 100, ]); foreach ($response->getChannels() as $channel) { echo "#{$channel->getName()} ({$channel->getId()})\n"; echo " Members: {$channel->getNumMembers()}\n"; echo " Purpose: {$channel->getPurpose()->getValue()}\n"; } foreach ($client->iterateConversationsList(['types' => 'public_channel,private_channel,mpim,im']) as $channel) { $type = $channel->getIsIm() ? 'DM' : ($channel->getIsPrivate() ? 'Private' : 'Public'); echo "[{$type}] " . ($channel->getName() ?? $channel->getId()) . "\n"; } } catch (SlackErrorResponse $e) { echo "Error: " . $e->getErrorCode() . "\n"; } ``` -------------------------------- ### Retrieve User Information with Slack PHP API Source: https://context7.com/jolicode/slack-php-api/llms.txt Fetches detailed profile information for a specific Slack user by ID. It demonstrates handling the response object and accessing profile fields like email, status, and avatar URLs. ```php usersInfo(['user' => 'U1234567890']); $user = $response->getUser(); echo "User: " . $user->getName() . "\n"; echo "Real Name: " . $user->getRealName() . "\n"; echo "Email: " . $user->getProfile()->getEmail() . "\n"; echo "Title: " . $user->getProfile()->getTitle() . "\n"; echo "Status: " . $user->getProfile()->getStatusText() . "\n"; echo "Timezone: " . $user->getTz() . "\n"; echo "Is Admin: " . ($user->getIsAdmin() ? 'Yes' : 'No') . "\n"; echo "Is Bot: " . ($user->getIsBot() ? 'Yes' : 'No') . "\n"; $profile = $user->getProfile(); echo "Avatar (24px): " . $profile->getImage24() . "\n"; echo "Avatar (192px): " . $profile->getImage192() . "\n"; } catch (SlackErrorResponse $e) { echo "Error: " . $e->getErrorCode() . "\n"; } ``` -------------------------------- ### Manage Slack Do Not Disturb settings with PHP Source: https://context7.com/jolicode/slack-php-api/llms.txt Covers enabling DND mode, checking status for a specific user, and disabling snooze early. Utilizes dndSetSnooze, dndInfo, and dndEndSnooze methods. ```php dndSetSnooze(['num_minutes' => '60']); $info = $client->dndInfo(['user' => 'U1234567890']); echo "DND enabled: " . ($info->getDndEnabled() ? 'Yes' : 'No') . "\n"; $client->dndEndSnooze(); } catch (SlackErrorResponse $e) { echo "Error: " . $e->getErrorCode() . "\n"; } ``` -------------------------------- ### conversationsHistory Source: https://context7.com/jolicode/slack-php-api/llms.txt Fetches the message history of a conversation (channel, DM, or group). Supports filtering by date and automatic pagination. ```APIDOC ## GET /conversationsHistory ### Description Fetches the message history of a conversation (channel, DM, or group). Supports filtering by date and automatic pagination. ### Method GET ### Endpoint /conversationsHistory ### Parameters #### Query Parameters - **channel** (string) - Required - The ID of the channel, private channel, or DM conversation. - **limit** (integer) - Optional - The number of messages to return, between 1 and 1000. - **oldest** (integer) - Optional - A Unix timestamp to get messages after this time. - **latest** (integer) - Optional - A Unix timestamp to get messages before this time. - **inclusive** (boolean) - Optional - Include messages with oldest or latest timestamps. ### Request Example ```php $response = $client->conversationsHistory([ 'channel' => 'C1234567890', 'limit' => 50, 'oldest' => strtotime('-7 days'), 'latest' => time(), 'inclusive' => true, ]); ``` ### Response #### Success Response (200) - **messages** (array) - An array of message objects. - **has_more** (boolean) - Indicates if there are more messages available. #### Response Example ```json { "messages": [ { "ts": "1678886400.000000", "user": "U1234567890", "text": "Hello world!", "reactions": [ { "name": "thumbsup", "count": 5 } ] } ], "has_more": true } ``` ### Error Handling - **SlackErrorResponse** - Thrown on API errors (e.g., `channel_not_found`, `not_in_channel`). ``` -------------------------------- ### Fetch Conversation History with PHP Source: https://context7.com/jolicode/slack-php-api/llms.txt Retrieves message history from a specific Slack channel, supporting pagination and time-range filtering. It requires a valid bot token and handles Slack-specific error responses. ```php conversationsHistory([ 'channel' => 'C1234567890', 'limit' => 50, ]); foreach ($response->getMessages() as $message) { $timestamp = date('Y-m-d H:i:s', (int) $message->getTs()); $user = $message->getUser() ?? 'bot'; $text = $message->getText(); echo "[{$timestamp}] {$user}: {$text}\n"; if ($message->getReactions()) { foreach ($message->getReactions() as $reaction) { echo " :{$reaction->getName()}: ({$reaction->getCount()})\n"; } } } foreach ($client->iterateConversationsHistory(['channel' => 'C1234567890']) as $message) { echo $message->getText() . "\n"; } } catch (SlackErrorResponse $e) { echo "Error: " . $e->getErrorCode() . "\n"; } ```