TODO: Add a description
The generated code has dependencies over external libraries like UniRest. These dependencies are defined in the composer.json file that comes with the SDK.
To resolve these dependencies, we use the Composer package manager which requires PHP greater than 5.3.2 installed in your system.
Visit https://getcomposer.org/download/ to download the installer file for Composer and run it in your system.
Open command prompt and type composer --version. This should display the current version of the Composer installed if the installation was successful.
- Using command line, navigate to the directory containing the generated files (including
composer.json) for the SDK. - Run the command
composer install. This should install all the required dependencies and create thevendordirectory in your project directory.
CURL used to include a list of accepted CAs, but no longer bundles ANY CA certs. So by default it will reject all SSL certificates as unverifiable. You will have to get your CA's cert and point curl at it. The steps are as follows:
- Download the certificate bundle (.pem file) from https://curl.haxx.se/docs/caextract.html on to your system.
- Add curl.cainfo = "PATH_TO/cacert.pem" to your php.ini file located in your php installation. “PATH_TO” must be an absolute path containing the .pem file.
[curl]
; A default value for the CURLOPT_CAINFO option. This is required to be an
; absolute path.
;curl.cainfo =The following section explains how to use the MessageMediaWebhooks library in a new project.
Open an IDE for PHP like PhpStorm. The basic workflow presented here is also applicable if you prefer using a different editor or IDE.
Click on Open in PhpStorm to browse to your generated SDK directory and then click OK.
Create a new directory by right clicking on the solution name as shown below:
Name the directory as "test"
Add a PHP file to this project
Name it "testSDK"
Depending on your project setup, you might need to include composer's autoloader in your PHP code to enable auto loading of classes.
require_once "../vendor/autoload.php";It is important that the path inside require_once correctly points to the file autoload.php inside the vendor directory created during dependency installations.
After this you can add code to initialize the client library and acquire the instance of a Controller class. Sample code to initialize the client library and using controller methods is given in the subsequent sections.
To run your project you must set the Interpreter for your project. Interpreter is the PHP engine installed on your computer.
Open Settings from File menu.
Select PHP from within Languages & Frameworks
Browse for Interpreters near the Interpreter option and choose your interpreter.
Once the interpreter is selected, click OK
To run your project, right click on your PHP file inside your Test project and click on Run
Unit tests in this SDK can be run using PHPUnit.
- First install the dependencies using composer including the
require-devdependencies. - Run
vendor\bin\phpunit --verbosefrom commandline to execute tests. If you have installed PHPUnit globally, run tests usingphpunit --verboseinstead.
You can change the PHPUnit test configuration in the phpunit.xml file.
In order to setup authentication and initialization of the API client, you need the following information.
| Parameter | Description |
|---|---|
| basicAuthUserName | The username to use with basic authentication |
| basicAuthPassword | The password to use with basic authentication |
API client can be initialized as following.
$basicAuthUserName = 'basicAuthUserName'; // The username to use with basic authentication
$basicAuthPassword = 'basicAuthPassword'; // The password to use with basic authentication
$client = new MessageMediaWebhooksLib\MessageMediaWebhooksClient($basicAuthUserName, $basicAuthPassword);The singleton instance of the WebhooksController class can be accessed from the API Client.
$webhooks = $client->getWebhooks();Create a webhook for one or more of the specified events. A webhook would typically have the following structure:
{ "url": "http://webhook.com", "method": "POST", "encoding": "JSON", "headers": { "Account": "DeveloperPortal7000" }, "events": [ "RECEIVED_SMS" ], "template": "{\"id\":\"$mtId\",\"status\":\"$statusCode\"}" }A valid webhook must consist of the following properties:
urlThe configured URL which will trigger the webhook when a selected event occurs.methodThe methods to map CRUD (create, retrieve, update, delete) operations to HTTP requests.encodingThe format in which the payload will be returned. You can choose fromJSON,FORM_ENCODEDorXML. This will automatically add the Content-Type header for you so you don't have to add it again in theheadersproperty.headersHTTP header fields which provide required information about the request or response, or about the object sent in the message body. This should not include theContent-Typeheader.eventsEvent or events that will trigger the webhook. Atleast one event should be present.templateThe structure of the payload that will be returned.You can select all of the events (listed below) or combine them in whatever way you like but atleast one event must be used. Otherwise, the webhook won't be created. A webhook will be triggered when any one or more of the events occur:
- SMS
RECEIVED_SMSReceive an SMSOPT_OUT_SMSOpt-out occured- MMS
RECEIVED_MMSReceive an MMS- DR (Delivery Reports)
ENROUTE_DRMessage is enrouteEXPIRED_DRMessage has expiredREJECTED_DRMessage is rejectedFAILED_DRMessage has failedDELIVERED_DRMessage is deliveredSUBMITTED_DRMessage is submittedYou can choose what to include in the data that will be sent as the payload via the Webhook. Keep in my mind, you must escape the JSON in the template value (see example above). The table illustrates a list of all the parameters that can be included in the template and which event types it can be applied to. | Data | Parameter Name | Example | Event Type | |:--|--|--|--|--| | Service Type | $type|
SMS|DRMOMO MMS| | Message ID | $mtId, $messageId|877c19ef-fa2e-4cec-827a-e1df9b5509f7|DRMOMO MMS| | Delivery Report ID |$drId, $reportId|01e1fa0a-6e27-4945-9cdb-18644b4de043|DR| | Reply ID| $moId, $replyId|a175e797-2b54-468b-9850-41a3eab32f74|MOMO MMS| | Account ID | $accountId|DeveloperPortal7000|DRMOMO MMS| | Message Timestamp | $submittedTimestamp|2016-12-07T08:43:00.850Z|DRMOMO MMS| | Provider Timestamp | $receivedTimestamp|2016-12-07T08:44:00.850Z|DRMOMO MMS| | Message Status | $status|enroute|DR| | Status Code | $statusCode|200|DR| | External Metadata | $metadata.get('key')|name|DRMOMO MMS| | Source Address| $sourceAddress|+61491570156|DRMOMO MMS| | Destination Address| $destinationAddress|+61491593156|MOMO MMS| | Message Content| $mtContent, $messageContent|Hi Derp|DRMOMO MMS| | Reply Content| $moContent, $replyContent|Hello Derpina|MOMO MMS| | Retry Count| $retryCount|1|DRMOMO MMS| Note: A 400 response will be returned if theurlis invalid, theevents,encodingormethodis null or theheadershas a Content-Type attribute.
function createWebhook($body)| Parameter | Tags | Description |
|---|---|---|
| body | Required |
TODO: Add a parameter description |
$body = new CreateWebhookRequest();
$result = $webhooks->createWebhook($body);| Error Code | Error Description |
|---|---|
| 400 | Unexpected error in API call. See HTTP response body for details. |
| 409 | Unexpected error in API call. See HTTP response body for details. |
Retrieve all the webhooks created for the connected account. A successful request to the retrieve webhook endpoint will return a response body as follows:
{ "page": 0, "pageSize": 100, "pageData": [ { "url": "https://webhook.com", "method": "POST", "id": "8805c9d8-bef7-41c7-906a-69ede93aa024", "encoding": "JSON", "events": [ "RECEIVED_SMS" ], "headers": {}, "template": "{\"id\":\"$mtId\", \"status\":\"$statusCode\"}" } ] }Note: Response 400 is returned when the
pagequery parameter is not valid or thepageSizequery parameter is not valid.
function retrieveWebhook(
$page = null,
$pageSize = null)| Parameter | Tags | Description |
|---|---|---|
| page | Optional |
TODO: Add a parameter description |
| pageSize | Optional |
TODO: Add a parameter description |
$page = 79;
$pageSize = 79;
$result = $webhooks->retrieveWebhook($page, $pageSize);| Error Code | Error Description |
|---|---|
| 400 | Unexpected error in API call. See HTTP response body for details. |
Delete a webhook that was previously created for the connected account. A webhook can be cancelled by appending the UUID of the webhook to the endpoint and submitting a DELETE request to the /webhooks/messages endpoint. Note: Only pre-created webhooks can be deleted. If an invalid or non existent webhook ID parameter is specified in the request, then a HTTP 404 Not Found response will be returned.
function deleteWebhook($webhookId)| Parameter | Tags | Description |
|---|---|---|
| webhookId | Required |
TODO: Add a parameter description |
$webhookId = a7f11bb0-f299-4861-a5ca-9b29d04bc5ad;
$webhooks->deleteWebhook($webhookId);| Error Code | Error Description |
|---|---|
| 404 | TODO: Add an error description |
Update a webhook. You can update individual attributes or all of them by submitting a PATCH request to the /webhooks/messages endpoint (the same endpoint used above to delete a webhook) A successful request to the retrieve webhook endpoint will return a response body as follows:
{ "url": "https://webhook.com", "method": "POST", "id": "04442623-0961-464e-9cbc-ec50804e0413", "encoding": "JSON", "events": [ "RECEIVED_SMS" ], "headers": {}, "template": "{\"id\":\"$mtId\", \"status\":\"$statusCode\"}" }Note: Only pre-created webhooks can be deleted. If an invalid or non existent webhook ID parameter is specified in the request, then a HTTP 404 Not Found response will be returned.
function updateWebhook(
$webhookId,
$body)| Parameter | Tags | Description |
|---|---|---|
| webhookId | Required |
TODO: Add a parameter description |
| body | Required |
TODO: Add a parameter description |
$webhookId = a7f11bb0-f299-4861-a5ca-9b29d04bc5ad;
$bodyValue = " { \"url\": \"https://myurl.com\", \"method\": \"POST\", \"encoding\": \"FORM_ENCODED\", \"events\": [ \"ENROUTE_DR\" ], \"template\": \"{\\\"id\\\":\\\"$mtId\\\", \\\"status\\\":\\\"$statusCode\\\"}\" }";
$body = APIHelper::deserialize($bodyValue);
$result = $webhooks->updateWebhook($webhookId, $body);| Error Code | Error Description |
|---|---|
| 400 | Unexpected error in API call. See HTTP response body for details. |
| 404 | TODO: Add an error description |

