Skip to content

Instantly share code, notes, and snippets.

@itswadesh
Created December 17, 2016 14:21
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itswadesh/838e4ea2b6f841d313ecc8e05ce6d1b2 to your computer and use it in GitHub Desktop.
Save itswadesh/838e4ea2b6f841d313ecc8e05ce6d1b2 to your computer and use it in GitHub Desktop.
Send sms using NodeJS from India (https://www.textlocal.in/)
var http = require('http');
var urlencode = require('urlencode');
var msg = urlencode('hello js');
var toNumber = 'TO_PHONE_NO';
var username = 'TEXTLOCAL_USER_EMAIL';
var hash = 'TEXTLOCAL_USER_HASH'; // The hash key could be found under Help->All Documentation->Your hash key. Alternatively you can use your Textlocal password in plain text.
var sender = 'txtlcl';
var data = 'username=' + username + '&hash=' + hash + '&sender=' + sender + '&numbers=' + toNumber + '&message=' + msg;
var options = {
host: 'api.textlocal.in', path: '/send?' + data
};
callback = function (response) {
var str = '';//another chunk of data has been recieved, so append it to `str`
response.on('data', function (chunk) {
str += chunk;
});//the whole response has been recieved, so we just print it out here
response.on('end', function () {
console.log(str);
});
}//console.log('hello js'))
http.request(options, callback).end();//url encode instalation need to use $ npm install urlencode
@cnuvasan
Copy link

cnuvasan commented Nov 4, 2017

sir in laravel i used your code but i didnot get the message. please give the solution

@nayan-dhabarde
Copy link

Hi Any one tried this? Does this work? so how do you use it?

@nayan-dhabarde
Copy link

A big thank you, really worked well

@prabhakarupadhyay
Copy link

cout<<"WOW works like a charm. \n THNX"

@Greeta-Hiyan
Copy link

Greeta-Hiyan commented May 28, 2019

It's working fine.. but I can't return a response.

@BMLande
Copy link

BMLande commented Jun 12, 2019

Thanks its working ,also you need to pass exact message template as template created on gateway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment