Skip to content

Instantly share code, notes, and snippets.

@IbrahimTareq
Last active May 24, 2018 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IbrahimTareq/0089efa22c3971a93314f397203f280f to your computer and use it in GitHub Desktop.
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.
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