easyatworkas / sunshineconversations
PHP client lib for Sunshine Conversations.
Installs: 2 533
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- ext-json: *
- guzzlehttp/guzzle: ^6.5
This package is auto-updated.
Last update: 2025-06-14 17:55:18 UTC
README
Install it with composer:
composer require easyatworkas/sunshineconversations
Usage
Authentication
// Create a client. $client = new SmoochApiClient(); $client->setBaseUri('https://easyatwork.zendesk.com/sc/v2'); $client->authenticate('your api key', 'your api secret'); // Create an "app". $app = new SmoochApp($client, 'your app id');
Basics
// Find an existing user. $user = $app->getUser(3)->getData(); // List their conversations. $conversations = $app->listConversations($user['id'])->getData(); // Unless multi conversation mode is enabled, each user will only ever have one conversation. $activeConversation = reset($conversations); $app->createMessageAsBusiness($activeConversation['id'], 'Hello! How can I help you today?');
Pagination
When you have an instance of SmoochApiPaginatedResponse
you can invoke hasMore()
to see if there are more pages available, then use nextPage()
to generate the request parameters required to fetch the next page. Simply pass these parameters back to the relevant request method.
$messages = []; $pageParams = []; do { $response = $app->listMessages($conversation['id'], $pageParams); $messages = array_merge($messages, $response->getData()); } while ($response->hasMore() && $pageParams = $response->nextPage()); foreach ($messages as $message) { echo $message['author']['displayName'] ?? 'Bot', ': ', $message['content']['text'], PHP_EOL; }