SMS Webhook

Overview

Make an http/https API call to an external system and POST SMS/MMS details whenever an SMS/MMS event occurs on the PBX. 

Configuration

Overview

To navigate to the SMS WebHook:

  • Click Modules in the top menu

  • Click SMS under Connectivity category

The home screen will show any webhook that have been created.

Add Webhook

Click on the + Add New Web Hook option at the top.

WebHook Enabled:-

Yes/No: You can enable/disable the WebHook by toggling this switch.

WebHook Base URL :-

Set the URL, where you want data to be sent. It should be proper URL including protocol.

When data has to be sent:-

Choose which SMS events fire the webhook

Send:- When send the SMS.

Receive:- When Receive a SMS.

Send and Receive :- In both cases (Send And Receive)

Note

Only three webhook are supported, One webhook for each process (Send, Receive, Send and receive)

Edit/Delete WebHook

On the home screen → Actions section we have option to edit and delete the webhook.

 

Note

SMS webhooks can also be added / updated / deleted using SMS Module GraphQL APIs

Example

Here is sample data which we are sending to webhook (Send Process)

  1. SMS data

    { "to": "1202020", "from": "1212121", "adaptor": "Sipstation", "time": "Thu, 13 Dec 5612 16:39:39 +0000", "message": "Hello", "eventDirection": "out" }
  2. MMS data

    { "to": "1202020", "from": "1212121", "adaptor": "Sipstation", "time": "Thu, 13 Dec 5612 16:39:39 +0000", "message": { mediaUrl:"http://AMPWEBADDRESS/admin/api/api/rest/sms/media/8" }, "eventDirection": "out" }

AMPWEBADDRESS can be set in Settings → Advance Settings page or can be set using GQL API (https://wiki.sangoma.com/display/FPG/Core+Module+GraphQL+APIs#CoreModuleGraphQLAPIs-UpdateAdvanceSetting's)

Logs

We are storing all the webhook records in sms_web_hook.log file.

Path:- /var/log/asterisk/sms_web_hook.log

Testing

Please follow the steps below to test the webhook functionality.

  1. Configure SipStation / VoipInnovations in FreePBX Server (Make sure SMS is enabled for DIDs) 

  2. Assign the DID number to any user.

  3. Login to UCP with this user.

  4. Use https://webhook.site/ and copy the unique URL, add the same URL as Webhook for send process

  5. Send the SMS by UCP

  6. SMS Data / MMS url will display on the browser(https://webhook.site/ page)

  7. MMS file can be fetched using the url sent to the webhook. 

    1. Create a authorization token for REST API (Reference Link: https://wiki.freepbx.org/display/FPG/REST+API)

    2. Use the generate authorization token in header to get the MMS file 

    3. Or alternatively can use the below PHP script by replacing API URL and authorization token

      <?php $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'http://AMPWEBADDRESS/admin/api/api/rest/sms/media/5', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NDBiMWRkMjMxOGFjY2YzMTVkODNiOGM5ZWI2MGQyOGYxOGQwMzM2OTIxNDBkZTc0IiwianRpIjoijM2I0ZmM4NmE0YzRlYTlkZGNjNDFlOTA2ZTYwMDZI6MTY0MDg0Njg5OiIiLCJzY29wZXMiOlsicmVzdCJdfQ.JuBSC0gAzWLYrPRJ52fUyy-LusIPT0xfB5e3g_ahlAoi6oMvSNhYh9JAzcXhEYJyr2s9wi4BcsINbPXEbrnG-b8r62F3fdfIc2IOdxdkMUKVif2JyudiOhNC9FOZf26wZ2Ytaf0ssb-n836Pvl1CySj_oIv9TX32Xe8bjPfJobuX2ZH5IlVani3CyypnF5ydwy3lmUFXoo5BhZwDMzKa7ZWhdwG_afzQm9lG7Q4u9b-gomezWOd2TlKtrZZ0DAyxLL12mhmwc8Wq_PpepcKz_UVlz4_OAris5jg5U_1UnpnuNpCKZM2RkRSg', 'Cookie: PHPSESSID=813a845q6ch8ulcvk9klvosgt2' ), )); $response = curl_exec($curl); curl_close($curl); $finfo = new \finfo(FILEINFO_MIME); header('Content-Type: ' . $finfo->buffer($response)); header("Content-Length: " . strlen($response)); echo $response; ?>

 

 

Return to Documentation Home I Return to Sangoma Support