├── src
└── MessageBird
│ ├── Exceptions
│ ├── HttpException.php
│ ├── BalanceException.php
│ ├── RequestException.php
│ ├── ServerException.php
│ ├── ValidationException.php
│ ├── AuthenticateException.php
│ └── MessageBirdException.php
│ ├── Objects
│ ├── PartnerAccount
│ │ ├── AccessKey.php
│ │ └── Account.php
│ ├── Conversation
│ │ ├── HSM
│ │ │ ├── Currency.php
│ │ │ ├── Params.php
│ │ │ ├── Message.php
│ │ │ └── Language.php
│ │ ├── MessageReference.php
│ │ ├── SendMessageResult.php
│ │ ├── Fallback.php
│ │ ├── Contact.php
│ │ ├── SendMessage.php
│ │ ├── Channel.php
│ │ ├── Webhook.php
│ │ ├── Content.php
│ │ ├── Message.php
│ │ └── Conversation.php
│ ├── Voice
│ │ ├── BaseList.php
│ │ ├── Step.php
│ │ ├── Webhook.php
│ │ ├── Transcription.php
│ │ ├── Recording.php
│ │ ├── CallFlow.php
│ │ ├── Call.php
│ │ └── Leg.php
│ ├── BaseList.php
│ ├── Balance.php
│ ├── NumberPurchaseRequest.php
│ ├── Base.php
│ ├── Number.php
│ ├── EmailMessage.php
│ ├── Recipients.php
│ ├── Group.php
│ ├── Recipient.php
│ ├── Hlr.php
│ ├── Verify.php
│ ├── MmsMessage.php
│ ├── MessageResponse.php
│ ├── SignedRequest.php
│ ├── Lookup.php
│ ├── VoiceMessage.php
│ ├── Contact.php
│ └── Message.php
│ ├── Common
│ ├── Authentication.php
│ └── ResponseError.php
│ └── Resources
│ ├── Conversation
│ ├── Contacts.php
│ ├── Content.php
│ ├── Webhooks.php
│ ├── Send.php
│ └── Conversations.php
│ ├── Hlr.php
│ ├── Balance.php
│ ├── MmsMessages.php
│ ├── Voice
│ ├── Calls.php
│ ├── Webhooks.php
│ ├── CallFlows.php
│ ├── Base.php
│ ├── Legs.php
│ └── Recordings.php
│ ├── VoiceMessage.php
│ ├── EmailMessage.php
│ ├── Messages.php
│ ├── Verify.php
│ ├── Lookup.php
│ ├── PhoneNumbers.php
│ ├── AvailablePhoneNumbers.php
│ ├── LookupHlr.php
│ ├── Contacts.php
│ ├── PartnerAccount
│ └── Accounts.php
│ └── Groups.php
├── examples
├── voice-calls-list.php
├── voice-webhooks-list.php
├── voice-call-flows-list.php
├── voice-calls-read.php
├── voice-webhooks-read.php
├── conversations
│ ├── message-read.php
│ ├── webhooks-delete.php
│ ├── webhooks-list.php
│ ├── messages-list.php
│ ├── webhooks-read.php
│ ├── list.php
│ ├── read.php
│ ├── update.php
│ ├── create.php
│ ├── messages-create-location.php
│ ├── messages-create-text.php
│ ├── send.php
│ ├── messages-create-media.php
│ ├── enable-whatsapp-sandbox.php
│ ├── webhooks-create.php
│ └── create-hsm.php
├── voice-call-flows-read.php
├── voice-webhooks-delete.php
├── voice-call-flows-delete.php
├── voice-legs-list.php
├── voice-legs-read.php
├── balance-view.php
├── group-list.php
├── voice-call-flows-update.php
├── contact-list.php
├── hlr-list.php
├── mms-list.php
├── phone-numbers-view.php
├── group-view.php
├── partner-account-read.php
├── group-get-contacts.php
├── partner-account-delete.php
├── partner-account-list.php
├── voice-recordings-list.php
├── contact-get-groups.php
├── group-delete.php
├── message-list.php
├── mms-view.php
├── phone-numbers-delete.php
├── voice-webhooks-create.php
├── contact-get-messages.php
├── voice-recordings-read.php
├── contact-view.php
├── hlr-view.php
├── available-phone-numbers-view.php
├── contact-delete.php
├── verify-view.php
├── voicemessages-list.php
├── message-view.php
├── message-delete.php
├── voice-transcriptions-read.php
├── voice-webhooks-update.php
├── voice-transcriptions-list.php
├── voice-transcriptions-create.php
├── voicemessages-view.php
├── lookup-view.php
├── emailmessages-view.php
├── group-create.php
├── group-update.php
├── phone-numbers-update.php
├── group-remove-contact-from-group.php
├── partner-account-create.php
├── partner-account-update.php
├── group-add-contact-to-group.php
├── mms-delete.php
├── signedrequest-verification.php
├── voice-transcriptions-download.php
├── voice-call-flows-create.php
├── verify-verification.php
├── voice-recordings-download.php
├── phone-numbers-create.php
├── hlr-create.php
├── contact-update.php
├── contact-create.php
├── voice-calls-create.php
├── message-create.php
├── verify-create.php
├── message-create-unicode.php
├── signed-request-validation.php
├── mms-create.php
├── lookup-hlr-view.php
├── voicemessages-create.php
└── verify-create-email.php
├── psalm.xml
├── composer.json
├── autoload.php
├── LICENSE
└── README.md
/src/MessageBird/Exceptions/HttpException.php:
--------------------------------------------------------------------------------
1 | voiceCalls->getList(['offset' => 100, 'limit' => 30]);
9 | var_dump($result);
10 | } catch (\Exception $e) {
11 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
12 | }
13 |
--------------------------------------------------------------------------------
/src/MessageBird/Common/Authentication.php:
--------------------------------------------------------------------------------
1 | accessKey = $accessKey;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/examples/voice-webhooks-list.php:
--------------------------------------------------------------------------------
1 | voiceWebhooks->getList(['offset' => 100, 'limit' => 30]);
9 | var_dump($result);
10 | } catch (\Exception $e) {
11 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
12 | }
13 |
--------------------------------------------------------------------------------
/examples/voice-call-flows-list.php:
--------------------------------------------------------------------------------
1 | voiceCallFlows->getList(['offset' => 100, 'limit' => 30]);
9 | var_dump($result);
10 | } catch (\Exception $e) {
11 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
12 | }
13 |
--------------------------------------------------------------------------------
/examples/voice-calls-read.php:
--------------------------------------------------------------------------------
1 | voiceCalls->read('dbf1373c-6781-43c7-bfe4-6538583c444b'); // Set a call id here
9 | var_dump($result);
10 | } catch (\Exception $e) {
11 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
12 | }
13 |
--------------------------------------------------------------------------------
/examples/voice-webhooks-read.php:
--------------------------------------------------------------------------------
1 | voiceWebhooks->read('e5f56d49-4fa2-4802-895d-b0a306f73f76'); // Set a webhook id here
9 | var_dump($result);
10 | } catch (\Exception $e) {
11 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
12 | }
13 |
--------------------------------------------------------------------------------
/examples/conversations/message-read.php:
--------------------------------------------------------------------------------
1 | conversationMessages->read('YOUR MESSAGE ID');
11 |
12 | var_dump($message);
13 | } catch (\Exception $e) {
14 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
15 | }
16 |
--------------------------------------------------------------------------------
/examples/voice-call-flows-read.php:
--------------------------------------------------------------------------------
1 | voiceCallFlows->read('f24dd28c-90da-4ed6-af92-d8e32a0e5f55'); // Set a call flow id here
9 | var_dump($result);
10 | } catch (\Exception $e) {
11 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
12 | }
13 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/Conversation/HSM/Params.php:
--------------------------------------------------------------------------------
1 | object = new Contact();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/examples/voice-webhooks-delete.php:
--------------------------------------------------------------------------------
1 | voiceWebhooks->delete('e5f56d49-4fa2-4802-895d-b0a306f73f76'); // Set a webhook id here
9 | var_dump('Deleted: ' . $deleted);
10 | } catch (\Exception $e) {
11 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
12 | }
13 |
--------------------------------------------------------------------------------
/examples/voice-call-flows-delete.php:
--------------------------------------------------------------------------------
1 | voiceCallFlows->delete('7d3c2125-4ab4-4dcb-acf9-1c2dbfa24087'); // Set a call flow id here
9 | var_dump('Deleted: ' . $deleted);
10 | } catch (\Exception $e) {
11 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
12 | }
13 |
--------------------------------------------------------------------------------
/examples/voice-legs-list.php:
--------------------------------------------------------------------------------
1 | voiceLegs->getList('dbf1373c-6781-43c7-bfe4-6538583c444b', ['offset' => 100, 'limit' => 30]); // Set a call id here
9 | var_dump($result);
10 | } catch (\Exception $e) {
11 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
12 | }
13 |
--------------------------------------------------------------------------------
/src/MessageBird/Resources/Conversation/Content.php:
--------------------------------------------------------------------------------
1 | object = new ContentObject();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/examples/voice-legs-read.php:
--------------------------------------------------------------------------------
1 | voiceLegs->read('dbf1373c-6781-43c7-bfe4-6538583c444b', '6f39d883-94ac-4068-9fed-a9e31b77acda'); // Set a call and leg id here
9 | var_dump($result);
10 | } catch (\Exception $e) {
11 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
12 | }
13 |
--------------------------------------------------------------------------------
/examples/balance-view.php:
--------------------------------------------------------------------------------
1 | balance->read();
9 | var_dump($balance);
10 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
11 | // That means that your accessKey is unknown
12 | echo 'wrong login';
13 | } catch (\Exception $e) {
14 | var_dump($e->getMessage());
15 | }
16 |
--------------------------------------------------------------------------------
/src/MessageBird/Resources/Hlr.php:
--------------------------------------------------------------------------------
1 | object = new Objects\Hlr();
18 | $this->setResourceName('hlr');
19 |
20 | parent::__construct($httpClient);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/examples/group-list.php:
--------------------------------------------------------------------------------
1 | groups->getList([]);
9 | var_dump($groupsList);
10 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
11 | // That means that your accessKey is unknown
12 | echo 'Wrong login';
13 | } catch (\Exception $e) {
14 | var_dump($e->getMessage());
15 | }
16 |
--------------------------------------------------------------------------------
/examples/voice-call-flows-update.php:
--------------------------------------------------------------------------------
1 | voiceCallFlows->update($callFlow, '21e5fc51-3285-4f41-97fd-cd1785ab54f8');
10 | var_dump($result);
11 | } catch (\Exception $e) {
12 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
13 | }
14 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/BaseList.php:
--------------------------------------------------------------------------------
1 | null,
18 | 'previous' => null,
19 | 'next' => null,
20 | 'last' => null,
21 | ];
22 |
23 | public $items = [];
24 | }
25 |
--------------------------------------------------------------------------------
/psalm.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/examples/contact-list.php:
--------------------------------------------------------------------------------
1 | contacts->getList([]);
9 | var_dump($contactList);
10 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
11 | // That means that your accessKey is unknown
12 | echo 'Wrong login';
13 | } catch (\Exception $e) {
14 | var_dump($e->getMessage());
15 | }
16 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/Conversation/HSM/Message.php:
--------------------------------------------------------------------------------
1 | object = new Objects\Balance();
18 | $this->setResourceName('balance');
19 |
20 | parent::__construct($httpClient);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/examples/hlr-list.php:
--------------------------------------------------------------------------------
1 | hlr->getList(['offset' => 100, 'limit' => 30]);
9 | var_dump($hlrList);
10 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
11 | // That means that your accessKey is unknown
12 | echo 'wrong login';
13 | } catch (\Exception $e) {
14 | var_dump($e->getMessage());
15 | }
16 |
--------------------------------------------------------------------------------
/examples/mms-list.php:
--------------------------------------------------------------------------------
1 | mmsMessages->getList(['offset' => 0, 'limit' => 30]);
9 | var_dump($mmsList);
10 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
11 | // That means that your accessKey is unknown
12 | echo 'wrong login';
13 | } catch (\Exception $e) {
14 | var_dump($e->getMessage());
15 | }
16 |
--------------------------------------------------------------------------------
/examples/phone-numbers-view.php:
--------------------------------------------------------------------------------
1 | phoneNumbers->getList();
9 | var_dump($phoneNumbers);
10 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
11 | // That means that your accessKey is unknown
12 | print("wrong login\n");
13 | } catch (\Exception $e) {
14 | var_dump($e->getMessage());
15 | }
16 |
--------------------------------------------------------------------------------
/src/MessageBird/Resources/MmsMessages.php:
--------------------------------------------------------------------------------
1 | object = new Objects\MmsMessage();
18 | $this->setResourceName('mms');
19 |
20 | parent::__construct($httpClient);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/MessageBird/Resources/Voice/Calls.php:
--------------------------------------------------------------------------------
1 | object = new Objects\Voice\Call();
18 | $this->setResourceName('calls');
19 |
20 | parent::__construct($httpClient);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/examples/group-view.php:
--------------------------------------------------------------------------------
1 | groups->read('group_id'); // Set a group id here
9 | var_dump($groupResult);
10 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
11 | // That means that your accessKey is unknown
12 | echo 'Wrong login';
13 | } catch (\Exception $e) {
14 | var_dump($e->getMessage());
15 | }
16 |
--------------------------------------------------------------------------------
/examples/partner-account-read.php:
--------------------------------------------------------------------------------
1 | partnerAccounts->read(1);
9 | var_dump($partnerAccountResult);
10 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
11 | // That means that your accessKey is unknown
12 | echo 'wrong login';
13 | } catch (\Exception $e) {
14 | echo $e->getMessage();
15 | }
16 |
--------------------------------------------------------------------------------
/examples/group-get-contacts.php:
--------------------------------------------------------------------------------
1 | groups->getContacts('group_id');
9 | var_dump($groupsContactList);
10 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
11 | // That means that your accessKey is unknown
12 | echo 'Wrong login';
13 | } catch (\Exception $e) {
14 | var_dump($e->getMessage());
15 | }
16 |
--------------------------------------------------------------------------------
/examples/partner-account-delete.php:
--------------------------------------------------------------------------------
1 | partnerAccounts->delete(1);
9 | var_dump($partnerAccountResult);
10 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
11 | // That means that your accessKey is unknown
12 | echo 'wrong login';
13 | } catch (\Exception $e) {
14 | echo $e->getMessage();
15 | }
16 |
--------------------------------------------------------------------------------
/examples/partner-account-list.php:
--------------------------------------------------------------------------------
1 | partnerAccounts->getList();
9 | var_dump($partnerAccountResult);
10 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
11 | // That means that your accessKey is unknown
12 | echo 'wrong login';
13 | } catch (\Exception $e) {
14 | echo $e->getMessage();
15 | }
16 |
--------------------------------------------------------------------------------
/examples/voice-recordings-list.php:
--------------------------------------------------------------------------------
1 | voiceRecordings->getList('c226420d-f107-4db1-b2f9-4646656a90bc', '4f5ab5f4-c4b6-4586-9255-980bb3fd7336', ['offset' => 100, 'limit' => 30]); // Set a call and leg id here
9 | var_dump($result);
10 | } catch (\Exception $e) {
11 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
12 | }
13 |
--------------------------------------------------------------------------------
/examples/contact-get-groups.php:
--------------------------------------------------------------------------------
1 | contacts->getGroups('contact_id');
9 | var_dump($contactGroupsList);
10 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
11 | // That means that your accessKey is unknown
12 | echo 'Wrong login';
13 | } catch (\Exception $e) {
14 | var_dump($e->getMessage());
15 | }
16 |
--------------------------------------------------------------------------------
/examples/group-delete.php:
--------------------------------------------------------------------------------
1 | groups->delete('group_id'); // Set a group id here
9 | var_dump('Deleted: ' . $deleted);
10 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
11 | // That means that your accessKey is unknown
12 | echo 'Wrong login';
13 | } catch (\Exception $e) {
14 | var_dump($e->getMessage());
15 | }
16 |
--------------------------------------------------------------------------------
/examples/message-list.php:
--------------------------------------------------------------------------------
1 | messages->getList(['offset' => 100, 'limit' => 30]);
9 | var_dump($messageList);
10 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
11 | // That means that your accessKey is unknown
12 | echo 'wrong login';
13 | } catch (\Exception $e) {
14 | var_dump($e->getMessage());
15 | }
16 |
--------------------------------------------------------------------------------
/examples/mms-view.php:
--------------------------------------------------------------------------------
1 | mmsMessages->read('mms_message_id'); // Set a MMS Message id
9 | var_dump($mmsResult);
10 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
11 | // That means that your accessKey is unknown
12 | echo 'wrong login';
13 | } catch (\Exception $e) {
14 | var_dump($e->getMessage());
15 | }
16 |
--------------------------------------------------------------------------------
/examples/phone-numbers-delete.php:
--------------------------------------------------------------------------------
1 | phoneNumbers->delete('31612345678');
9 | var_dump('Deleted: ' . $deleted);
10 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
11 | // That means that your accessKey is unknown
12 | print("wrong login\n");
13 | } catch (\Exception $e) {
14 | echo $e->getMessage();
15 | }
16 |
--------------------------------------------------------------------------------
/examples/voice-webhooks-create.php:
--------------------------------------------------------------------------------
1 | url = 'https://example.com/status';
8 | $webhook->token = 'foobar';
9 |
10 | try {
11 | $result = $messageBird->voiceWebhooks->create($webhook);
12 | var_dump($result);
13 | } catch (\Exception $e) {
14 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
15 | }
16 |
--------------------------------------------------------------------------------
/src/MessageBird/Resources/Voice/Webhooks.php:
--------------------------------------------------------------------------------
1 | object = new Objects\Voice\Webhook();
18 | $this->setResourceName('webhooks');
19 |
20 | parent::__construct($httpClient);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/MessageBird/Resources/VoiceMessage.php:
--------------------------------------------------------------------------------
1 | object = new Objects\VoiceMessage();
18 | $this->setResourceName('voicemessages');
19 |
20 | parent::__construct($httpClient);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/examples/contact-get-messages.php:
--------------------------------------------------------------------------------
1 | contacts->getMessages('contact_id');
9 | var_dump($contactMessageList);
10 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
11 | // That means that your accessKey is unknown
12 | echo 'Wrong login';
13 | } catch (\Exception $e) {
14 | var_dump($e->getMessage());
15 | }
16 |
--------------------------------------------------------------------------------
/examples/voice-recordings-read.php:
--------------------------------------------------------------------------------
1 | voiceRecordings->read('c226420d-f107-4db1-b2f9-4646656a90bc', '4f5ab5f4-c4b6-4586-9255-980bb3fd7336', 'a94f7d51-19b5-4eb8-9e8e-90fce490a577'); // Set call, leg and recording id here
9 | var_dump($result);
10 | } catch (\Exception $e) {
11 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
12 | }
13 |
--------------------------------------------------------------------------------
/examples/contact-view.php:
--------------------------------------------------------------------------------
1 | contacts->read('123_contact_id'); // Set a contact id here
9 | var_dump($contactResult);
10 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
11 | // That means that your accessKey is unknown
12 | echo 'Wrong login';
13 | } catch (\Exception $e) {
14 | var_dump($e->getMessage());
15 | }
16 |
--------------------------------------------------------------------------------
/examples/hlr-view.php:
--------------------------------------------------------------------------------
1 | hlr->read('c8143db0152a58755c80492h61377581'); // Set a message id here
9 | var_dump($hlrResult);
10 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
11 | // That means that your accessKey is unknown
12 | echo 'wrong login';
13 | } catch (\Exception $e) {
14 | var_dump($e->getMessage());
15 | }
16 |
--------------------------------------------------------------------------------
/src/MessageBird/Resources/EmailMessage.php:
--------------------------------------------------------------------------------
1 | object = new Objects\EmailMessage();
18 | $this->setResourceName('verify/messages/email');
19 |
20 | parent::__construct($httpClient);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/MessageBird/Resources/Voice/CallFlows.php:
--------------------------------------------------------------------------------
1 | object = new Objects\Voice\CallFlow();
18 | $this->setResourceName('call-flows');
19 |
20 | parent::__construct($httpClient);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/examples/available-phone-numbers-view.php:
--------------------------------------------------------------------------------
1 | availablePhoneNumbers->getList("nl", []);
9 | var_dump($phoneNumbers);
10 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
11 | var_dump($e->getMessage());
12 | // That means that your accessKey is unknown
13 | print("wrong login\n");
14 | } catch (\Exception $e) {
15 | var_dump($e->getMessage());
16 | }
17 |
--------------------------------------------------------------------------------
/examples/contact-delete.php:
--------------------------------------------------------------------------------
1 | contacts->delete('123_contact_id'); // Set a contact id here
9 | var_dump('Deleted: ' . $deleted);
10 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
11 | // That means that your accessKey is unknown
12 | echo 'Wrong login';
13 | } catch (\Exception $e) {
14 | var_dump($e->getMessage());
15 | }
16 |
--------------------------------------------------------------------------------
/examples/verify-view.php:
--------------------------------------------------------------------------------
1 | verify->read('05a90ee1155d2f4cdd12440v10006813'); // Set a message id here
9 | var_dump($verifyResult);
10 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
11 | // That means that your accessKey is unknown
12 | echo 'wrong login';
13 | } catch (\Exception $e) {
14 | echo $e->getMessage();
15 | }
16 |
--------------------------------------------------------------------------------
/examples/conversations/webhooks-delete.php:
--------------------------------------------------------------------------------
1 | conversationWebhooks->delete('WEBHOOK_ID');
13 | } catch (\Exception $e) {
14 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
15 | }
16 |
--------------------------------------------------------------------------------
/examples/conversations/webhooks-list.php:
--------------------------------------------------------------------------------
1 | conversationWebhooks->getList();
12 |
13 | var_dump($webhooks);
14 | } catch (\Exception $e) {
15 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
16 | }
17 |
--------------------------------------------------------------------------------
/examples/voicemessages-list.php:
--------------------------------------------------------------------------------
1 | voicemessages->getList(['offset' => 100, 'limit' => 30]);
9 | var_dump($voiceMessageList);
10 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
11 | // That means that your accessKey is unknown
12 | echo 'wrong login';
13 | } catch (\Exception $e) {
14 | var_dump($e->getMessage());
15 | }
16 |
--------------------------------------------------------------------------------
/examples/message-view.php:
--------------------------------------------------------------------------------
1 | messages->read('ad86c8c0153a194a59a17e2b71578856'); // Set a message id here
9 | var_dump($messageResult);
10 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
11 | // That means that your accessKey is unknown
12 | echo 'wrong login';
13 | } catch (\Exception $e) {
14 | var_dump($e->getMessage());
15 | }
16 |
--------------------------------------------------------------------------------
/examples/message-delete.php:
--------------------------------------------------------------------------------
1 | messages->delete('deb1fe303539efdf1730124b69920283'); // Set a message id here
9 | var_dump('Deleted: ' . $deleted);
10 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
11 | // That means that your accessKey is unknown
12 | echo 'wrong login';
13 | } catch (\Exception $e) {
14 | var_dump($e->getMessage());
15 | }
16 |
--------------------------------------------------------------------------------
/examples/voice-transcriptions-read.php:
--------------------------------------------------------------------------------
1 | voiceTranscriptions->read('c226420d-f107-4db1-b2f9-4646656a90bc', '4f5ab5f4-c4b6-4586-9255-980bb3fd7336', 'a94f7d51-19b5-4eb8-9e8e-90fce490a577'); // Set call, leg, recording and transcription id here
9 | var_dump($result);
10 | } catch (\Exception $e) {
11 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
12 | }
13 |
--------------------------------------------------------------------------------
/examples/conversations/messages-list.php:
--------------------------------------------------------------------------------
1 | conversationMessages->getList('CONVERSATION_ID');
12 |
13 | var_dump($messages);
14 | } catch (\Exception $e) {
15 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
16 | }
17 |
--------------------------------------------------------------------------------
/examples/voice-webhooks-update.php:
--------------------------------------------------------------------------------
1 | url = 'https://example.com/foobar';
8 | $webhook->token = 'baz';
9 |
10 | try {
11 | $result = $messageBird->voiceWebhooks->update($webhook, 'e5f56d49-4fa2-4802-895d-b0a306f73f76');
12 | var_dump($result);
13 | } catch (\Exception $e) {
14 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
15 | }
16 |
--------------------------------------------------------------------------------
/src/MessageBird/Resources/Conversation/Webhooks.php:
--------------------------------------------------------------------------------
1 | object = new Webhook();
18 | $this->setResourceName(self::RESOURCE_NAME);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/examples/voice-transcriptions-list.php:
--------------------------------------------------------------------------------
1 | voiceTranscriptions->getList('c226420d-f107-4db1-b2f9-4646656a90bc', '4f5ab5f4-c4b6-4586-9255-980bb3fd7336', 'a94f7d51-19b5-4eb8-9e8e-90fce490a577', ['offset' => 100, 'limit' => 30]); // Set a call and leg id here
9 | var_dump($result);
10 | } catch (\Exception $e) {
11 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
12 | }
13 |
--------------------------------------------------------------------------------
/examples/voice-transcriptions-create.php:
--------------------------------------------------------------------------------
1 | voiceTranscriptions->create('c226420d-f107-4db1-b2f9-4646656a90bc', '4f5ab5f4-c4b6-4586-9255-980bb3fd7336', 'a94f7d51-19b5-4eb8-9e8e-90fce490a577');
10 | var_dump($result);
11 | } catch (\Exception $e) {
12 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
13 | }
14 |
--------------------------------------------------------------------------------
/examples/voicemessages-view.php:
--------------------------------------------------------------------------------
1 | voicemessages->read('ca0a8220453bc36ddeb3115a37400870'); // Set a message id here
9 | var_dump($voiceMessageResult);
10 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
11 | // That means that your accessKey is unknown
12 | echo 'wrong login';
13 | } catch (\Exception $e) {
14 | var_dump($e->getMessage());
15 | }
16 |
--------------------------------------------------------------------------------
/src/MessageBird/Resources/Messages.php:
--------------------------------------------------------------------------------
1 | object = new Objects\Message();
18 | $this->setResponseObject(new Objects\MessageResponse());
19 | $this->setResourceName('messages');
20 |
21 | parent::__construct($httpClient);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/examples/lookup-view.php:
--------------------------------------------------------------------------------
1 | lookup->read(31624971134);
9 | var_dump($lookup);
10 |
11 | $lookup = $messageBird->lookup->read("624971134", "NL");
12 | var_dump($lookup);
13 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
14 | // That means that your accessKey is unknown
15 | echo 'wrong login';
16 | } catch (\Exception $e) {
17 | var_dump($e->getMessage());
18 | }
19 |
--------------------------------------------------------------------------------
/examples/conversations/webhooks-read.php:
--------------------------------------------------------------------------------
1 | conversationWebhooks->read('WEBHOOK_ID');
13 |
14 | var_dump($webhook);
15 | } catch (\Exception $e) {
16 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
17 | }
18 |
--------------------------------------------------------------------------------
/examples/emailmessages-view.php:
--------------------------------------------------------------------------------
1 | emailmessages->read('ca0a8220453bc36ddeb3115a37400870'); // Set a message id here
11 | var_dump($emailMessageResult);
12 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
13 | // That means that your accessKey is unknown
14 | echo 'wrong login';
15 | } catch (\Exception $e) {
16 | var_dump($e->getMessage());
17 | }
18 |
--------------------------------------------------------------------------------
/examples/group-create.php:
--------------------------------------------------------------------------------
1 | name = "group_name";
9 |
10 | try {
11 | $groupResult = $messageBird->groups->create($group);
12 | var_dump($groupResult);
13 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
14 | // That means that your accessKey is unknown
15 | echo 'Wrong login';
16 | } catch (\Exception $e) {
17 | echo $e->getMessage();
18 | }
19 |
--------------------------------------------------------------------------------
/examples/group-update.php:
--------------------------------------------------------------------------------
1 | name = 'New group name';
9 |
10 | try {
11 | $groupResult = $messageBird->groups->update($group, 'group_id');
12 | var_dump($groupResult);
13 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
14 | // That means that your accessKey is unknown
15 | echo 'Wrong login';
16 | } catch (\Exception $e) {
17 | echo $e->getMessage();
18 | }
19 |
--------------------------------------------------------------------------------
/examples/phone-numbers-update.php:
--------------------------------------------------------------------------------
1 | tags = ['tag1'];
8 |
9 | try {
10 | $numberResult = $messageBird->phoneNumbers->update($number, '31612345678');
11 | var_dump($numberResult);
12 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
13 | // That means that your accessKey is unknown
14 | print("wrong login\n");
15 | } catch (\Exception $e) {
16 | echo $e->getMessage();
17 | }
18 |
--------------------------------------------------------------------------------
/examples/group-remove-contact-from-group.php:
--------------------------------------------------------------------------------
1 | groups->removeContact($contact_id, $group_id);
11 | var_dump($groupAddContact);
12 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
13 | // That means that your accessKey is unknown
14 | echo 'Wrong login';
15 | } catch (\Exception $e) {
16 | var_dump($e->getMessage());
17 | }
18 |
--------------------------------------------------------------------------------
/examples/partner-account-create.php:
--------------------------------------------------------------------------------
1 | name = 'Name Test';
9 |
10 | try {
11 | $partnerAccountResult = $messageBird->partnerAccounts->create($account);
12 | var_dump($partnerAccountResult);
13 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
14 | // That means that your accessKey is unknown
15 | echo 'wrong login';
16 | } catch (\Exception $e) {
17 | echo $e->getMessage();
18 | }
19 |
--------------------------------------------------------------------------------
/examples/partner-account-update.php:
--------------------------------------------------------------------------------
1 | name = 'Name Test';
9 |
10 | try {
11 | $partnerAccountResult = $messageBird->partnerAccounts->update($account, 1);
12 | var_dump($partnerAccountResult);
13 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
14 | // That means that your accessKey is unknown
15 | echo 'wrong login';
16 | } catch (\Exception $e) {
17 | echo $e->getMessage();
18 | }
19 |
--------------------------------------------------------------------------------
/examples/group-add-contact-to-group.php:
--------------------------------------------------------------------------------
1 | groups->addContacts($contacts, $group_id);
14 | var_dump($groupAddContact);
15 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
16 | // That means that your accessKey is unknown
17 | echo 'Wrong login';
18 | } catch (\Exception $e) {
19 | var_dump($e->getMessage());
20 | }
21 |
--------------------------------------------------------------------------------
/examples/mms-delete.php:
--------------------------------------------------------------------------------
1 | mmsMessages->delete('mms_message_id'); // id here
9 | var_dump('Deleted: ' . $deleted);
10 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
11 | // That means that your accessKey is unknown
12 | echo 'wrong login';
13 | } catch (\MessageBird\Exceptions\BalanceException $e) {
14 | // That means that you are out of credits, so do something about it.
15 | echo 'no balance';
16 | } catch (\Exception $e) {
17 | echo $e->getMessage();
18 | }
19 |
--------------------------------------------------------------------------------
/examples/conversations/list.php:
--------------------------------------------------------------------------------
1 | '10',
13 | 'offset' => '5',
14 | ];
15 |
16 | try {
17 | $conversations = $messageBird->conversations->getList($optionalParameters);
18 |
19 | var_dump($conversations);
20 | } catch (\Exception $e) {
21 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
22 | }
23 |
--------------------------------------------------------------------------------
/examples/signedrequest-verification.php:
--------------------------------------------------------------------------------
1 | verify($request)) {
17 | // The request was invalid, so respond accordingly.
18 | http_response_code(412);
19 | }
20 |
--------------------------------------------------------------------------------
/examples/voice-transcriptions-download.php:
--------------------------------------------------------------------------------
1 | voiceTranscriptions->download('c226420d-f107-4db1-b2f9-4646656a90bc', '4f5ab5f4-c4b6-4586-9255-980bb3fd7336', 'a94f7d51-19b5-4eb8-9e8e-90fce490a577', '44e73d1f-201d-4a7d-963a-9d76bbca6c4f'); // Set call, leg, recording and transcription id here
9 | echo sprintf("Received %d bytes.\n", mb_strlen($data));
10 | echo sprintf("Transcription contents: `%s`.\n", $data);
11 | } catch (\Exception $e) {
12 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
13 | }
14 |
--------------------------------------------------------------------------------
/examples/voice-call-flows-create.php:
--------------------------------------------------------------------------------
1 | action = 'say';
9 | $step->options = [
10 | 'payload' => 'This is a journey into sound.',
11 | 'language' => 'en-GB',
12 | 'voice' => 'male',
13 | ];
14 | $callFlow->steps = [$step];
15 |
16 | try {
17 | $result = $messageBird->voiceCallFlows->create($callFlow);
18 | var_dump($result);
19 | } catch (\Exception $e) {
20 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
21 | }
22 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/Balance.php:
--------------------------------------------------------------------------------
1 | 'content',
13 | ];
14 |
15 | try {
16 | $conversation = $messageBird->conversations->read(
17 | 'CONVERSATION_ID'
18 | );
19 |
20 | var_dump($conversation);
21 | } catch (\Exception $e) {
22 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
23 | }
24 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/Conversation/MessageReference.php:
--------------------------------------------------------------------------------
1 | conversations->read($conversationId);
13 |
14 | $conversation->status = \MessageBird\Objects\Conversation\Conversation::STATUS_ACTIVE;
15 | $messageBird->conversations->update($conversation, $conversationId);
16 | } catch (\Exception $e) {
17 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
18 | }
19 |
--------------------------------------------------------------------------------
/examples/verify-verification.php:
--------------------------------------------------------------------------------
1 | verify->verify('05a90ee1155d2f4cdd12440v10006813', '585438'); // Set a message id and the token here.
9 | var_dump($verifyResult);
10 |
11 | // Check if $verifyResult->getStatus() === MessageBird\Objects\Verify::STATUS_VERIFIED
12 | } catch (\MessageBird\Exceptions\RequestException $e) {
13 | echo 'token incorrect';
14 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
15 | // That means that your accessKey is unknown
16 | echo 'wrong login';
17 | } catch (\Exception $e) {
18 | echo $e->getMessage();
19 | }
20 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/Conversation/SendMessageResult.php:
--------------------------------------------------------------------------------
1 | $value) {
28 | if (!empty($value)) {
29 | $json[$key] = $value;
30 | }
31 | }
32 |
33 | return $json;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/examples/voice-recordings-download.php:
--------------------------------------------------------------------------------
1 | voiceRecordings->download('c226420d-f107-4db1-b2f9-4646656a90bc', '4f5ab5f4-c4b6-4586-9255-980bb3fd7336', 'a94f7d51-19b5-4eb8-9e8e-90fce490a577'); // Set call, leg and recording id here
9 | echo sprintf("Received %d bytes.\n", mb_strlen($data));
10 | $tmpfname = tempnam('/tmp', 'voice-recording-');
11 | $handle = fopen($tmpfname, "w");
12 | fwrite($handle, $data);
13 | fclose($handle);
14 | echo sprintf("Wrote to file: %s\n", $tmpfname);
15 | } catch (\Exception $e) {
16 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
17 | }
18 |
--------------------------------------------------------------------------------
/examples/phone-numbers-create.php:
--------------------------------------------------------------------------------
1 | number = '31612345678';
8 | $numberPurchaseRequest->countryCode = 'NL';
9 | $numberPurchaseRequest->billingIntervalMonths = 1;
10 |
11 | try {
12 | $numberPurchaseRequestResult = $messageBird->phoneNumbers->create($numberPurchaseRequest);
13 | var_dump($numberPurchaseRequestResult);
14 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
15 | // That means that your accessKey is unknown
16 | print("wrong login\n");
17 | } catch (\Exception $e) {
18 | echo $e->getMessage();
19 | }
20 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/Conversation/Fallback.php:
--------------------------------------------------------------------------------
1 | msisdn = 31612345678;
9 | $hlr->reference = "Custom reference";
10 |
11 | try {
12 | $hlrResult = $messageBird->hlr->create($hlr);
13 | var_export($hlrResult);
14 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
15 | // That means that your accessKey is unknown
16 | echo 'wrong login';
17 | } catch (\MessageBird\Exceptions\BalanceException $e) {
18 | // That means that you are out of credits, so do something about it.
19 | echo 'no balance';
20 | } catch (\MessageBird\Exceptions\RequestException $e) {
21 | echo $e->getMessage();
22 | }
23 |
--------------------------------------------------------------------------------
/examples/contact-update.php:
--------------------------------------------------------------------------------
1 | msisdn = '31123456789';
9 | $contact->firstName = 'ChangedFirst';
10 | $contact->lastName = "ChangedLast";
11 | $contact->custom1 = "custom-1b";
12 | $contact->custom2 = "custom-2b";
13 | $contact->custom3 = "custom-3b";
14 | $contact->custom4 = "custom-4b";
15 |
16 |
17 | try {
18 | $groupResult = $messageBird->contacts->update($contact, 'contact_id');
19 | var_dump($groupResult);
20 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
21 | // That means that your accessKey is unknown
22 | echo 'Wrong login';
23 | } catch (\Exception $e) {
24 | echo $e->getMessage();
25 | }
26 |
--------------------------------------------------------------------------------
/examples/contact-create.php:
--------------------------------------------------------------------------------
1 | msisdn = "31123456780";
9 | $contact->firstName = "FirstName";
10 | $contact->lastName = "LastName";
11 | $contact->custom1 = "test_custom1";
12 | $contact->custom2 = "test_custom2";
13 | $contact->custom3 = "test_custom3";
14 | $contact->custom4 = "test_custom4";
15 |
16 |
17 | try {
18 | $contactResult = $messageBird->contacts->create($contact);
19 | var_dump($contactResult);
20 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
21 | // That means that your accessKey is unknown
22 | echo 'Wrong login';
23 | } catch (\Exception $e) {
24 | echo $e->getMessage();
25 | }
26 |
--------------------------------------------------------------------------------
/examples/voice-calls-create.php:
--------------------------------------------------------------------------------
1 | source = '31971234567';
8 | $call->destination = '31612345678';
9 | $callFlow = new \MessageBird\Objects\Voice\CallFlow();
10 | $step = new \MessageBird\Objects\Voice\Step();
11 | $step->action = 'say';
12 | $step->options = [
13 | 'payload' => 'This is a journey into sound.',
14 | 'language' => 'en-GB',
15 | 'voice' => 'male',
16 | ];
17 | $callFlow->steps = [$step];
18 | $call->callFlow = $callFlow;
19 |
20 | try {
21 | $result = $messageBird->voiceCalls->create($call);
22 | var_dump($result);
23 | } catch (\Exception $e) {
24 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
25 | }
26 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/Conversation/HSM/Language.php:
--------------------------------------------------------------------------------
1 | id;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/examples/message-create.php:
--------------------------------------------------------------------------------
1 | originator = 'YourBrand';
9 | $message->recipients = [31612345678];
10 | $message->body = 'This is a test message.';
11 |
12 | try {
13 | $messageResult = $messageBird->messages->create($message);
14 | var_dump($messageResult);
15 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
16 | // That means that your accessKey is unknown
17 | echo 'wrong login';
18 | } catch (\MessageBird\Exceptions\BalanceException $e) {
19 | // That means that you are out of credits, so do something about it.
20 | echo 'no balance';
21 | } catch (\Exception $e) {
22 | echo $e->getMessage();
23 | }
24 |
--------------------------------------------------------------------------------
/examples/verify-create.php:
--------------------------------------------------------------------------------
1 | recipient = 31612345678;
9 |
10 | $extraOptions = [
11 | 'originator' => 'YourBrand',
12 | 'timeout' => 60,
13 | ];
14 |
15 | try {
16 | $verifyResult = $messageBird->verify->create($verify, $extraOptions);
17 | var_dump($verifyResult);
18 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
19 | // That means that your accessKey is unknown
20 | echo 'wrong login';
21 | } catch (\MessageBird\Exceptions\BalanceException $e) {
22 | // That means that you are out of credits, so do something about it.
23 | echo 'no balance';
24 | } catch (\Exception $e) {
25 | echo $e->getMessage();
26 | }
27 |
--------------------------------------------------------------------------------
/examples/message-create-unicode.php:
--------------------------------------------------------------------------------
1 | originator = 'YourBrand';
9 | $message->recipients = [31612345678];
10 | $message->body = 'This is a test message with a smiling emoji 😀.';
11 | $message->datacoding = 'unicode';
12 |
13 | try {
14 | $messageResult = $messageBird->messages->create($message);
15 | var_dump($messageResult);
16 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
17 | // That means that your accessKey is unknown
18 | echo 'wrong login';
19 | } catch (\MessageBird\Exceptions\BalanceException $e) {
20 | // That means that you are out of credits, so do something about it.
21 | echo 'no balance';
22 | } catch (\Exception $e) {
23 | echo $e->getMessage();
24 | }
25 |
--------------------------------------------------------------------------------
/examples/conversations/create.php:
--------------------------------------------------------------------------------
1 | text = 'Hello world';
13 |
14 | $message = new \MessageBird\Objects\Conversation\Message();
15 | $message->channelId = 'CHANNEL_ID';
16 | $message->content = $content;
17 | $message->to = 'RECIPIENT'; // Channel-specific, e.g. MSISDN for SMS.
18 | $message->type = 'text';
19 |
20 | try {
21 | $conversation = $messageBird->conversations->start($message);
22 |
23 | var_dump($conversation);
24 | } catch (\Exception $e) {
25 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
26 | }
27 |
--------------------------------------------------------------------------------
/examples/signed-request-validation.php:
--------------------------------------------------------------------------------
1 | validateRequestFromGlobals();
11 | } catch (\MessageBird\Exceptions\ValidationException $e) {
12 | // The request was invalid, so respond accordingly.
13 | http_response_code(412);
14 | }
15 |
16 | // Or directly verify the signature of the incoming request
17 | $signature = 'JWT_TOKEN_STRING';
18 | $url = 'https://yourdomain.com/path';
19 | $body = 'REQUEST_BODY';
20 |
21 | try {
22 | $request = $requestValidator->validateSignature($signature, $url, $body);
23 | } catch (\MessageBird\Exceptions\ValidationException $e) {
24 | // The request was invalid, so respond accordingly.
25 | http_response_code(412);
26 | }
27 |
--------------------------------------------------------------------------------
/examples/conversations/messages-create-location.php:
--------------------------------------------------------------------------------
1 | location = [
11 | 'latitude' => 52.379112,
12 | 'longitude' => 4.900384,
13 | ];
14 |
15 | $message = new \MessageBird\Objects\Conversation\Message();
16 | $message->channelId = 'CHANNEL_ID';
17 | $message->content = $content;
18 | $message->to = 'RECIPIENT';
19 | $message->type = \MessageBird\Objects\Conversation\Content::TYPE_LOCATION; // 'location'
20 |
21 | try {
22 | $conversation = $messageBird->conversationMessages->create(
23 | 'CONVERSATION_ID',
24 | $message
25 | );
26 |
27 | var_dump($conversation);
28 | } catch (\Exception $e) {
29 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
30 | }
31 |
--------------------------------------------------------------------------------
/examples/mms-create.php:
--------------------------------------------------------------------------------
1 | originator = 'YourNumber';
9 | $mmsMessage->recipients = [31612345678];
10 | $mmsMessage->subject = "Check out this cool MMS";
11 | $mmsMessage->body = 'Have you seen this logo?';
12 | $mmsMessage->mediaUrls = ['https://www.messagebird.com/assets/images/og/messagebird.gif'];
13 |
14 | try {
15 | $mmsMessageResult = $messageBird->mmsMessages->create($mmsMessage);
16 | var_dump($mmsMessageResult);
17 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
18 | // That means that your accessKey is unknown
19 | echo 'wrong login';
20 | } catch (\MessageBird\Exceptions\BalanceException $e) {
21 | // That means that you are out of credits, so do something about it.
22 | echo 'no balance';
23 | } catch (\Exception $e) {
24 | echo $e->getMessage();
25 | }
26 |
--------------------------------------------------------------------------------
/examples/conversations/messages-create-text.php:
--------------------------------------------------------------------------------
1 | text = 'Hello world';
13 |
14 | $message = new \MessageBird\Objects\Conversation\Message();
15 | $message->channelId = 'CHANNEL_ID';
16 | $message->content = $content;
17 | $message->to = 'RECIPIENT';
18 | $message->type = \MessageBird\Objects\Conversation\Content::TYPE_TEXT;
19 |
20 | try {
21 | $conversation = $messageBird->conversationMessages->create(
22 | 'CONVERSATION_ID',
23 | $message
24 | );
25 |
26 | var_dump($conversation);
27 | } catch (\Exception $e) {
28 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
29 | }
30 |
--------------------------------------------------------------------------------
/examples/conversations/send.php:
--------------------------------------------------------------------------------
1 | text = 'Hello world';
13 |
14 | $sendMessage = new \MessageBird\Objects\Conversation\SendMessage();
15 | $sendMessage->from = 'CHANNEL_ID';
16 | $sendMessage->to = 'RECIPIENT'; // Channel-specific, e.g. MSISDN for SMS.
17 | $sendMessage->content = $content;
18 | $sendMessage->type = 'text';
19 |
20 | try {
21 | $sendResult = $messageBird->conversationSend->send($sendMessage);
22 |
23 | var_dump($sendResult);
24 | } catch (\Exception $e) {
25 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
26 | }
27 |
--------------------------------------------------------------------------------
/examples/lookup-hlr-view.php:
--------------------------------------------------------------------------------
1 | msisdn = '31624971134';
10 | $hlrObject->reference = "yoloswag3001";
11 |
12 | // create a new hlr request
13 | $hlr = $messageBird->lookupHlr->create($hlrObject);
14 | var_dump($hlr);
15 |
16 | // pool for the results
17 | $poolCount = 10;
18 | while ($poolCount--) {
19 | $hlr = $messageBird->lookupHlr->read($hlrObject->msisdn);
20 | if ($hlr->status !== \MessageBird\Objects\Hlr::STATUS_SENT) {
21 | // we have something
22 | var_dump($hlr);
23 | break;
24 | }
25 | sleep(0.5);
26 | }
27 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
28 | // That means that your accessKey is unknown
29 | echo 'wrong login';
30 | } catch (\Exception $e) {
31 | var_dump($e->getMessage());
32 | }
33 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/PartnerAccount/Account.php:
--------------------------------------------------------------------------------
1 | $this->name,
27 | ], \JSON_THROW_ON_ERROR);
28 | }
29 |
30 | /**
31 | * @param mixed $object
32 | */
33 | public function loadFromArray($object): Account
34 | {
35 | parent::loadFromArray($object);
36 |
37 | if (empty($this->accessKeys)) {
38 | return $this;
39 | }
40 |
41 | foreach ($this->accessKeys as &$item) {
42 | $accessKey = new AccessKey();
43 | $item = $accessKey->loadFromArray($item);
44 | }
45 |
46 | return $this;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/examples/voicemessages-create.php:
--------------------------------------------------------------------------------
1 | recipients = [31654286496];
9 | $voiceMessage->body = 'This is a test message. The message is converted to speech and the recipient is called on his mobile.';
10 | $voiceMessage->language = 'en-gb';
11 | $voiceMessage->voice = 'female';
12 | $voiceMessage->ifMachine = 'continue'; // We don't care if it is a machine.
13 |
14 | try {
15 | $voiceMessageResult = $messageBird->voicemessages->create($voiceMessage);
16 | var_dump($voiceMessageResult);
17 | } catch (\MessageBird\Exceptions\AuthenticateException $e) {
18 | // That means that your accessKey is unknown
19 | echo 'wrong login';
20 | } catch (\MessageBird\Exceptions\BalanceException $e) {
21 | // That means that you are out of credits, so do something about it.
22 | echo 'no balance';
23 | } catch (\Exception $e) {
24 | echo $e->getMessage();
25 | }
26 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/Base.php:
--------------------------------------------------------------------------------
1 | $value) {
25 | if (property_exists($this, $key)) {
26 | $this->$key = $value;
27 | }
28 | }
29 | }
30 | return $this;
31 | }
32 |
33 | /**
34 | * @param stdClass $object
35 | * @return self
36 | */
37 | public function loadFromStdclass(stdClass $object)
38 | {
39 | foreach ($object as $key => $value) {
40 | if (property_exists($this, $key)) {
41 | $this->$key = $value;
42 | }
43 | }
44 | return $this;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/examples/conversations/messages-create-media.php:
--------------------------------------------------------------------------------
1 | image = [
12 | 'url' => 'https://cdn-gc.messagebird.com/assets/images/logo.png'
13 | ];
14 |
15 | $message = new \MessageBird\Objects\Conversation\Message();
16 | $message->channelId = 'CHANNEL_ID';
17 | $message->content = $content;
18 | $message->to = 'RECIPIENT_MSISDN';
19 | $message->type = \MessageBird\Objects\Conversation\Content::TYPE_IMAGE; // 'image'
20 |
21 | try {
22 | // Using a contactId instead of a conversationId is also supported.
23 | $conversation = $messageBird->conversationMessages->create(
24 | 'CONVERSATION_ID',
25 | $message
26 | );
27 |
28 | var_dump($conversation);
29 | } catch (\Exception $e) {
30 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
31 | }
32 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "messagebird/php-rest-api",
3 | "description": "MessageBird REST API client for PHP",
4 | "type": "library",
5 | "homepage": "https://github.com/messagebird/php-rest-api",
6 | "license": "BSD-2-Clause",
7 | "authors": [
8 | {
9 | "name": "MessageBird",
10 | "email": "info@messagebird.com"
11 | }
12 | ],
13 | "support": {
14 | "docs": "https://developers.messagebird.com/api",
15 | "issues": "https://github.com/messagebird/php-rest-api/issues",
16 | "source": "https://github.com/messagebird/php-rest-api"
17 | },
18 | "require": {
19 | "php": ">=7.3|~8.0.0|~8.1.0|~8.2.0",
20 | "ext-curl": "*",
21 | "ext-json": "*",
22 | "firebase/php-jwt": "^5.5.1|^6.2"
23 | },
24 | "require-dev": {
25 | "phpunit/phpunit": "^9.5.14",
26 | "vimeo/psalm": "4.18.1"
27 | },
28 | "autoload": {
29 | "psr-4": {
30 | "MessageBird\\": "src/MessageBird/"
31 | }
32 | },
33 | "autoload-dev": {
34 | "psr-4": {
35 | "Tests\\": "tests/"
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/examples/conversations/enable-whatsapp-sandbox.php:
--------------------------------------------------------------------------------
1 | text = 'Hello world';
17 |
18 | $message = new \MessageBird\Objects\Conversation\Message();
19 | $message->channelId = 'WHATSAPP_SANDBOX_CHANNEL_ID';
20 | $message->content = $content;
21 | $message->to = 'RECIPIENT'; // Channel-specific, e.g. MSISDN for SMS.
22 | $message->type = 'text';
23 |
24 | try {
25 | $conversation = $messageBird->conversations->start($message);
26 |
27 | var_dump($conversation);
28 | } catch (\Exception $e) {
29 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
30 | }
31 |
--------------------------------------------------------------------------------
/autoload.php:
--------------------------------------------------------------------------------
1 | recipient = 'Client Name ';
14 |
15 | $extraOptions = [
16 | 'type' => 'email',
17 | // This email domain needs to be set up as an email channel in your account at https://dashboard.messagebird.com/en/channels/
18 | 'originator' => 'Email Verification ',
19 | 'timeout' => 60,
20 | ];
21 |
22 | try {
23 | $verifyResult = $messageBird->verify->create($verify, $extraOptions);
24 | var_dump($verifyResult);
25 | } catch (AuthenticateException $e) {
26 | // That means that your accessKey is unknown
27 | echo 'wrong login';
28 | } catch (BalanceException $e) {
29 | // That means that you are out of credits, so do something about it.
30 | echo 'no balance';
31 | } catch (\Exception $e) {
32 | echo $e->getMessage();
33 | }
34 |
--------------------------------------------------------------------------------
/examples/conversations/webhooks-create.php:
--------------------------------------------------------------------------------
1 | channelId = 'CHANNEL_ID';
15 | $webhook->url = 'https://example.com/webhook';
16 | $webhook->events = [
17 | \MessageBird\Objects\Conversation\Webhook::EVENT_CONVERSATION_CREATED,
18 | \MessageBird\Objects\Conversation\Webhook::EVENT_MESSAGE_CREATED,
19 |
20 | // Other options:
21 | // \MessageBird\Objects\Conversation\Webhook::EVENT_CONVERSATION_UPDATED,
22 | // \MessageBird\Objects\Conversation\Webhook::EVENT_MESSAGE_UPDATED,
23 | ];
24 |
25 | $messageBird->conversationWebhooks->create($webhook);
26 | } catch (\Exception $e) {
27 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
28 | }
29 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/Voice/Webhook.php:
--------------------------------------------------------------------------------
1 | id;
45 | }
46 |
47 | public function getCreatedAt(): string
48 | {
49 | return $this->createdAt;
50 | }
51 |
52 | public function getUpdatedAt(): string
53 | {
54 | return $this->updatedAt;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/Number.php:
--------------------------------------------------------------------------------
1 | object = new Objects\Verify();
22 | $this->setResourceName('verify');
23 |
24 | parent::__construct($httpClient);
25 | }
26 |
27 | /**
28 | * @param mixed $id
29 | * @param mixed $token
30 | *
31 | * @return Objects\Balance|Objects\Conversation\Conversation|Objects\Hlr|Objects\Lookup|Objects\Message|Objects\Verify|Objects\VoiceMessage|null
32 | *
33 | * @throws HttpException
34 | * @throws RequestException
35 | * @throws ServerException|AuthenticateException
36 | */
37 | public function verify($id, $token)
38 | {
39 | $resourceName = $this->resourceName . (($id) ? '/' . $id : null);
40 | [, , $body] = $this->httpClient->performHttpRequest(
41 | Common\HttpClient::REQUEST_GET,
42 | $resourceName,
43 | ['token' => $token]
44 | );
45 | return $this->processRequest($body);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/Voice/Transcription.php:
--------------------------------------------------------------------------------
1 | id;
47 | }
48 |
49 | public function getRecordingId(): string
50 | {
51 | return $this->recordingId;
52 | }
53 |
54 | public function getError(): string
55 | {
56 | return $this->error;
57 | }
58 |
59 | public function getCreatedAt(): string
60 | {
61 | return $this->createdAt;
62 | }
63 |
64 | public function getUpdatedAt(): string
65 | {
66 | return $this->updatedAt;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/EmailMessage.php:
--------------------------------------------------------------------------------
1 | id;
47 | }
48 |
49 | /**
50 | * Get the status
51 | */
52 | public function getStatus(): string
53 | {
54 | return $this->status;
55 | }
56 |
57 | /**
58 | * @return int|null
59 | */
60 | public function getFailureCode()
61 | {
62 | return $this->failure_code;
63 | }
64 |
65 | /**
66 | * @return string|null
67 | */
68 | public function getFailureDescription()
69 | {
70 | return $this->failure_description;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/Recipients.php:
--------------------------------------------------------------------------------
1 | items as &$item) {
51 | $recipient = new Recipient();
52 | $recipient->loadFromArray($item);
53 |
54 | $item = $recipient;
55 | }
56 |
57 | return $this;
58 | }
59 |
60 | public function loadFromStdclass(stdClass $object): self
61 | {
62 | parent::loadFromStdclass($object);
63 |
64 | foreach ($this->items as &$item) {
65 | $recipient = new Recipient();
66 | $recipient->loadFromStdclass($item);
67 |
68 | $item = $recipient;
69 | }
70 |
71 | return $this;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/examples/conversations/create-hsm.php:
--------------------------------------------------------------------------------
1 | default = 'YOUR FIRST TEMPLATE PARAM VALUE';
11 |
12 | $hsmParam2 = new \MessageBird\Objects\Conversation\HSM\Params();
13 | $hsmParam2->default = 'YOUR SECOND TEMPLATE PARAM VALUE';
14 |
15 | $hsmLanguage = new \MessageBird\Objects\Conversation\HSM\Language();
16 | $hsmLanguage->policy = \MessageBird\Objects\Conversation\HSM\Language::DETERMINISTIC_POLICY;
17 | //$hsmLanguage->policy = \MessageBird\Objects\Conversation\HSM\Language::FALLBACK_POLICY;
18 | $hsmLanguage->code = 'YOUR LANGUAGE CODE';
19 |
20 | $hsm = new \MessageBird\Objects\Conversation\HSM\Message();
21 | $hsm->templateName = 'YOUR TEMPLATE NAME';
22 | $hsm->namespace = 'YOUR NAMESPACE';
23 | $hsm->params = [$hsmParam1, $hsmParam2];
24 | $hsm->language = $hsmLanguage;
25 |
26 | $content = new \MessageBird\Objects\Conversation\Content();
27 | $content->hsm = $hsm;
28 |
29 | $message = new \MessageBird\Objects\Conversation\Message();
30 | $message->channelId = 'YOUR CHANNEL ID';
31 | $message->content = $content;
32 | $message->to = 'YOUR MSISDN';
33 | $message->type = 'hsm';
34 |
35 | try {
36 | $conversation = $messageBird->conversations->start($message);
37 |
38 | var_dump($conversation);
39 | } catch (\Exception $e) {
40 | echo sprintf("%s: %s", get_class($e), $e->getMessage());
41 | }
42 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/Voice/Recording.php:
--------------------------------------------------------------------------------
1 | id;
54 | }
55 |
56 | public function getLegId(): string
57 | {
58 | return $this->legId;
59 | }
60 |
61 | public function getStatus(): string
62 | {
63 | return $this->status;
64 | }
65 |
66 | public function getDuration(): int
67 | {
68 | return $this->duration;
69 | }
70 |
71 | public function getCreatedAt(): string
72 | {
73 | return $this->createdAt;
74 | }
75 |
76 | public function getUpdatedAt(): string
77 | {
78 | return $this->updatedAt;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/MessageBird/Resources/Lookup.php:
--------------------------------------------------------------------------------
1 | object = new Objects\Lookup();
23 | $this->setResourceName('lookup');
24 |
25 | parent::__construct($httpClient);
26 | }
27 |
28 | /**
29 | * @no-named-arguments
30 | *
31 | * @param string|int $phoneNumber
32 | * @param string|null $countryCode
33 | *
34 | * @return Objects\Balance|Objects\Conversation\Conversation|Objects\Hlr|Objects\Lookup|Objects\Message|Objects\Verify|Objects\VoiceMessage|null
35 | *
36 | * @throws HttpException
37 | * @throws RequestException
38 | * @throws ServerException
39 | * @throws AuthenticateException
40 | */
41 | public function read($phoneNumber = null, ?string $countryCode = null)
42 | {
43 | if (empty($phoneNumber)) {
44 | throw new InvalidArgumentException('The phone number cannot be empty.');
45 | }
46 | $query = null;
47 | if ($countryCode !== null) {
48 | $query = ["countryCode" => $countryCode];
49 | }
50 | $resourceName = $this->resourceName . '/' . $phoneNumber;
51 | [, , $body] = $this->httpClient->performHttpRequest(Common\HttpClient::REQUEST_GET, $resourceName, $query);
52 | return $this->processRequest($body);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/Voice/CallFlow.php:
--------------------------------------------------------------------------------
1 | title == null) {
47 | unset($this->title);
48 | }
49 | }
50 |
51 | /**
52 | * @inheritdoc
53 | */
54 | public function loadFromArray($object): self
55 | {
56 | parent::loadFromArray($object);
57 |
58 | foreach ($this->steps as &$item) {
59 | $step = new Step();
60 | $step->loadFromArray($item);
61 |
62 | $item = $step;
63 | }
64 |
65 | return $this;
66 | }
67 |
68 | public function getId()
69 | {
70 | return $this->id;
71 | }
72 |
73 | public function getCreatedAt(): string
74 | {
75 | return $this->createdAt;
76 | }
77 |
78 | public function getUpdatedAt(): string
79 | {
80 | return $this->updatedAt;
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/MessageBird/Resources/Conversation/Send.php:
--------------------------------------------------------------------------------
1 | object = new SendMessageResult();
27 | $this->setResourceName(self::RESOURCE_NAME);
28 | }
29 |
30 | /**
31 | * Starts a conversation or adding a message to the conversation when a conversation with the contact already exist.
32 | *
33 | * @return Balance|Conversation|Hlr|Lookup|Message|Verify|VoiceMessage|null
34 | *
35 | * @throws Exceptions\AuthenticateException
36 | * @throws Exceptions\BalanceException
37 | * @throws Exceptions\HttpException
38 | * @throws Exceptions\RequestException
39 | * @throws Exceptions\ServerException
40 | * @throws \JsonException
41 | */
42 | public function send(SendMessage $object, ?array $query = null)
43 | {
44 | $body = json_encode($object, \JSON_THROW_ON_ERROR);
45 |
46 | [, , $resultBody] = $this->httpClient->performHttpRequest(
47 | HttpClient::REQUEST_POST,
48 | $this->getResourceName(),
49 | $query,
50 | $body
51 | );
52 |
53 | return $this->processRequest($resultBody);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/MessageBird/Resources/PhoneNumbers.php:
--------------------------------------------------------------------------------
1 | object = new Objects\Number();
23 | $this->setResourceName('phone-numbers');
24 |
25 | parent::__construct($httpClient);
26 | }
27 |
28 | /**
29 | * @param mixed $object
30 | * @param mixed $id
31 | *
32 | * @return Objects\Balance|Objects\Conversation\Conversation|Objects\Hlr|Objects\Lookup|Objects\Message|Objects\Verify|Objects\VoiceMessage|null
33 | *
34 | * @throws \JsonException
35 | * @throws \MessageBird\Exceptions\AuthenticateException
36 | * @throws \MessageBird\Exceptions\HttpException
37 | * @throws \MessageBird\Exceptions\RequestException
38 | * @throws \MessageBird\Exceptions\ServerException
39 | * @internal param array $parameters
40 | */
41 | public function update($object, $id)
42 | {
43 | $objVars = get_object_vars($object);
44 | $body = [];
45 | foreach ($objVars as $key => $value) {
46 | if ($value !== null) {
47 | $body[$key] = $value;
48 | }
49 | }
50 |
51 | $resourceName = $this->resourceName . ($id ? '/' . $id : null);
52 | $body = json_encode($body, \JSON_THROW_ON_ERROR);
53 |
54 | // This override is only needed to use the PATCH http method
55 | [, , $body] = $this->httpClient->performHttpRequest(
56 | HttpClient::REQUEST_PATCH,
57 | $resourceName,
58 | false,
59 | $body
60 | );
61 | return $this->processRequest($body);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/Conversation/Contact.php:
--------------------------------------------------------------------------------
1 | customDetails)) {
78 | $this->customDetails = (array)$this->customDetails;
79 | }
80 |
81 | return $this;
82 | }
83 |
84 | public function loadFromStdclass(stdClass $object): self
85 | {
86 | parent::loadFromStdclass($object);
87 |
88 | if (!empty($this->customDetails)) {
89 | $this->customDetails = (array)$this->customDetails;
90 | }
91 |
92 | return $this;
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/Conversation/SendMessage.php:
--------------------------------------------------------------------------------
1 | $value) {
81 | if (!empty($value)) {
82 | $json[$key] = $value;
83 | }
84 | }
85 |
86 | return $json;
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/Conversation/Channel.php:
--------------------------------------------------------------------------------
1 | callFlow)) {
76 | $callFlow = new CallFlow();
77 | $this->callFlow = $callFlow->loadFromArray($this->callFlow);
78 | }
79 |
80 | return $this;
81 | }
82 |
83 | public function getId(): string
84 | {
85 | return $this->id;
86 | }
87 |
88 | public function getNumberId(): string
89 | {
90 | return $this->numberId;
91 | }
92 |
93 | public function getStatus(): string
94 | {
95 | return $this->status;
96 | }
97 |
98 | public function getCreatedAt(): string
99 | {
100 | return $this->createdAt;
101 | }
102 |
103 | public function getUpdatedAt(): string
104 | {
105 | return $this->updatedAt;
106 | }
107 |
108 | public function getEndedAt(): string
109 | {
110 | return $this->endedAt;
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/Conversation/Webhook.php:
--------------------------------------------------------------------------------
1 | $value) {
83 | if (!empty($value)) {
84 | $json[$key] = $value;
85 | }
86 | }
87 |
88 | return $json;
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/Group.php:
--------------------------------------------------------------------------------
1 | id;
63 | }
64 |
65 | /**
66 | * Get the created href
67 | */
68 | public function getHref(): string
69 | {
70 | return $this->href;
71 | }
72 |
73 | /**
74 | * Get the $createdDatetime value
75 | */
76 | public function getCreatedDatetime(): string
77 | {
78 | return $this->createdDatetime;
79 | }
80 |
81 | /**
82 | * Get the $updatedDatetime value
83 | */
84 | public function getUpdatedDatetime(): ?string
85 | {
86 | return $this->createdDatetime;
87 | }
88 |
89 | public function getContacts(): stdClass
90 | {
91 | return $this->contacts;
92 | }
93 |
94 | /**
95 | * @deprecated 2.2.0 No longer used by internal code, please switch to {@see self::loadFromStdclass()}
96 | *
97 | * @param mixed $object
98 | *
99 | * @return $this|void
100 | */
101 | public function loadFromArray($object): self
102 | {
103 | return parent::loadFromArray($object);
104 | }
105 |
106 | public function loadFromStdclass(stdClass $object): self
107 | {
108 | return parent::loadFromStdclass($object);
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/src/MessageBird/Common/ResponseError.php:
--------------------------------------------------------------------------------
1 | errors)) {
41 | foreach ($body->errors as $error) {
42 | // Voice API returns errors with a "message" field instead of "description".
43 | // This ensures all errors have a description set.
44 | if (!empty($error->message)) {
45 | $error->description = $error->message;
46 | unset($error->message);
47 | }
48 |
49 | if ($error->code === self::NOT_ENOUGH_CREDIT) {
50 | throw new Exceptions\BalanceException($this->getExceptionMessage($error));
51 | } elseif ($error->code === self::REQUEST_NOT_ALLOWED) {
52 | throw new Exceptions\AuthenticateException($this->getExceptionMessage($error));
53 | }
54 |
55 | $this->errors[] = $error;
56 | }
57 | }
58 | }
59 |
60 | /**
61 | * Get the exception message for the provided error.
62 | *
63 | * @param mixed $error
64 | *
65 | * @return string
66 | */
67 | private function getExceptionMessage($error)
68 | {
69 | return sprintf(self::EXCEPTION_MESSAGE, $error->description);
70 | }
71 |
72 | /**
73 | * Get a string of all of this response's concatenated error descriptions.
74 | *
75 | * @return string
76 | */
77 | public function getErrorString()
78 | {
79 | $errorDescriptions = [];
80 |
81 | foreach ($this->errors as $error) {
82 | $errorDescriptions[] = $error->description;
83 | }
84 |
85 | return implode(', ', $errorDescriptions);
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/src/MessageBird/Resources/AvailablePhoneNumbers.php:
--------------------------------------------------------------------------------
1 | httpClient = $httpClient;
25 | }
26 |
27 | /**
28 | * @return Objects\BaseList|Objects\Number
29 | *
30 | * @throws Exceptions\AuthenticateException
31 | * @throws Exceptions\BalanceException
32 | * @throws Exceptions\HttpException
33 | * @throws Exceptions\RequestException
34 | * @throws Exceptions\ServerException
35 | * @throws \JsonException
36 | */
37 | public function getList(string $countryCode, array $parameters = [])
38 | {
39 | [$status, , $body] = $this->httpClient->performHttpRequest(
40 | HttpClient::REQUEST_GET,
41 | "available-phone-numbers/$countryCode",
42 | $parameters
43 | );
44 |
45 | if ($status !== 200) {
46 | return $this->processRequest($body);
47 | }
48 | $body = json_decode($body, null, 512, \JSON_THROW_ON_ERROR);
49 |
50 | $items = $body->items;
51 | unset($body->items);
52 |
53 | $baseList = new Objects\BaseList();
54 | $baseList->loadFromStdclass($body);
55 |
56 | foreach ($items as $item) {
57 | $object = new Objects\Number();
58 | $itemObject = $object->loadFromStdclass($item);
59 | $baseList->items[] = $itemObject;
60 | }
61 | return $baseList;
62 | }
63 |
64 | /**
65 | * @throws Exceptions\AuthenticateException
66 | * @throws Exceptions\BalanceException
67 | * @throws Exceptions\ServerException
68 | * @throws Exceptions\RequestException
69 | */
70 | private function processRequest(?string $body): Objects\Number
71 | {
72 | if ($body === null) {
73 | throw new Exceptions\ServerException('Got an invalid JSON response from the server.');
74 | }
75 |
76 | try {
77 | $body = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
78 | } catch (\JsonException $e) {
79 | throw new Exceptions\ServerException('Got an invalid JSON response from the server.');
80 | }
81 |
82 | if (!empty($body->errors)) {
83 | $responseError = new Common\ResponseError($body);
84 | throw new Exceptions\RequestException($responseError->getErrorString());
85 | }
86 |
87 | return (new Objects\Number())->loadFromStdclass($body->data[0]);
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/Recipient.php:
--------------------------------------------------------------------------------
1 | id;
81 | }
82 |
83 | /**
84 | * Get the created href
85 | */
86 | public function getHref(): string
87 | {
88 | return $this->href;
89 | }
90 |
91 | /**
92 | * Get the date and time the resource was created
93 | */
94 | public function getCreatedDatetime(): string
95 | {
96 | return $this->createdDatetime;
97 | }
98 |
99 | /**
100 | * Get the date and time the resource was created
101 | */
102 | public function getStatusDatetime(): string
103 | {
104 | return $this->statusDatetime;
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/Voice/Leg.php:
--------------------------------------------------------------------------------
1 | id;
83 | }
84 |
85 | public function getCallId(): string
86 | {
87 | return $this->callId;
88 | }
89 |
90 | public function getSource(): string
91 | {
92 | return $this->source;
93 | }
94 |
95 | public function getDestination(): string
96 | {
97 | return $this->destination;
98 | }
99 |
100 | public function getStatus(): string
101 | {
102 | return $this->status;
103 | }
104 |
105 | public function getDirection(): string
106 | {
107 | return $this->direction;
108 | }
109 |
110 | public function getCreatedAt(): string
111 | {
112 | return $this->createdAt;
113 | }
114 |
115 | public function getUpdatedAt(): string
116 | {
117 | return $this->updatedAt;
118 | }
119 |
120 | public function getAnsweredAt(): string
121 | {
122 | return $this->answeredAt;
123 | }
124 |
125 | public function getEndedAt(): string
126 | {
127 | return $this->endedAt;
128 | }
129 | }
130 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | MessageBird's REST API for PHP
2 | ===============================
3 | This repository contains the open source PHP client for MessageBird's REST API. Documentation can be found at: https://developers.messagebird.com/
4 |
5 | [](https://github.com/messagebird/php-rest-api/actions/workflows/tests.yml?query=branch%3Amaster)
6 | [](https://packagist.org/packages/messagebird/php-rest-api)
7 | [](https://packagist.org/packages/messagebird/php-rest-api)
8 |
9 | Requirements
10 | -----
11 |
12 | - [Sign up](https://www.messagebird.com/en/signup) for a free MessageBird account
13 | - Create a new access_key in the developers sections
14 | - MessageBird API client for PHP requires PHP >= 7.3.
15 |
16 | Installation
17 | -----
18 |
19 | #### Composer installation
20 |
21 | - [Download composer](https://getcomposer.org/doc/00-intro.md#installation-nix)
22 | - Run `composer require messagebird/php-rest-api`.
23 |
24 | #### Manual installation
25 |
26 | When you do not use Composer. You can git checkout or download [this repository](https://github.com/messagebird/php-rest-api/archive/master.zip) and include the MessageBird API client manually.
27 |
28 |
29 | Usage
30 | -----
31 |
32 | We have put some self-explanatory examples in the *examples* directory, but here is a quick breakdown on how it works. First, you need to set up a **MessageBird\Client**. Be sure to replace **YOUR_ACCESS_KEY** with something real.
33 |
34 | ```php
35 | require 'autoload.php';
36 |
37 | $messageBird = new \MessageBird\Client('YOUR_ACCESS_KEY');
38 |
39 | ```
40 |
41 | That's easy enough. Now we can query the server for information. Lets use getting your balance overview as an example:
42 |
43 | ```php
44 | // Get your balance
45 | $balance = $messageBird->balance->read();
46 | ```
47 |
48 |
49 | Conversations WhatsApp Sandbox
50 | -------------
51 |
52 | To use the WhatsApp sandbox you need to add `\MessageBird\Client::ENABLE_CONVERSATIONSAPI_WHATSAPP_SANDBOX` to the list of features you want enabled. Don't forget to replace `YOUR_ACCESS_KEY` with your actual access key.
53 |
54 | ```php
55 | $messageBird = new \MessageBird\Client('YOUR_ACCESS_KEY', null, [\MessageBird\Client::ENABLE_CONVERSATIONSAPI_WHATSAPP_SANDBOX]);
56 | ```
57 |
58 | If you use a custom `HttpClient` you will have to manually direct Conversation API request to the WhatsApp sandbox endpoint.
59 |
60 |
61 | Documentation
62 | ----
63 | Complete documentation, instructions, and examples are available at:
64 | [https://developers.messagebird.com/](https://developers.messagebird.com/)
65 |
66 |
67 | License
68 | ----
69 | The MessageBird REST Client for PHP is licensed under [The BSD 2-Clause License](http://opensource.org/licenses/BSD-2-Clause). Copyright (c) 2014, MessageBird
70 |
--------------------------------------------------------------------------------
/src/MessageBird/Resources/Voice/Base.php:
--------------------------------------------------------------------------------
1 | httpClient->performHttpRequest(
36 | Common\HttpClient::REQUEST_GET,
37 | $this->resourceName,
38 | $parameters
39 | );
40 |
41 | if ($status === 200) {
42 | $body = json_decode($body, null, 512, \JSON_THROW_ON_ERROR);
43 |
44 | $data = $body->data;
45 |
46 | $baseList = new BaseList();
47 | if (property_exists($body, 'pagination')) {
48 | $baseList->loadFromStdclass($body->pagination);
49 | }
50 |
51 | $objectName = $this->object;
52 |
53 | foreach ($data as $singleData) {
54 | /** @psalm-suppress UndefinedClass */
55 | $itemObject = new $objectName($this->httpClient);
56 |
57 | $message = $itemObject->loadFromStdclass($singleData);
58 | $baseList->items[] = $message;
59 | }
60 | return $baseList;
61 | }
62 |
63 | return $this->processRequest($body);
64 | }
65 |
66 | /**
67 | * @inheritdoc
68 | *
69 | * @return Balance|Conversation|Hlr|Lookup|Message|Verify|VoiceMessage|null
70 | */
71 | public function processRequest(?string $body)
72 | {
73 | if ($body === null) {
74 | throw new Exceptions\ServerException('Got an invalid JSON response from the server.');
75 | }
76 |
77 | try {
78 | $body = json_decode($body, null, 512, \JSON_THROW_ON_ERROR);
79 | } catch (\JsonException $e) {
80 | throw new Exceptions\ServerException('Got an invalid JSON response from the server.');
81 |
82 | }
83 |
84 | if (empty($body->errors)) {
85 | return $this->object->loadFromStdclass($body->data[0]);
86 | }
87 |
88 | $responseError = new Common\ResponseError($body);
89 | throw new Exceptions\RequestException($responseError->getErrorString());
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/src/MessageBird/Resources/LookupHlr.php:
--------------------------------------------------------------------------------
1 | object = new Objects\Hlr();
23 | $this->setResourceName('lookup');
24 |
25 | parent::__construct($httpClient);
26 | }
27 |
28 | /**
29 | * @param Objects\Hlr $object
30 | * @param array|null $query
31 | *
32 | * @return Objects\Balance|Objects\Conversation\Conversation|Objects\Hlr|Objects\Lookup|Objects\Message|Objects\Verify|Objects\VoiceMessage|null
33 | *
34 | * @throws HttpException
35 | * @throws RequestException
36 | * @throws ServerException
37 | * @throws \JsonException
38 | * @throws AuthenticateException
39 | */
40 | public function create($hlr, $countryCode = null)
41 | {
42 | if (empty($hlr->msisdn)) {
43 | throw new InvalidArgumentException('The phone number ($hlr->msisdn) cannot be empty.');
44 | }
45 |
46 | $query = null;
47 | if ($countryCode !== null) {
48 | $query = ["countryCode" => $countryCode];
49 | }
50 | $resourceName = $this->resourceName . '/' . ($hlr->msisdn) . '/hlr';
51 | [, , $body] = $this->httpClient->performHttpRequest(
52 | Common\HttpClient::REQUEST_POST,
53 | $resourceName,
54 | $query,
55 | json_encode($hlr, \JSON_THROW_ON_ERROR)
56 | );
57 | return $this->processRequest($body);
58 | }
59 |
60 | /**
61 | * @no-named-arguments
62 | *
63 | * @param mixed $phoneNumber
64 | * @param string|null $countryCode
65 | *
66 | * @return Objects\Balance|Objects\Conversation\Conversation|Objects\Hlr|Objects\Lookup|Objects\Message|Objects\Verify|Objects\VoiceMessage|null
67 | *
68 | * @throws HttpException
69 | * @throws RequestException
70 | * @throws ServerException
71 | * @throws AuthenticateException
72 | */
73 | public function read($phoneNumber = null, ?string $countryCode = null)
74 | {
75 | if (empty($phoneNumber)) {
76 | throw new InvalidArgumentException('The phone number cannot be empty.');
77 | }
78 |
79 | $query = null;
80 | if ($countryCode !== null) {
81 | $query = ["countryCode" => $countryCode];
82 | }
83 | $resourceName = $this->resourceName . '/' . $phoneNumber . '/hlr';
84 | [, , $body] = $this->httpClient->performHttpRequest(
85 | Common\HttpClient::REQUEST_GET,
86 | $resourceName,
87 | $query,
88 | null
89 | );
90 | return $this->processRequest($body);
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/Verify.php:
--------------------------------------------------------------------------------
1 | id;
81 | }
82 |
83 | /**
84 | * Get the created href
85 | */
86 | public function getHref(): string
87 | {
88 | return $this->href;
89 | }
90 |
91 | /**
92 | * Get the created href
93 | */
94 | public function getMessage(): string
95 | {
96 | return $this->messages->href;
97 | }
98 |
99 | /**
100 | * Get the status
101 | */
102 | public function getStatus(): string
103 | {
104 | return $this->status;
105 | }
106 |
107 | /**
108 | * Get the $createdDatetime value
109 | */
110 | public function getCreatedDatetime(): string
111 | {
112 | return $this->createdDatetime;
113 | }
114 |
115 | /**
116 | * Get the $validUntilDatetime value
117 | */
118 | public function getValidUntilDatetime(): string
119 | {
120 | return $this->validUntilDatetime;
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/src/MessageBird/Resources/Contacts.php:
--------------------------------------------------------------------------------
1 | object = new Objects\Contact();
26 | $this->setResourceName('contacts');
27 |
28 | $this->messagesObject = new Messages($httpClient);
29 |
30 | parent::__construct($httpClient);
31 | }
32 |
33 | /**
34 | * @param mixed $object
35 | * @param mixed $id
36 | *
37 | * @return Objects\Balance|Objects\Conversation\Conversation|Objects\Hlr|Objects\Lookup|Objects\Message|Objects\Verify|Objects\VoiceMessage|null ->object
38 | *
39 | * @throws \JsonException
40 | * @throws Exceptions\AuthenticateException
41 | * @throws Exceptions\HttpException
42 | * @throws Exceptions\RequestException
43 | * @throws Exceptions\ServerException
44 | *
45 | * @internal param array $parameters
46 | */
47 | public function update($object, $id)
48 | {
49 | $objVars = get_object_vars($object);
50 | $body = [];
51 | foreach ($objVars as $key => $value) {
52 | if ($value !== null) {
53 | $body[$key] = $value;
54 | }
55 | }
56 |
57 | $resourceName = $this->resourceName . ($id ? '/' . $id : null);
58 | $body = json_encode($body, \JSON_THROW_ON_ERROR);
59 |
60 | [, , $body] = $this->httpClient->performHttpRequest(
61 | Common\HttpClient::REQUEST_PATCH,
62 | $resourceName,
63 | false,
64 | $body
65 | );
66 | return $this->processRequest($body);
67 | }
68 |
69 | /**
70 | * @param mixed $id
71 | * @param array|null $parameters
72 | *
73 | * @return Objects\Balance|Objects\BaseList|Objects\Conversation\Conversation|Objects\Hlr|Objects\Lookup|Objects\Message|Objects\Verify|Objects\VoiceMessage|null ->object
74 | * @throws \JsonException
75 | */
76 | public function getMessages($id, ?array $parameters = [])
77 | {
78 | if ($id === null) {
79 | throw new InvalidArgumentException('No contact id provided.');
80 | }
81 |
82 | $this->messagesObject->setResourceName($this->resourceName . '/' . $id . '/messages');
83 | return $this->messagesObject->getList($parameters);
84 | }
85 |
86 | /**
87 | * @param mixed $id
88 | * @param array|null $parameters
89 | *
90 | * @return Objects\Balance|Objects\BaseList|Objects\Conversation\Conversation|Objects\Hlr|Objects\Lookup|Objects\Message|Objects\Verify|Objects\VoiceMessage|null ->object
91 | * @throws \JsonException
92 | */
93 | public function getGroups($id, ?array $parameters = [])
94 | {
95 | if ($id === null) {
96 | throw new InvalidArgumentException('No contact id provided.');
97 | }
98 |
99 | $this->object = new Objects\Group();
100 | $this->setResourceName($this->resourceName . '/' . $id . '/groups');
101 | return $this->getList($parameters);
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/src/MessageBird/Resources/PartnerAccount/Accounts.php:
--------------------------------------------------------------------------------
1 | object = new Account();
26 | $this->setResourceName(self::RESOURCE_NAME);
27 | }
28 |
29 | /**
30 | * @param $object
31 | * @param array|null $query
32 | * @return Balance|Conversation|Hlr|Lookup|Message|Verify|VoiceMessage|null
33 | * @throws Exceptions\AuthenticateException
34 | * @throws Exceptions\BalanceException
35 | * @throws Exceptions\HttpException
36 | * @throws Exceptions\RequestException
37 | * @throws Exceptions\ServerException
38 | */
39 | public function create($object, ?array $query = null)
40 | {
41 | [, , $body] = $this->httpClient->performHttpRequest(
42 | HttpClient::REQUEST_POST,
43 | self::RESOURCE_NAME,
44 | null,
45 | $object->loadToJson()
46 | );
47 |
48 | return $this->processRequest($body);
49 | }
50 |
51 | /**
52 | * @return array|Balance|\MessageBird\Objects\BaseList|Conversation|Hlr|Lookup|Message|\MessageBird\Objects\MessageResponse|Verify|VoiceMessage|null
53 | * @throws Exceptions\AuthenticateException
54 | * @throws Exceptions\BalanceException
55 | * @throws Exceptions\HttpException
56 | * @throws Exceptions\RequestException
57 | * @throws Exceptions\ServerException
58 | * @throws \JsonException
59 | */
60 | public function getList(?array $parameters = [])
61 | {
62 | [$status, , $body] = $this->httpClient->performHttpRequest(
63 | HttpClient::REQUEST_GET,
64 | self::RESOURCE_NAME,
65 | $parameters
66 | );
67 |
68 | if ($status !== 200) {
69 | return $this->processRequest($body);
70 | }
71 |
72 | $response = json_decode($body, false, 512, \JSON_THROW_ON_ERROR);
73 |
74 | $return = [];
75 | foreach ($response as &$singleResponse) {
76 | $object = clone $this->getObject();
77 | $return[] = $object->loadFromStdclass($singleResponse);
78 | }
79 |
80 | return $return;
81 | }
82 |
83 | /**
84 | * @param $object
85 | * @param $id
86 | * @return Balance|Conversation|Hlr|Lookup|Message|Verify|VoiceMessage|null
87 | * @throws Exceptions\AuthenticateException
88 | * @throws Exceptions\BalanceException
89 | * @throws Exceptions\HttpException
90 | * @throws Exceptions\RequestException
91 | * @throws Exceptions\ServerException
92 | */
93 | public function update($object, $id)
94 | {
95 | [, , $body] = $this->httpClient->performHttpRequest(
96 | HttpClient::REQUEST_PATCH,
97 | sprintf('%s/%s', self::RESOURCE_NAME, $id),
98 | null,
99 | $object->loadToJson()
100 | );
101 |
102 | return $this->processRequest($body);
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/src/MessageBird/Resources/Conversation/Conversations.php:
--------------------------------------------------------------------------------
1 | object = new Conversation();
25 | $this->setResourceName(self::RESOURCE_NAME);
26 | }
27 |
28 | /**
29 | * Starts a conversation by sending an initial message.
30 | *
31 | * @param Message $object
32 | * @param array|null $query
33 | *
34 | * @return Conversation|Balance|Hlr|Lookup|\MessageBird\Objects\Message|Verify|VoiceMessage|null
35 | *
36 | * @throws Exceptions\HttpException
37 | * @throws Exceptions\RequestException
38 | * @throws Exceptions\ServerException
39 | */
40 | public function start($object, $query = null)
41 | {
42 | $body = json_encode($object, \JSON_THROW_ON_ERROR);
43 |
44 | [, , $body] = $this->httpClient->performHttpRequest(
45 | HttpClient::REQUEST_POST,
46 | $this->getStartUrl(),
47 | $query,
48 | $body
49 | );
50 |
51 | return $this->processRequest($body);
52 | }
53 |
54 | /**
55 | * Conversations API uses a special URL scheme for starting a conversation.
56 | */
57 | private function getStartUrl(): string
58 | {
59 | return $this->resourceName . '/start';
60 | }
61 |
62 | /**
63 | * Starts a conversation without sending an initial message.
64 | *
65 | * @param int $object
66 | *
67 | * @return Conversation|Balance|Hlr|Lookup|\MessageBird\Objects\Message|Verify|VoiceMessage|null
68 | *
69 | * @throws Exceptions\HttpException
70 | * @throws Exceptions\RequestException
71 | * @throws Exceptions\ServerException
72 | */
73 | public function create($object, ?array $query = null)
74 | {
75 | $body = json_encode(['contactId' => $object], \JSON_THROW_ON_ERROR);
76 |
77 | [, , $body] = $this->httpClient->performHttpRequest(
78 | HttpClient::REQUEST_POST,
79 | $this->resourceName,
80 | $query,
81 | $body
82 | );
83 |
84 | return $this->processRequest($body);
85 | }
86 |
87 | /**
88 | * @param mixed $object
89 | * @param mixed $id
90 | *
91 | * @return Conversation|Balance|Hlr|Lookup|\MessageBird\Objects\Message|Verify|VoiceMessage|null ->object
92 | *
93 | * @internal param array $parameters
94 | */
95 | public function update($object, $id)
96 | {
97 | $objVars = get_object_vars($object);
98 | $body = [];
99 |
100 | foreach ($objVars as $key => $value) {
101 | if ($value !== null) {
102 | $body[$key] = $value;
103 | }
104 | }
105 |
106 | $resourceName = $this->resourceName . ($id ? '/' . $id : null);
107 | $body = json_encode($body, \JSON_THROW_ON_ERROR);
108 |
109 | [, , $body] = $this->httpClient->performHttpRequest(HttpClient::REQUEST_PATCH, $resourceName, false, $body);
110 |
111 | return $this->processRequest($body);
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/src/MessageBird/Resources/Voice/Legs.php:
--------------------------------------------------------------------------------
1 | httpClient = $httpClient;
30 | $this->object = new Objects\Voice\Leg();
31 | }
32 |
33 | public function getObject(): Objects\Voice\Leg
34 | {
35 | return $this->object;
36 | }
37 |
38 | /**
39 | * @deprecated
40 | *
41 | * @param mixed $object
42 | */
43 | public function setObject($object): void
44 | {
45 | $this->object = $object;
46 | }
47 |
48 | /**
49 | * @param string $callId
50 | * @param array $parameters
51 | *
52 | * @return Objects\BaseList|Objects\Voice\Leg
53 | * @throws Exceptions\AuthenticateException
54 | * @throws Exceptions\HttpException
55 | * @throws \JsonException
56 | */
57 | public function getList(string $callId, array $parameters = [])
58 | {
59 | [$status, , $body] = $this->httpClient->performHttpRequest(
60 | HttpClient::REQUEST_GET,
61 | "calls/$callId/legs",
62 | $parameters
63 | );
64 |
65 | if ($status === 200) {
66 | $body = json_decode($body, null, 512, \JSON_THROW_ON_ERROR);
67 |
68 | $items = $body->data;
69 | unset($body->data);
70 |
71 | $baseList = new Objects\BaseList();
72 | $baseList->loadFromStdclass($body);
73 |
74 | $objectName = $this->object;
75 |
76 | foreach ($items as $item) {
77 | /** @psalm-suppress UndefinedClass */
78 | $object = new $objectName($this->httpClient);
79 |
80 | $itemObject = $object->loadFromStdclass($item);
81 | $baseList->items[] = $itemObject;
82 | }
83 | return $baseList;
84 | }
85 |
86 | return $this->processRequest($body);
87 | }
88 |
89 | /**
90 | * @throws Exceptions\AuthenticateException
91 | * @throws Exceptions\BalanceException
92 | * @throws Exceptions\RequestException
93 | * @throws Exceptions\ServerException
94 | */
95 | public function processRequest(?string $body): Objects\Voice\Leg
96 | {
97 | if ($body === null) {
98 | throw new Exceptions\ServerException('Got an invalid JSON response from the server.');
99 | }
100 |
101 | try {
102 | $body = json_decode($body, null, 512, \JSON_THROW_ON_ERROR);
103 | } catch (\JsonException $e) {
104 | throw new Exceptions\ServerException('Got an invalid JSON response from the server.');
105 | }
106 |
107 | if (empty($body->errors)) {
108 | return $this->object->loadFromStdclass($body->data[0]);
109 | }
110 |
111 | $responseError = new Common\ResponseError($body);
112 | throw new Exceptions\RequestException($responseError->getErrorString());
113 | }
114 |
115 | public function read(string $callId, string $legId): Objects\Voice\Leg
116 | {
117 | [, , $body] = $this->httpClient->performHttpRequest(
118 | HttpClient::REQUEST_GET,
119 | "calls/$callId/legs/$legId"
120 | );
121 |
122 | return $this->processRequest($body);
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/Conversation/Content.php:
--------------------------------------------------------------------------------
1 | loadLocationIfNeeded();
71 | $this->loadMediaIfNeeded();
72 |
73 | return $this;
74 | }
75 |
76 | public function loadFromStdclass(stdClass $object): self
77 | {
78 | // Text is already properly set if available due to the response's structure.
79 | parent::loadFromStdclass($object);
80 |
81 | $this->loadLocationIfNeeded();
82 | $this->loadMediaIfNeeded();
83 |
84 | return $this;
85 | }
86 |
87 | /**
88 | * Sets the location on this object if available.
89 | */
90 | private function loadLocationIfNeeded(): void
91 | {
92 | if (empty($this->location->latitude)) {
93 | return;
94 | }
95 | if (empty($this->location->longitude)) {
96 | return;
97 | }
98 | $this->location = [
99 | 'latitude' => $this->location->latitude,
100 | 'longitude' => $this->location->longitude,
101 | ];
102 | }
103 |
104 | /**
105 | * Sets the media on this object if available.
106 | */
107 | private function loadMediaIfNeeded(): void
108 | {
109 | if (!empty($this->audio->url)) {
110 | $this->audio = ['url' => $this->audio->url];
111 | }
112 |
113 | if (!empty($this->file->url)) {
114 | $this->file = ['url' => $this->file->url];
115 | }
116 |
117 | if (!empty($this->image->url)) {
118 | $this->image = ['url' => $this->image->url];
119 | }
120 |
121 | if (!empty($this->video->url)) {
122 | $this->video = ['url' => $this->video->url];
123 | }
124 | }
125 |
126 | /**
127 | * Serialize only non empty fields.
128 | */
129 | public function jsonSerialize(): array
130 | {
131 | $json = [];
132 |
133 | foreach (get_object_vars($this) as $key => $value) {
134 | if (!empty($value)) {
135 | $json[$key] = $value;
136 | }
137 | }
138 |
139 | return $json;
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/MmsMessage.php:
--------------------------------------------------------------------------------
1 | id;
92 | }
93 |
94 | /**
95 | * Get the created href
96 | */
97 | public function getHref(): string
98 | {
99 | return $this->href;
100 | }
101 |
102 | /**
103 | * Get the $createdDatetime value
104 | */
105 | public function getCreatedDatetime(): string
106 | {
107 | return $this->createdDatetime;
108 | }
109 |
110 | /**
111 | * @deprecated 2.2.0 No longer used by internal code, please switch to {@see self::loadFromStdclass()}
112 | *
113 | * @param mixed $object
114 | *
115 | * @return $this|void
116 | */
117 | public function loadFromArray($object): self
118 | {
119 | parent::loadFromArray($object);
120 |
121 | if (!empty($this->recipients->items)) {
122 | foreach ($this->recipients->items as &$item) {
123 | $recipient = new Recipient();
124 | $recipient->loadFromArray($item);
125 |
126 | $item = $recipient;
127 | }
128 | }
129 |
130 | return $this;
131 | }
132 |
133 | public function loadFromStdclass(stdClass $object): self
134 | {
135 | parent::loadFromStdclass($object);
136 |
137 | if (!empty($this->recipients->items)) {
138 | foreach ($this->recipients->items as &$item) {
139 | $recipient = new Recipient();
140 | $recipient->loadFromStdclass($item);
141 |
142 | $item = $recipient;
143 | }
144 | }
145 |
146 | return $this;
147 | }
148 | }
149 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/MessageResponse.php:
--------------------------------------------------------------------------------
1 | recipients = (new Recipients())->loadFromArray($this->recipients);
139 | $this->typeDetails = get_object_vars($this->typeDetails);
140 |
141 | return $this;
142 | }
143 |
144 | public function loadFromStdclass(stdClass $object): self
145 | {
146 | parent::loadFromStdclass($object);
147 |
148 | $this->recipients = (new Recipients())->loadFromStdclass($this->recipients);
149 | $this->typeDetails = get_object_vars($this->typeDetails);
150 |
151 | return $this;
152 | }
153 | }
154 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/Conversation/Message.php:
--------------------------------------------------------------------------------
1 | loadFromArray($this->content);
109 |
110 | $this->content = $content;
111 |
112 | return $this;
113 | }
114 |
115 | public function loadFromStdclass(stdClass $object): self
116 | {
117 | parent::loadFromStdclass($object);
118 |
119 | if (property_exists($object, 'content')) {
120 | $content = new Content();
121 | $content->loadFromStdclass($object->content);
122 | $this->content = $content;
123 | }
124 |
125 | return $this;
126 | }
127 |
128 | /**
129 | * Serialize only non empty fields.
130 | */
131 | public function jsonSerialize(): array
132 | {
133 | $json = [];
134 |
135 | foreach (get_object_vars($this) as $key => $value) {
136 | if (!empty($value)) {
137 | $json[$key] = $value;
138 | }
139 | }
140 |
141 | return $json;
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/SignedRequest.php:
--------------------------------------------------------------------------------
1 | loadFromArray(compact('body', 'queryParameters', 'requestTimestamp', 'signature'));
62 |
63 | return $signedRequest;
64 | }
65 |
66 | /**
67 | * Create a SignedRequest from the provided data.
68 | *
69 | * @param string|array $query The query string from the request
70 | * @param string $signature The base64-encoded signature for the request
71 | * @param int $requestTimestamp The UNIX timestamp for the time the request was made
72 | * @param string $body The request body
73 | * @return SignedRequest
74 | * @throws ValidationException when a required parameter is missing.
75 | * @deprecated Use {@link RequestValidator::validateSignature()} instead.
76 | */
77 | public static function create($query, string $signature, int $requestTimestamp, string $body): SignedRequest
78 | {
79 | if (is_string($query)) {
80 | $queryParameters = [];
81 | parse_str($query, $queryParameters);
82 | } else {
83 | $queryParameters = $query;
84 | }
85 |
86 | $signedRequest = new self();
87 | $signedRequest->loadFromArray(compact('body', 'queryParameters', 'requestTimestamp', 'signature'));
88 |
89 | return $signedRequest;
90 | }
91 |
92 | /**
93 | * {@inheritdoc}
94 | * @throws ValidationException when a required parameter is missing.
95 | */
96 | public function loadFromArray($object): self
97 | {
98 | if (!isset($object['requestTimestamp']) || !\is_int($object['requestTimestamp'])) {
99 | throw new ValidationException('The "requestTimestamp" value is missing or invalid.');
100 | }
101 |
102 | if (!isset($object['signature']) || !\is_string($object['signature'])) {
103 | throw new ValidationException('The "signature" parameter is missing.');
104 | }
105 |
106 | if (!isset($object['queryParameters']) || !\is_array($object['queryParameters'])) {
107 | throw new ValidationException('The "queryParameters" parameter is missing or invalid.');
108 | }
109 |
110 | if (!isset($object['body']) || !\is_string($object['body'])) {
111 | throw new ValidationException('The "body" parameter is missing.');
112 | }
113 |
114 | return parent::loadFromArray($object);
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/Lookup.php:
--------------------------------------------------------------------------------
1 | href;
89 | }
90 |
91 | public function getCountryCode(): ?string
92 | {
93 | return $this->countryCode;
94 | }
95 |
96 | public function getCountryPrefix(): ?int
97 | {
98 | return $this->countryPrefix;
99 | }
100 |
101 | public function getPhoneNumber(): ?int
102 | {
103 | return $this->phoneNumber;
104 | }
105 |
106 | public function getType(): ?string
107 | {
108 | return $this->type;
109 | }
110 |
111 | public function getFormats(): ?stdClass
112 | {
113 | return $this->formats;
114 | }
115 |
116 | public function getHLR(): ?stdClass
117 | {
118 | return $this->hlr;
119 | }
120 |
121 | /**
122 | * @deprecated 2.2.0 No longer used by internal code, please switch to {@see self::loadFromStdclass()}
123 | *
124 | * @param mixed $object
125 | *
126 | * @return $this
127 | */
128 | public function loadFromArray($object): self
129 | {
130 | unset($this->hlr);
131 | return parent::loadFromArray($object);
132 | }
133 |
134 | public function loadFromStdclass(stdClass $object): self
135 | {
136 | unset($this->hlr);
137 | return parent::loadFromStdclass($object);
138 | }
139 | }
140 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/VoiceMessage.php:
--------------------------------------------------------------------------------
1 | id;
114 | }
115 |
116 | /**
117 | * Get the created href
118 | */
119 | public function getHref(): string
120 | {
121 | return $this->href;
122 | }
123 |
124 | /**
125 | * Get the date and time the resource was created
126 | */
127 | public function getCreatedDatetime(): string
128 | {
129 | return $this->createdDatetime;
130 | }
131 |
132 | /**
133 | * @deprecated 2.2.0 No longer used by internal code, please switch to {@see self::loadFromStdclass()}
134 | *
135 | * @param mixed $object
136 | *
137 | * @return $this|void
138 | */
139 | public function loadFromArray($object): self
140 | {
141 | parent::loadFromArray($object);
142 |
143 | if (!empty($this->recipients->items)) {
144 | foreach ($this->recipients->items as &$item) {
145 | $recipient = new Recipient();
146 | $recipient->loadFromArray($item);
147 |
148 | $item = $recipient;
149 | }
150 | }
151 |
152 | return $this;
153 | }
154 | }
155 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/Contact.php:
--------------------------------------------------------------------------------
1 | id;
98 | }
99 |
100 | public function getHref(): string
101 | {
102 | return $this->href;
103 | }
104 |
105 | public function getGroups(): stdClass
106 | {
107 | return $this->groups;
108 | }
109 |
110 | public function getMessages(): stdClass
111 | {
112 | return $this->messages;
113 | }
114 |
115 | public function getCreatedDatetime(): string
116 | {
117 | return $this->createdDatetime;
118 | }
119 |
120 | public function getUpdatedDatetime(): ?string
121 | {
122 | return $this->updatedDatetime;
123 | }
124 |
125 | public function getCustomDetails(): stdClass
126 | {
127 | return $this->customDetails;
128 | }
129 |
130 | /**
131 | * @deprecated 2.2.0 No longer used by internal code, please switch to {@see self::loadFromStdclass()}
132 | *
133 | * @param mixed $object
134 | */
135 | public function loadFromArray($object): self
136 | {
137 | unset($this->custom1, $this->custom2, $this->custom3, $this->custom4);
138 |
139 | return parent::loadFromArray($object);
140 | }
141 |
142 | public function loadFromStdclass(stdClass $object): self
143 | {
144 | unset($this->custom1, $this->custom2, $this->custom3, $this->custom4);
145 |
146 | return parent::loadFromStdclass($object);
147 | }
148 |
149 | /**
150 | * @deprecated 2.2.0 No longer used by internal code, please switch to {@see self::loadFromStdclassForGroups()}
151 | *
152 | * @param mixed $object
153 | *
154 | * @return $this ->object
155 | */
156 | public function loadFromArrayForGroups($object)
157 | {
158 | parent::loadFromArray($object);
159 |
160 | if (!empty($object->items)) {
161 | foreach ($object->items as &$item) {
162 | $group = new Group();
163 | $group->loadFromArray($item);
164 |
165 | $item = $group;
166 | }
167 | }
168 | return $object;
169 | }
170 |
171 | public function loadFromStdclassForGroups(stdClass $object)
172 | {
173 | parent::loadFromStdclass($object);
174 |
175 | if (!empty($object->items)) {
176 | foreach ($object->items as &$item) {
177 | $group = new Group();
178 | $group->loadFromStdclass($item);
179 |
180 | $item = $group;
181 | }
182 | }
183 | return $object;
184 | }
185 | }
186 |
--------------------------------------------------------------------------------
/src/MessageBird/Resources/Groups.php:
--------------------------------------------------------------------------------
1 | object = new Objects\Group();
25 | $this->setResourceName('groups');
26 |
27 | $this->contactsObject = new Contacts($httpClient);
28 |
29 | parent::__construct($httpClient);
30 | }
31 |
32 | /**
33 | * @param mixed $object
34 | * @param mixed $id
35 | *
36 | * @return Objects\Balance|Objects\Conversation\Conversation|Objects\Hlr|Objects\Lookup|Objects\Message|Objects\Verify|Objects\VoiceMessage|null ->object
37 | *
38 | * @throws Exceptions\AuthenticateException
39 | * @throws Exceptions\HttpException
40 | * @throws Exceptions\RequestException
41 | * @throws Exceptions\ServerException
42 | * @throws \JsonException
43 | *
44 | * @internal param array $parameters
45 | */
46 | public function update($object, $id)
47 | {
48 | $objVars = get_object_vars($object);
49 | $body = [];
50 | foreach ($objVars as $key => $value) {
51 | if ($value !== null) {
52 | $body[$key] = $value;
53 | }
54 | }
55 |
56 | $resourceName = $this->resourceName . ($id ? '/' . $id : null);
57 | $body = json_encode($body, \JSON_THROW_ON_ERROR);
58 |
59 | [, , $body] = $this->httpClient->performHttpRequest(
60 | Common\HttpClient::REQUEST_PATCH,
61 | $resourceName,
62 | false,
63 | $body
64 | );
65 | return $this->processRequest($body);
66 | }
67 |
68 | /**
69 | * @param string|null $id
70 | * @param array|null $parameters
71 | *
72 | * @return mixed
73 | *
74 | * @throws InvalidArgumentException
75 | * @throws \JsonException
76 | *
77 | */
78 | public function getContacts(?string $id = null, ?array $parameters = [])
79 | {
80 | if ($id === null) {
81 | throw new InvalidArgumentException('No group id provided.');
82 | }
83 |
84 | $this->contactsObject->setResourceName($this->resourceName . '/' . $id . '/contacts');
85 | return $this->contactsObject->getList($parameters);
86 | }
87 |
88 | /**
89 | * @param array $contacts
90 | * @param string|null $id
91 | *
92 | * @return mixed
93 | * @throws Exceptions\HttpException
94 | * @throws InvalidArgumentException
95 | *
96 | * @throws Exceptions\AuthenticateException
97 | * @throws \JsonException
98 | */
99 | public function addContacts(array $contacts, ?string $id = null)
100 | {
101 | if (!\is_array($contacts)) {
102 | throw new InvalidArgumentException('No array with contacts provided.');
103 | }
104 | if ($id === null) {
105 | throw new InvalidArgumentException('No group id provided.');
106 | }
107 |
108 | $resourceName = $this->resourceName . ($id ? '/' . $id . '/contacts' : null);
109 | $contacts = json_encode($contacts, \JSON_THROW_ON_ERROR);
110 | [$responseStatus, , $responseBody] = $this->httpClient->performHttpRequest(
111 | Common\HttpClient::REQUEST_PUT,
112 | $resourceName,
113 | false,
114 | $contacts
115 | );
116 | if ($responseStatus !== Common\HttpClient::HTTP_NO_CONTENT) {
117 | return json_decode($responseBody, null, 512, \JSON_THROW_ON_ERROR);
118 | }
119 | }
120 |
121 | /**
122 | * @param string|null $contact_id
123 | * @param string|null $id
124 | *
125 | * @return mixed
126 | * @throws Exceptions\HttpException
127 | *
128 | * @throws Exceptions\AuthenticateException
129 | * @throws \JsonException
130 | */
131 | public function removeContact(?string $contact_id = null, ?string $id = null)
132 | {
133 | if ($contact_id === null || $id === null) {
134 | throw new InvalidArgumentException('Null Contact or Group id.');
135 | }
136 | $resourceName = $this->resourceName . ($id ? '/' . $id . '/contacts/' . $contact_id : null);
137 |
138 | [$responseStatus, , $responseBody] = $this->httpClient->performHttpRequest(
139 | Common\HttpClient::REQUEST_DELETE,
140 | $resourceName
141 | );
142 | if ($responseStatus !== Common\HttpClient::HTTP_NO_CONTENT) {
143 | return json_decode($responseBody, null, 512, \JSON_THROW_ON_ERROR);
144 | }
145 | }
146 | }
147 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/Conversation/Conversation.php:
--------------------------------------------------------------------------------
1 | contact)) {
109 | $newContact = new Contact();
110 | $newContact->loadFromArray($this->contact);
111 |
112 | $this->contact = $newContact;
113 | }
114 |
115 | if (!empty($this->channels)) {
116 | $channels = [];
117 |
118 | foreach ($this->channels as $channel) {
119 | $newChannel = new Channel();
120 | $newChannel->loadFromArray($channel);
121 |
122 | $channels[] = $newChannel;
123 | }
124 |
125 | $this->channels = $channels;
126 | }
127 |
128 | if (!empty($this->messages)) {
129 | $messages = new MessageReference();
130 | $messages->loadFromArray($this->messages);
131 |
132 | $this->messages = $messages;
133 | }
134 |
135 | return $this;
136 | }
137 |
138 | public function loadFromStdclass(stdClass $object): self
139 | {
140 | parent::loadFromStdclass($object);
141 |
142 | if (!empty($object->contact)) {
143 | $newContact = new Contact();
144 | $newContact->loadFromStdclass($object->contact);
145 |
146 | $this->contact = $newContact;
147 | }
148 |
149 | if (!empty($object->channels)) {
150 | $channels = [];
151 |
152 | foreach ($object->channels as $channel) {
153 | $newChannel = new Channel();
154 | $newChannel->loadFromStdclass($channel);
155 |
156 | $channels[] = $newChannel;
157 | }
158 |
159 | $this->channels = $channels;
160 | }
161 |
162 | if (!empty($object->messages)) {
163 | $messages = new MessageReference();
164 | $messages->loadFromStdclass($object->messages);
165 |
166 | $this->messages = $messages;
167 | }
168 |
169 | return $this;
170 | }
171 | }
172 |
--------------------------------------------------------------------------------
/src/MessageBird/Objects/Message.php:
--------------------------------------------------------------------------------
1 | typeDetails['udh'] = $header;
131 | $this->body = $body;
132 | $this->type = self::TYPE_BINARY;
133 | }
134 |
135 | /**
136 | * @param mixed $bool
137 | */
138 | public function setFlash($bool): void
139 | {
140 | if ($bool === true) {
141 | $this->mclass = 0;
142 | } else {
143 | $this->mclass = 1;
144 | }
145 | }
146 |
147 | /**
148 | * Get the $createdDatetime value
149 | * */
150 | public function getCreatedDatetime(): string
151 | {
152 | return $this->createdDatetime;
153 | }
154 |
155 | /**
156 | * @deprecated 2.2.0 No longer used by internal code, please switch to {@see self::loadFromStdclass()}
157 | *
158 | * @param mixed $object
159 | *
160 | * @return self
161 | */
162 | public function loadFromArray($object): self
163 | {
164 | parent::loadFromArray($object);
165 |
166 | if (!empty($this->recipients->items)) {
167 | foreach ($this->recipients->items as &$item) {
168 | $recipient = new Recipient();
169 | $recipient->loadFromArray($item);
170 |
171 | $item = $recipient;
172 | }
173 | }
174 |
175 | return $this;
176 | }
177 |
178 | /**
179 | * @param stdClass $object
180 | * @return self
181 | */
182 | public function loadFromStdclass(stdClass $object): self
183 | {
184 | parent::loadFromStdclass($object);
185 |
186 | if (!empty($this->recipients->items)) {
187 | foreach ($this->recipients->items as &$item) {
188 | $recipient = new Recipient();
189 | $recipient->loadFromStdclass($item);
190 |
191 | $item = $recipient;
192 | }
193 | }
194 |
195 | return $this;
196 | }
197 | }
198 |
--------------------------------------------------------------------------------
/src/MessageBird/Resources/Voice/Recordings.php:
--------------------------------------------------------------------------------
1 | httpClient = $httpClient;
30 | $this->object = new Objects\Voice\Recording();
31 | }
32 |
33 | public function getObject(): Objects\Voice\Recording
34 | {
35 | return $this->object;
36 | }
37 |
38 | /**
39 | * @deprecated
40 | *
41 | * @param mixed $object
42 | */
43 | public function setObject($object): void
44 | {
45 | $this->object = $object;
46 | }
47 |
48 | /**
49 | * @return Objects\BaseList|Objects\Voice\Recording
50 | * @throws Exceptions\AuthenticateException
51 | * @throws Exceptions\HttpException
52 | * @throws \JsonException
53 | */
54 | public function getList(string $callId, string $legId, array $parameters = [])
55 | {
56 | [$status, , $body] = $this->httpClient->performHttpRequest(
57 | HttpClient::REQUEST_GET,
58 | "calls/$callId/legs/$legId/recordings",
59 | $parameters
60 | );
61 |
62 | if ($status === 200) {
63 | $body = json_decode($body, null, 512, \JSON_THROW_ON_ERROR);
64 |
65 | $items = $body->data;
66 | unset($body->data);
67 |
68 | $baseList = new Objects\BaseList();
69 | $baseList->loadFromStdclass($body);
70 |
71 | $objectName = $this->object;
72 |
73 | foreach ($items as $item) {
74 | /** @psalm-suppress UndefinedClass */
75 | $object = new $objectName($this->httpClient);
76 |
77 | $itemObject = $object->loadFromStdclass($item);
78 | $baseList->items[] = $itemObject;
79 | }
80 | return $baseList;
81 | }
82 |
83 | return $this->processRequest($body);
84 | }
85 |
86 | /**
87 | * @throws Exceptions\AuthenticateException
88 | * @throws Exceptions\BalanceException
89 | * @throws Exceptions\RequestException
90 | * @throws Exceptions\ServerException
91 | */
92 | public function processRequest(?string $body): Objects\Voice\Recording
93 | {
94 | try {
95 | $body = @json_decode($body, null, 512, \JSON_THROW_ON_ERROR);
96 | } catch (\JsonException $e) {
97 | throw new Exceptions\ServerException('Got an invalid JSON response from the server.');
98 | }
99 |
100 | if ($body === null) {
101 | throw new Exceptions\ServerException('Got an invalid JSON response from the server.');
102 | }
103 |
104 | if (empty($body->errors)) {
105 | return $this->object->loadFromStdclass($body->data[0]);
106 | }
107 |
108 | $responseError = new Common\ResponseError($body);
109 | throw new Exceptions\RequestException($responseError->getErrorString());
110 | }
111 |
112 | /**
113 | * @throws Exceptions\AuthenticateException
114 | * @throws Exceptions\BalanceException
115 | * @throws Exceptions\HttpException
116 | * @throws Exceptions\RequestException
117 | * @throws Exceptions\ServerException
118 | */
119 | public function read(string $callId, string $legId, string $recordingId): Objects\Voice\Recording
120 | {
121 | [, , $body] = $this->httpClient->performHttpRequest(
122 | HttpClient::REQUEST_GET,
123 | "calls/$callId/legs/$legId/recordings/$recordingId"
124 | );
125 |
126 | return $this->processRequest($body);
127 | }
128 |
129 | /**
130 | * @throws Exceptions\AuthenticateException
131 | * @throws Exceptions\BalanceException
132 | * @throws Exceptions\HttpException
133 | * @throws Exceptions\RequestException
134 | * @throws Exceptions\ServerException
135 | */
136 | public function delete(string $callId, string $legId, string $recordingId): Objects\Voice\Recording
137 | {
138 | [, , $body] = $this->httpClient->performHttpRequest(
139 | HttpClient::REQUEST_DELETE,
140 | "calls/$callId/legs/$legId/recordings/$recordingId"
141 | );
142 | return $this->processRequest($body);
143 | }
144 |
145 | /**
146 | * @return mixed
147 | * @throws Exceptions\AuthenticateException
148 | * @throws Exceptions\BalanceException
149 | * @throws Exceptions\HttpException
150 | * @throws Exceptions\RequestException
151 | * @throws Exceptions\ServerException
152 | */
153 | public function download(string $callId, string $legId, string $recordingId)
154 | {
155 | [$status, , $body] = $this->httpClient->performHttpRequest(
156 | HttpClient::REQUEST_GET,
157 | "calls/$callId/legs/$legId/recordings/$recordingId.wav"
158 | );
159 |
160 | if ($status !== 200) {
161 | return $this->processRequest($body);
162 | }
163 |
164 | return $body;
165 | }
166 | }
167 |
--------------------------------------------------------------------------------