Solutions Infini SMS gateway integration using Node.js, AWS lambda & API Gateway

AWS lambda

AWS Lambda runs your code on a high-availability compute infrastructure and performs all of the compute resource management including the operating system and server maintenance, automatic scaling and code monitoring, capacity provisioning, etc., which makes it ideal for sending messages.

Node.js Support

The AWS SDK for Node.js enables developers to build libraries and applications that use AWS services. You can use the JavaScript API in the browser and inside Node.js applications on the server.

API Gateway

Amazon API Gateway manages all the tasks involved in accepting and processing up to hundreds of thousands of concurrent API calls, including authorization and access control, traffic management,  monitoring, and API version management.

Requirement

Sending an SMS based on the request parameters through API call.

Prerequisites

  • AWS lambda function
  • API Gateway
  • Node.js

Solution

API Gateway

The following Steps are required for implementing the above flow chart:

Step 1: Create a Lambda function using the below code.

var globalTunnel = require('global-tunnel');

var aws = require("aws-sdk");

var solutionInfiApiUrl = “http://alerts.solutionsinfini.com/api/v3/index.php?method=sms.json&api_key=” + <APIKey>;

var request = require('request');

//initializing Json request

              var Json = {};

              Json.sender = <Sender Number>;

              Json.message = <Message>;

              Json.format = 'json';

              Json.flash = 0;

              Json.sms = [];

              var receiver = {}

              receiver.to =<receiver Number>;

              Json.sms.push(receiver);

                var body = JSON.stringify(Json);                     

              // making POST request to send SMS

              request.post({

                       url:  solutionInfiApiUrl,

                       body:   body

                  }, function(error, response){

                 if (error) {

                     result.message = 'Send SMS faild'

                       result.error = error ;

                             context.fail (result);

}

                else{

                   result.message = 'SMS sent Successfully to ' + phoneMumber;

                   console.log('response' +  JSON.stringify(response));

                     context.succeed(result);

                 }

           }); 

Step 2: Create an API Gateway and add mapping of above lambda function.

Step 3: Test the API through Postman (Chrome App) by passing the below request parameters.

Request Format Type:  JSON 

      Method:  POST.

{

 "PhoneNumber": "<ReceiverMobileNumber>",

 "ProjectName": "<ProjectName>",

 "PropertyName": "<PropertyName>"

}

Conclusion

Using solutions inifini, we can create multiple Dynamic templates as well as a static template. Hence, we can send both dynamic and static SMS through AWS for the given phone number.

 

FacebookTwitterGoogle+Share
About Pragyan Panda

Pragyan panda is a software developer at Vmoksha Technologies who have outstanding knowledge in the .net domain. She also has work experience in AWS services.She is a person who is positive about every aspect of her life.Apart from this, she likes to spend her time by preparing food and listening music.



Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>