|
| 1 | +# Getting started |
| 2 | + |
| 3 | +TODO: Add a description |
| 4 | + |
| 5 | +## How to Build |
| 6 | + |
| 7 | + |
| 8 | +You must have Python ```2 >=2.7.9``` or Python ```3 >=3.4``` installed on your system to install and run this SDK. This SDK package depends on other Python packages like nose, jsonpickle etc. |
| 9 | +These dependencies are defined in the ```requirements.txt``` file that comes with the SDK. |
| 10 | +To resolve these dependencies, you can use the PIP Dependency manager. Install it by following steps at [https://pip.pypa.io/en/stable/installing/](https://pip.pypa.io/en/stable/installing/). |
| 11 | + |
| 12 | +Python and PIP executables should be defined in your PATH. Open command prompt and type ```pip --version```. |
| 13 | +This should display the version of the PIP Dependency Manager installed if your installation was successful and the paths are properly defined. |
| 14 | + |
| 15 | +* Using command line, navigate to the directory containing the generated files (including ```requirements.txt```) for the SDK. |
| 16 | +* Run the command ```pip install -r requirements.txt```. This should install all the required dependencies. |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +## How to Use |
| 22 | + |
| 23 | +The following section explains how to use the MessageMediaWebhooks SDK package in a new project. |
| 24 | + |
| 25 | +### 1. Open Project in an IDE |
| 26 | + |
| 27 | +Open up a Python IDE like PyCharm. The basic workflow presented here is also applicable if you prefer using a different editor or IDE. |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | +Click on ```Open``` in PyCharm to browse to your generated SDK directory and then click ```OK```. |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | +The project files will be displayed in the side bar as follows: |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | +### 2. Add a new Test Project |
| 40 | + |
| 41 | +Create a new directory by right clicking on the solution name as shown below: |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | +Name the directory as "test" |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | +Add a python file to this project with the name "testsdk" |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | +Name it "testsdk" |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | +In your python file you will be required to import the generated python library using the following code lines |
| 58 | + |
| 59 | +```Python |
| 60 | +from message_media_webhooks.message_media_webhooks_client import MessageMediaWebhooksClient |
| 61 | +``` |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | +After this you can write code to instantiate an API client object, get a controller object and make API calls. Sample code is given in the subsequent sections. |
| 66 | + |
| 67 | +### 3. Run the Test Project |
| 68 | + |
| 69 | +To run the file within your test project, right click on your Python file inside your Test project and click on ```Run``` |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | +## How to Test |
| 75 | + |
| 76 | +You can test the generated SDK and the server with automatically generated test |
| 77 | +cases. unittest is used as the testing framework and nose is used as the test |
| 78 | +runner. You can run the tests as follows: |
| 79 | + |
| 80 | + 1. From terminal/cmd navigate to the root directory of the SDK. |
| 81 | + 2. Invoke ```pip install -r test-requirements.txt``` |
| 82 | + 3. Invoke ```nosetests``` |
| 83 | + |
| 84 | +## Initialization |
| 85 | + |
| 86 | +### Authentication |
| 87 | +In order to setup authentication and initialization of the API client, you need the following information. |
| 88 | + |
| 89 | +| Parameter | Description | |
| 90 | +|-----------|-------------| |
| 91 | +| basic_auth_user_name | The username to use with basic authentication | |
| 92 | +| basic_auth_password | The password to use with basic authentication | |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | +API client can be initialized as following. |
| 97 | + |
| 98 | +```python |
| 99 | +# Configuration parameters and credentials |
| 100 | +basic_auth_user_name = 'basic_auth_user_name' # The username to use with basic authentication |
| 101 | +basic_auth_password = 'basic_auth_password' # The password to use with basic authentication |
| 102 | + |
| 103 | +client = MessageMediaWebhooksClient(basic_auth_user_name, basic_auth_password) |
| 104 | +``` |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | +# Class Reference |
| 109 | + |
| 110 | +## <a name="list_of_controllers"></a>List of Controllers |
| 111 | + |
| 112 | +* [WebhooksController](#webhooks_controller) |
| 113 | + |
| 114 | +## <a name="webhooks_controller"></a> WebhooksController |
| 115 | + |
| 116 | +### Get controller instance |
| 117 | + |
| 118 | +An instance of the ``` WebhooksController ``` class can be accessed from the API Client. |
| 119 | + |
| 120 | +```python |
| 121 | + webhooks_controller = client.webhooks |
| 122 | +``` |
| 123 | + |
| 124 | +### <a name="create_webhook"></a> create_webhook |
| 125 | + |
| 126 | +> Create a webhook for one or more of the specified events. |
| 127 | +> A webhook would typically have the following structure: |
| 128 | +> ``` |
| 129 | +> { |
| 130 | +> "url": "http://webhook.com", |
| 131 | +> "method": "POST", |
| 132 | +> "encoding": "JSON", |
| 133 | +> "headers": { |
| 134 | +> "Account": "DeveloperPortal7000" |
| 135 | +> }, |
| 136 | +> "events": [ |
| 137 | +> "RECEIVED_SMS" |
| 138 | +> ], |
| 139 | +> "template": "{\"id\":\"$mtId\",\"status\":\"$statusCode\"}" |
| 140 | +> } |
| 141 | +> ``` |
| 142 | +> A valid webhook must consist of the following properties: |
| 143 | +> - ```url``` The configured URL which will trigger the webhook when a selected event occurs. |
| 144 | +> - ```method``` The methods to map CRUD (create, retrieve, update, delete) operations to HTTP requests. |
| 145 | +> - ```encoding``` The format in which the payload will be returned. You can choose from ```JSON```, ```FORM_ENCODED``` or ```XML```. This will automatically add the Content-Type header for you so you don't have to add it again in the `headers` property. |
| 146 | +> - ```headers``` HTTP header fields which provide required information about the request or response, or about the object sent in the message body. This should not include the `Content-Type` header. |
| 147 | +> - ```events``` Event or events that will trigger the webhook. Atleast one event should be present. |
| 148 | +> - ```template``` The structure of the payload that will be returned. |
| 149 | +> #### Types of Events |
| 150 | +> 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. |
| 151 | +> A webhook will be triggered when any one or more of the events occur: |
| 152 | +> + **SMS** |
| 153 | +> + `RECEIVED_SMS` Receive an SMS |
| 154 | +> + `OPT_OUT_SMS` Opt-out occured |
| 155 | +> + **MMS** |
| 156 | +> + `RECEIVED_MMS` Receive an MMS |
| 157 | +> + **DR (Delivery Reports)** |
| 158 | +> + `ENROUTE_DR` Message is enroute |
| 159 | +> + `EXPIRED_DR` Message has expired |
| 160 | +> + `REJECTED_DR` Message is rejected |
| 161 | +> + `FAILED_DR` Message has failed |
| 162 | +> + `DELIVERED_DR` Message is delivered |
| 163 | +> + `SUBMITTED_DR` Message is submitted |
| 164 | +> #### Template Parameters |
| 165 | +> You can choose what to include in the data that will be sent as the payload via the Webhook. |
| 166 | +> Keep in my mind, you must escape the JSON in the template value (see example above). |
| 167 | +> 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. |
| 168 | +> | Data | Parameter Name | Example | Event Type | |
| 169 | +> |:--|--|--|--|--| |
| 170 | +> | **Service Type** | $type| `SMS` | `DR` `MO` `MO MMS` | |
| 171 | +> | **Message ID** | $mtId, $messageId| `877c19ef-fa2e-4cec-827a-e1df9b5509f7` | `DR` `MO` `MO MMS`| |
| 172 | +> | **Delivery Report ID** |$drId, $reportId| `01e1fa0a-6e27-4945-9cdb-18644b4de043` | `DR` | |
| 173 | +> | **Reply ID**| $moId, $replyId| `a175e797-2b54-468b-9850-41a3eab32f74` | `MO` `MO MMS` | |
| 174 | +> | **Account ID** | $accountId| `DeveloperPortal7000` | `DR` `MO` `MO MMS` | |
| 175 | +> | **Message Timestamp** | $submittedTimestamp| `2016-12-07T08:43:00.850Z` | `DR` `MO` `MO MMS` | |
| 176 | +> | **Provider Timestamp** | $receivedTimestamp| `2016-12-07T08:44:00.850Z` | `DR` `MO` `MO MMS` | |
| 177 | +> | **Message Status** | $status| `enroute` | `DR` | |
| 178 | +> | **Status Code** | $statusCode| `200` | `DR` | |
| 179 | +> | **External Metadata** | $metadata.get('key')| `name` | `DR` `MO` `MO MMS` | |
| 180 | +> | **Source Address**| $sourceAddress| `+61491570156` | `DR` `MO` `MO MMS` | |
| 181 | +> | **Destination Address**| $destinationAddress| `+61491593156` | `MO` `MO MMS` | |
| 182 | +> | **Message Content**| $mtContent, $messageContent| `Hi Derp` | `DR` `MO` `MO MMS` | |
| 183 | +> | **Reply Content**| $moContent, $replyContent| `Hello Derpina` | `MO` `MO MMS` | |
| 184 | +> | **Retry Count**| $retryCount| `1` | `DR` `MO` `MO MMS` | |
| 185 | +> *Note: A 400 response will be returned if the `url` is invalid, the `events`, `encoding` or `method` is null or the `headers` has a Content-Type attribute.* |
| 186 | +
|
| 187 | +```python |
| 188 | +def create_webhook(self, |
| 189 | + body) |
| 190 | +``` |
| 191 | +
|
| 192 | +#### Parameters |
| 193 | + |
| 194 | +| Parameter | Tags | Description | |
| 195 | +|-----------|------|-------------| |
| 196 | +| body | ``` Required ``` | TODO: Add a parameter description | |
| 197 | + |
| 198 | + |
| 199 | + |
| 200 | +#### Example Usage |
| 201 | + |
| 202 | +```python |
| 203 | +body = CreateWebhookRequest() |
| 204 | + |
| 205 | +result = webhooks_controller.create_webhook(body) |
| 206 | + |
| 207 | +``` |
| 208 | + |
| 209 | +#### Errors |
| 210 | + |
| 211 | +| Error Code | Error Description | |
| 212 | +|------------|-------------------| |
| 213 | +| 400 | Unexpected error in API call. See HTTP response body for details. | |
| 214 | +| 409 | Unexpected error in API call. See HTTP response body for details. | |
| 215 | + |
| 216 | + |
| 217 | + |
| 218 | + |
| 219 | +### <a name="retrieve_webhook"></a> retrieve_webhook |
| 220 | + |
| 221 | +> Retrieve all the webhooks created for the connected account. |
| 222 | +> A successful request to the retrieve webhook endpoint will return a response body as follows: |
| 223 | +> ``` |
| 224 | +> { |
| 225 | +> "page": 0, |
| 226 | +> "pageSize": 100, |
| 227 | +> "pageData": [ |
| 228 | +> { |
| 229 | +> "url": "https://webhook.com", |
| 230 | +> "method": "POST", |
| 231 | +> "id": "8805c9d8-bef7-41c7-906a-69ede93aa024", |
| 232 | +> "encoding": "JSON", |
| 233 | +> "events": [ |
| 234 | +> "RECEIVED_SMS" |
| 235 | +> ], |
| 236 | +> "headers": {}, |
| 237 | +> "template": "{\"id\":\"$mtId\", \"status\":\"$statusCode\"}" |
| 238 | +> } |
| 239 | +> ] |
| 240 | +> } |
| 241 | +> ``` |
| 242 | +> *Note: Response 400 is returned when the `page` query parameter is not valid or the `pageSize` query parameter is not valid.* |
| 243 | +
|
| 244 | +```python |
| 245 | +def retrieve_webhook(self, |
| 246 | + page=None, |
| 247 | + page_size=None) |
| 248 | +``` |
| 249 | +
|
| 250 | +#### Parameters |
| 251 | + |
| 252 | +| Parameter | Tags | Description | |
| 253 | +|-----------|------|-------------| |
| 254 | +| page | ``` Optional ``` | TODO: Add a parameter description | |
| 255 | +| pageSize | ``` Optional ``` | TODO: Add a parameter description | |
| 256 | + |
| 257 | + |
| 258 | + |
| 259 | +#### Example Usage |
| 260 | + |
| 261 | +```python |
| 262 | +page = 85 |
| 263 | +page_size = 85 |
| 264 | + |
| 265 | +result = webhooks_controller.retrieve_webhook(page, page_size) |
| 266 | + |
| 267 | +``` |
| 268 | + |
| 269 | +#### Errors |
| 270 | + |
| 271 | +| Error Code | Error Description | |
| 272 | +|------------|-------------------| |
| 273 | +| 400 | Unexpected error in API call. See HTTP response body for details. | |
| 274 | + |
| 275 | + |
| 276 | + |
| 277 | + |
| 278 | +### <a name="delete_webhook"></a> delete_webhook |
| 279 | + |
| 280 | +> Delete a webhook that was previously created for the connected account. |
| 281 | +> 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. |
| 282 | +> *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.* |
| 283 | +
|
| 284 | +```python |
| 285 | +def delete_webhook(self, |
| 286 | + webhook_id) |
| 287 | +``` |
| 288 | + |
| 289 | +#### Parameters |
| 290 | + |
| 291 | +| Parameter | Tags | Description | |
| 292 | +|-----------|------|-------------| |
| 293 | +| webhookId | ``` Required ``` | TODO: Add a parameter description | |
| 294 | + |
| 295 | + |
| 296 | + |
| 297 | +#### Example Usage |
| 298 | + |
| 299 | +```python |
| 300 | +webhook_id = a7f11bb0-f299-4861-a5ca-9b29d04bc5ad |
| 301 | + |
| 302 | +webhooks_controller.delete_webhook(webhook_id) |
| 303 | + |
| 304 | +``` |
| 305 | + |
| 306 | +#### Errors |
| 307 | + |
| 308 | +| Error Code | Error Description | |
| 309 | +|------------|-------------------| |
| 310 | +| 404 | TODO: Add an error description | |
| 311 | + |
| 312 | + |
| 313 | + |
| 314 | + |
| 315 | +### <a name="update_webhook"></a> update_webhook |
| 316 | + |
| 317 | +> 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) |
| 318 | +> A successful request to the retrieve webhook endpoint will return a response body as follows: |
| 319 | +> ``` |
| 320 | +> { |
| 321 | +> "url": "https://webhook.com", |
| 322 | +> "method": "POST", |
| 323 | +> "id": "04442623-0961-464e-9cbc-ec50804e0413", |
| 324 | +> "encoding": "JSON", |
| 325 | +> "events": [ |
| 326 | +> "RECEIVED_SMS" |
| 327 | +> ], |
| 328 | +> "headers": {}, |
| 329 | +> "template": "{\"id\":\"$mtId\", \"status\":\"$statusCode\"}" |
| 330 | +> } |
| 331 | +> ``` |
| 332 | +> *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.* |
| 333 | +
|
| 334 | +```python |
| 335 | +def update_webhook(self, |
| 336 | + webhook_id, |
| 337 | + body) |
| 338 | +``` |
| 339 | +
|
| 340 | +#### Parameters |
| 341 | + |
| 342 | +| Parameter | Tags | Description | |
| 343 | +|-----------|------|-------------| |
| 344 | +| webhookId | ``` Required ``` | TODO: Add a parameter description | |
| 345 | +| body | ``` Required ``` | TODO: Add a parameter description | |
| 346 | + |
| 347 | + |
| 348 | + |
| 349 | +#### Example Usage |
| 350 | + |
| 351 | +```python |
| 352 | +webhook_id = a7f11bb0-f299-4861-a5ca-9b29d04bc5ad |
| 353 | +body_value = " { \"url\": \"https://myurl.com\", \"method\": \"POST\", \"encoding\": \"FORM_ENCODED\", \"events\": [ \"ENROUTE_DR\" ], \"template\": \"{\\\"id\\\":\\\"$mtId\\\", \\\"status\\\":\\\"$statusCode\\\"}\" }" |
| 354 | +body = json.loads(body_value) |
| 355 | + |
| 356 | +result = webhooks_controller.update_webhook(webhook_id, body) |
| 357 | + |
| 358 | +``` |
| 359 | + |
| 360 | +#### Errors |
| 361 | + |
| 362 | +| Error Code | Error Description | |
| 363 | +|------------|-------------------| |
| 364 | +| 400 | Unexpected error in API call. See HTTP response body for details. | |
| 365 | +| 404 | TODO: Add an error description | |
| 366 | + |
| 367 | + |
| 368 | + |
| 369 | + |
| 370 | +[Back to List of Controllers](#list_of_controllers) |
0 commit comments