SMPP delivery receipt response not coming in Node smpp - node.js

I am using Node SMPP,i am able to send SMS to my number but i can't get delivery receipt it is delivered or not . Please refer my below code
can you please guide if anything went wrong
var smpp = require('smpp');
var session = smpp.connect('103.250.30.x', 51612);
session.bind_transceiver({
system_id: 'makesms1',
password: 'Prasad#1'
}, function(pdu) {
if (pdu.command_status == 0) {
// Successfully bound
console.log('bound bind_transceiver')
session.submit_sm({
destination_addr: '90000541x0',
short_message: new Buffer("Hi, Froxtel interview SMS/email has been sent by company only. Its not any related to freshersworld. U can contact directly company or call 08688805062/3.Please ignore the word freshersworld in sms/mail.regards Froxtel team.","utf8"),
source_addr:'FROXTL',
registered_delivery:1,
data_coding:0,
}, function(pdu) {
if (pdu.command_status == 0) {
// Message successfully sent
console.log(JSON.stringify(pdu));
}
});
}
});
When i use nodejs shorty module it working fine and i am able to get delivery receipt . but i am unable to send long message.
should i use data_sm for long messages or other ?

Your code looks fine for sending and processing the responses to your outgoing requests.
The delivery receipts are sent from the smpp server to your client using deliver_sm pakets and therefore you need to register an event handler:
session.on('deliver_sm', function(pdu) {
console.log(pdu.short_message);
session.send(pdu.response());
});

Related

How to change reply of message based message sent from client in Twilio using Node.js?

I am trying to make an SMS conversation platform where a user would enter yes or no which will work as a boolean check and on true Twilio server will reply with 'response 1' and on false Twilio, the server will reply with 'response 2'? How will that work in Node.js? All the library just talk about basic sending and receiving but not about changing the reply based on the message which is received.
Twilio developer evangelist here.
When you receive a message to your Twilio number, Twilio makes an HTTP request (a webhook) to a URL you provide. On the end of that URL is your application which decides how to respond. The webhook sends all the details about the message, so you can use that to make your response.
For example, if you were using Express to respond to the webhook, then you're route might look like this:
const MessagingResponse = require('twilio').twiml.MessagingResponse;
app.post('/messages', (req, res) => {
let message = req.body.Body;
message = message.trim().toLowerCase();
const twiml = new MessagingResponse();
if (message === 'yes') {
twiml.message('You said "yes"! Fantastic!');
else if (message === 'no') {
twiml.message('You said "no". That's a shame.');
} else {
twiml.message('Please reply with a "yes" or a "no". Thank you.');
}
res.header('Content-Type', 'application/xml');
res.send(twiml.toString());
});
In this case, the Body property of the request body is the message that was sent to your Twilio number and you can use conditionals to reply depending on what it said.
Let me know if that helps at all.

Attach messagingServiceSid to a twiml response in nodejs library

I have a webhook setup, and I am able to receive messages and reply to them. I would like to have the responses sent by my webhook to have messagingServiceSid attached to them.
I didn't find on documentation a way to configure that for responses from my webhook, only for new SMS using
client.sendMessage({
messagingServiceSid: 'MG9752274e9e519418a7406176694466fa',
to: '+16518675309',
body: 'Phantom Menace was clearly the best of the prequel trilogy.'
}, function(err, message) {
console.log(message);
});
Is there something similar for this code? Is it doable through the UI?
app.post('/foo/bar/sms', twilio.webhook({
host:'gassy-ocelot-129.herokuapp.com',
protocol:'https'
}), function(request, response) {
var twiml = new twilio.TwimlResponse();
twiml.message('This HTTP request came from Twilio!');
response.send(twiml);
});
Images:
No messagingService on reply messages sent using twiml response
Message Detail view from logs
Twilio developer evangelist here.
As far as I'm aware, there's no way to reply to message from a message service with TwiML.
However, rather than using TwiML, you could just send the SMS back to your user from the REST API and return an empty <Response> to the incoming webhook. Something a bit like this:
app.post('/foo/bar/sms', twilio.webhook({
host:'gassy-ocelot-129.herokuapp.com',
protocol:'https'
}), function(request, response) {
// send the message from the message service
client.sendMessage({
messagingServiceSid: 'MG9752274e9e519418a7406176694466fa',
to: request.body.From,
body: 'Your message'
}, function(err, message) {
console.log(message);
});
// send empty TwiML response
var twiml = new twilio.TwimlResponse();
response.send(twiml);
})
Let me know if that helps at all.
If you receive an incoming SMS on a phone number currently set up to that Messaging Service (via the web ui or phone number REST), then the incoming requests will have MessagingServiceSid in the query string.

Send message in hindi language using mg91 api in node.js

I am using msg91 Node.js API to send SMS. It is working fine if the message's text is in English.
Now I want to send SMS in Hindi.
Problem is, if I don't encode the message, it returns Authentication error. Post encoding it says the message is sent, but I don't receive any message on the test target.
Error Message:
{ success: 'false',
token: 'Authentication failure' }
Sample message is:
मोजो में आपका स्वागत है
npm module used: msg91
npm install --save msg91
Sending SMS via msg91 is just a simple get call. You don't need to rely on a language specific API.
As long as you send unicode=1 in the get call you can insert hindi text in you messages.
For more information about the same read here - https://control.msg91.com/apidoc/textsms/send-sms.php
You can refer NodeJS package https://www.npmjs.com/package/springedge to send sms. You can install as
npm install springedge
Code example of sending sms:
// send sms
var springedge = require('springedge');
var params = {
'apikey': '', // API Key
'sender': 'SEDEMO', // Sender Name
'to': [
'919019xxxxxxxx' //Moblie Number
],
'message': 'test+message'
};
springedge.messages.send(params, 5000, function (err, response) {
if (err) {
return console.log(err);
}
console.log(response);
});
You will just need api key and trail account to use it. or you can customize it as per your requirement.

Node.js send message to GCM server

I'm trying to send a message to GCM server to forward to another phone. The request keeps saying 400. I've checked the code close to a hundred times, but I'll put it up just in case. I also have changed the registration token parameter to registration_id and various others, along with changing the data to arrays etc. Just to be clear that the API key and Registration ID work, I can get a push notification from this Web site:
http://demo.androidhive.info/gcm_chat/push_test.php
Here's the code:
var gcm = require('node-gcm');
var gcmSender = new gcm.Sender('A......1234568AAA'); //my api key
var GCMmessage = new gcm.Message();
GCMmessage.addData("message", message);
GCMmessage.addData("from", from);
GCMmessage.addNotification('title', 'Alert!!!');
GCMmessage.addNotification('body', 'Abnormal data access');
GCMmessage.addNotification('icon', 'ic_launcher');
var regtoken = response.GCM.RegID; //data returned from another function
//Gives the RegID for a specific user
gcmSender.send(GCMmessage, {"to" : regtoken}, function(err, gcmResponse) {
if(err){
console.log(err);
} else {
console.log(gcmResponse);
console.log("message sent");
}
});
Ok it seems that it is best to send your gcm message directly using an npm module like 'request' or something similar. When I sent a message using that I received a very detailed error message telling me that 'from' is a reserved word. I'm not sure if that was the whole issue, but having a detailed error message made the code modification pretty easy.

Getting 250 OK status Delivered from SendGrid, but the email never ends up in the mailbox

function sendEmailVerification(username, email, destination, response, cb){
// create a random number
var email_url = security.createEmailToken(username, email);
// create a new URL for the verify call that will go into the email
link=PROTOCOL+"://"+destination+"/verify?token="+email_url;
// to : request.query.to,
var verifyEmail = new sendgrid.Email();
verifyEmail.addTo(email);
verifyEmail.setSubject('Verify your email with example.com.');
verifyEmail.setFrom('verify#example.com');
verifyEmail.setText(link);
verifyEmail.setHtml(link);
verifyEmail.addFilter('templates', 'enable', 1);
verifyEmail.addFilter('templates', 'template_id', '3cf3g721-4a31-4fd1-a862-408707e18c96');
logger.debug("send: mail options for user: " + JSON.stringify(verifyEmail));
// use the smtp transport to send the email
sendgrid.send(verifyEmail, function(error, resp) {
if (error) {
logger.error(error);
response.status(500).send("A backend email send error occurred.");
response.end();
} else {
logger.debug("Message sent: " + resp.message);
response.status(200).send("email sent");
}
cb();
});
}
What am I doing wrong? It seems the client service is not accepting my emails. Is it a problem with the headers? I am attempting to send a verification email with a SendGrid template.
Any suggestions are greatly appreciated, and thank you ahead of time!
Have you checked your Email Activity on your SendGrid account?
There's two big steps to mail delivery: You passing the message to SendGrid (the 200 OK Martyn is talking about), and SendGrid attempting to deliver the message for you (ideally, the 250 Delivered event).
If you're getting a 250 Delivered event, but not seeing it on the recipient side, that means the mail server is accepting the message from SendGrid, but not giving it to the recipient for some reason. Unfortunately, SendGrid can't see any further than the Delivered event, so you'd have to talk to the mail admin of the receiving server to see what's happened with the message.
I had this error and turned out GMail was sending my messages to Spam and Trash.

Resources