Last active
May 24, 2018 02:39
-
-
Save IbrahimTareq/0089efa22c3971a93314f397203f280f to your computer and use it in GitHub Desktop.
Code snippet on how to create a webhook using the MessageMedia Webhooks Node.js SDK.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const lib = require('messagemedia-webhooks-sdk'); | |
// Sets your auth credentials and creates controller which is used to call the createWebhook function from the SDK | |
function setup(){ | |
var controller; | |
// Configuration parameters and credentials | |
lib.Configuration.basicAuthUserName = "API_KEY"; | |
lib.Configuration.basicAuthPassword = "API_SECRET"; | |
controller = lib.WebhooksController; | |
return controller; | |
} | |
function createWebhook(){ | |
var controller = setup(); | |
// Create body of your webhook | |
var body = new lib.CreateWebhookRequest({ | |
"url": "http://webhook.com", // URL of the webhook | |
"method": "POST", // HTTP method | |
"encoding": "JSON", // Content type of the request | |
"events": [ | |
"RECEIVED_SMS" // Webhook subscribed to RECEIVED_SMS event which is triggered when an SMS is received | |
], | |
"template": "{\"id\":\"$mtId\",\"time_sent\":\"$submittedTimestamp\",\"time_received\":\"$receivedTimestamp\",\"account_id\":\"$accountId\"}" // The attributes in the template will be returned when the webhook is triggered | |
}); | |
// Call the function that creates the webhook | |
controller.createWebhook(body, function(error, response, context) { | |
console.log(response); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment