Skip to content

Commit bd8e4c3

Browse files
committed
update readme
1 parent 1b7fcff commit bd8e4c3

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed

README.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
#### Conversations
3838

3939
- [Fetch conversations](#fetch-conversations)
40+
- [Fetch single conversation](#fetch-single-conversation)
41+
- [Update single conversation](#update-single-conversation)
4042
- [Fetch messages](#fetch-messages)
4143

4244
#### Teams
@@ -754,6 +756,117 @@ if ($response->isSuccess()) {
754756
}
755757
```
756758

759+
### <a name='fetch-single-conversation'>Fetch single conversation</a>
760+
761+
```php
762+
// parameters
763+
$params = [
764+
// Conversation UUID, MANDATORY
765+
'conversation_id' => '...'
766+
];
767+
768+
try {
769+
$response = $sendbeeApi->getConversation($params);
770+
} catch (\Sendbee\Api\Support\DataException $ex) {
771+
// handle missing data
772+
// this happens when required data was not provided
773+
echo "Missing required data. ", $ex->getMessage();
774+
} catch (\Exception $ex) {
775+
// handle exception thrown by GuzzleHttp
776+
// this is most likely due to a network issue
777+
echo "Could not contact backend endpoint. ", $ex->getMessage();
778+
}
779+
780+
781+
if ($response->isSuccess()) {
782+
// everything is OK
783+
/**
784+
* @var $conversation \Sendbee\Api\Models\Conversation
785+
*/
786+
$conversation = $response->getData();
787+
788+
echo "\n ID: ", $conversation->id;
789+
echo "\n folder: ", $conversation->folder;
790+
echo "\n chatbot_active: ", $conversation->chatbot_active;
791+
echo "\n platform: ", $conversation->platform;
792+
echo "\n created_at: ", $conversation->created_at;
793+
794+
echo "\n contact -> id: ", $conversation->contact->id;
795+
echo "\n contact -> name: ", $conversation->contact->name;
796+
echo "\n contact -> phone: ", $conversation->contact->phone;
797+
798+
echo "\n last_message -> direction: ", $conversation->last_message->direction;
799+
echo "\n last_message -> status: ", $conversation->last_message->status;
800+
echo "\n last_message -> inbound_sent_at: ", $conversation->last_message->inbound_sent_at;
801+
echo "\n last_message -> outbound_sent_at: ", $conversation->last_message->outbound_sent_at;
802+
} else {
803+
/**
804+
* @var $error \Sendbee\Api\Transport\ResponseError
805+
*/
806+
$error = $response->getError();
807+
if ($error) {
808+
echo "\n error type: ", $error->type;
809+
echo "\n error details: ", $error->detail;
810+
}
811+
}
812+
```
813+
814+
815+
#update-single-conversation
816+
### <a name='fetch-messages'>Update a single conversation</a>
817+
818+
```php
819+
// parameters
820+
$params = [
821+
// Conversation UUID, MANDATORY
822+
'conversation_id' => '...',
823+
// Assigned "folder" - 'open' or 'done'
824+
'folder' => 'open|done'
825+
];
826+
827+
try {
828+
$response = $sendbeeApi->updateConversation($params);
829+
} catch (\Sendbee\Api\Support\DataException $ex) {
830+
// handle missing data
831+
// this happens when required data was not provided
832+
echo "Missing required data. ", $ex->getMessage();
833+
} catch (\Exception $ex) {
834+
// handle exception thrown by GuzzleHttp
835+
// this is most likely due to a network issue
836+
echo "Could not contact backend endpoint. ", $ex->getMessage();
837+
}
838+
839+
840+
if ($response->isSuccess()) {
841+
// everything is OK
842+
$data = $response->getData();
843+
844+
foreach ($data as $message) {
845+
/**
846+
* @var $message \Sendbee\Api\Models\Message
847+
*/
848+
echo "\n body: ", $message->body;
849+
echo "\n media_type: ", $message->media_type;
850+
echo "\n media_url: ", $message->media_url;
851+
echo "\n status: ", $message->status;
852+
echo "\n direction: ", $message->direction;
853+
echo "\n sent_at: ", $message->sent_at;
854+
855+
}
856+
} else {
857+
/**
858+
* @var $error \Sendbee\Api\Transport\ResponseError
859+
*/
860+
$error = $response->getError();
861+
if ($error) {
862+
echo "\n error type: ", $error->type;
863+
echo "\n error details: ", $error->detail;
864+
}
865+
}
866+
```
867+
868+
869+
757870
### <a name='fetch-messages'>Fetch messages in a conversation</a>
758871

759872
```php

0 commit comments

Comments
 (0)