Codxplore.com

Latest news:

Sahih al-Bukhari (সহীহ বুখারী) is a free Hadith application for android. This application is advertisement free. Download now https://play.google.com/store/apps/details?id=com.akramhossin.bukharisharif

Nodejs send sms using SMSBOX api


Nodejs send sms using SMSBOX api

In this blog post i will try to describe how to implement SMSBOX sms gateway in Nodejs application. to implement SMSBOX into any Nodejs application you

will need a SMSBOX account, you can register for new account at https://www.smsbox.com/

which is not free.Upon registration SMSBOX will provide you username and password to login to SMSBOX control panel.

After login to SMSBOX dashboard, Under left menu go to Account section and click on user info menu.You will see user info page.

In top part of that page contains user information such as email, phone, current balance,city, country etc.

Bottom part of that page contains api information such as Username, Your Api ID, Simple Request URL etc.

For implementation we will need 

  • Username 
  • Password 
  • Your Api ID 
  • Simple Request URL

Implementation:

Now we will create an async function named as sendSMS, this function will have following Parameters 

  • phone: string;
  • msg: string;
  • sender: string;

complete function will be look like this

https://i.imgur.com/x4bU36q.png

SMSBOX require xml http request, so we will create another async function named as sendXmlHttpGetRequest

which will be responsible for sending xml http request to SMSBOX.

this function will have following Parameters

  • hostname: string;
  • path: string;
  • query: any

final code will be look like this

https://i.imgur.com/2zSmY67.png

This xml http request depends on two npm package one is Follow Redirects, another one is url.

Do not forget to add this to your package dependency.

To install Follow Redirects run npm i follow-redirects into terminal.

and import these two package in top of your file as like bellow

import { http, https } from 'follow-redirects';

import url from 'url';

To send sms you just need to call that sendSMS function like this 

let msg = 'Hello! this is test SMS';

let phone = '+9654758xxxx';

let sms = await this.sendSMS(phone, msg, 'SENDER NAME');

Thats it. 

Tags : javascript, Nodejs,

Views : 963

Subscribe Us


Follow Us