How to send message to phone# outside of the US? - vonage

My Nodejs app uses nexmo 2.8.0 to send message to cell phones and it works fine with US phone number. My question is how to send the message to phone# of other countries such as China and Hong Kong? According to the nexmo doc, it shall work with international phone#. But I tried and the other party didn't receive it. Here is the code:
const Nexmo = require("nexmo");
const nexmo = new Nexmo({
apiKey: process.env.nexmoApiKey,
apiSecret: process.env.nexmoApiSecret
}, { debug: true });
function sendNexmoSms(nexmo, vcode, cell, cell_country_code){ //vcode is the message
return new Promise(resolve => {
nexmo.message.sendSms(process.env.nexmo_sender_number, cell_country_code + cell, vcode, {type: 'unicode'}, async (err, result) => {
if(err){
resolve('failed to send');
}else{
if (result.messages[0]['status'] === "0") {
resolve('success');
} else {
resolve('failed to send');
}
}
});
});
};

According to Vonage document, you should set the receiver number in E.164 format
Here is how to build E.164 format phone number: https://www.twilio.com/docs/glossary/what-e164

Can you share more details about the question? It is not clear about the error code that you receive.
One of the issue can be routing issue as well.

Related

AWS-SNS publish() method not sending any messages to phone number

I have used aws-sdk in node express to send the verification code to the phone number I referred this docs to implement it. here I get the response but do not get any messages on the phone.
const AWS = require("aws-sdk");
AWS.config.update({
region: "region",
accessKeyId: "ACCESS_KEY",
secretAccessKey: "SECRET_KEY",
});
router.post("/", async (req, res) => {
let phone_no = "+91876214****";
let random = Math.floor(100000 + Math.random() * 900000);
const YOUR_MESSAGE = `Your verification code is ${random}`;
let params = {
Message: YOUR_MESSAGE,
PhoneNumber: phone_no,
MessageAttributes: {
"AWS.SNS.SMS.SMSType": {
DataType: "String",
StringValue: "Transactional",
},
};
let publishTextPromise = new AWS.SNS({ apiVersion: "2010-03-31" })
.publish(params)
.promise();
publishTextPromise
.then(function (data) {
return res.json({ id: data.MessageId, otp: random });
})
.catch(function (err) {
return res.send(err.stack);
});
});
is anything I'm doing wrong, new to this aws-sns concept.
here i logged the publishTextPromise i get response as Promise { <pending> }
If you get Success result from api but message is not received. You need to check SNS logs.
On SNS console, you can see Text messaging (SMS) under Mobile section. If you don't enable status logging, firstly edit preferences on Delivery status logs section then on new page create an IAM Role (SNSSuccessFeedback) with Success sample rate 100%.
You can find error on cloudwatch.
Potential problem. You account is in the SMS sandbox in the region which you used.
If you see any message like ☝️, You can add your phone number on sandbox destination phone number.
Then sandbox will send you a verify code, when you put it on AWS console. Then you will be able to receive messages from SNS.

twilio isn't sending sms nodejs

I use twilio to send sms after a order is placed, but it isn't sending any sms and also not console logging anything.
Code: npm i twilio
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require("twilio")(accountSid, authToken);
exports.createOrder = (req, res) => {
const { orders, status, details } = req.body;
const order = new Order({
orders: orders,
status: status,
details: details,
});
order.save((error, order) => {
if (error) return res.status(400).json(error);
if (order) {
// if (res.status === 201) {
client.messages
.create({
body: "This is the ship that made the Kessel Run in fourteen parsecs?",
from: "+xxxxxxxxx",
to: "+xxxxxxxxxx",
})
.then((message) => console.log(message.sid));
// }
return res.status(201).json({ order });
}
});
};
LINK TO DOC (where I took the code) : https://www.twilio.com/docs/sms/quickstart/node
Twilio developer evangelist here.
There is likely an issue in sending your message, but the code you have is dropping errors, so you can't see what is going on. Try updating it to this:
client.messages
.create({
body: "This is the ship that made the Kessel Run in fourteen parsecs?",
from: "+xxxxxxxxx",
to: "+xxxxxxxxxx",
})
.then((message) => console.log(message.sid))
.catch(error => console.error(error));
Once you see what the error is, you will be able to fix it. My guess is that you have either configured your Account Sid and Auth Token incorrectly, or you are using a trial account and trying to send a message to a number you haven't verified yet, or you are trying to send a message to a country that isn't enabled.

Azure SMS message is not received on phone after a successful response

I'm using the latest Azure Communication SMS package, and basically directly copy/pasted the sample code to try sending a text to my cell. I got a successful 202 code back and can see the event successfully in the event grid I set up. But my phone never got the text, if it helps T-Mobile is my cell provider and I reside in the US with a US cell number.
Here is my code sample and response with sensitive information redacted
public sendSms = async (message: string, numbers: string[]) => {
if (this.checkIfReachLimit()) {
return;
}
const endpoint = `https://<resource name>.communication.azure.com`;
const credential = new AzureKeyCredential("<cred>");
const client = new SmsClient(endpoint, credential);
try {
const sendResults = await client.send(
{
from: "My Azure Toll Free #", // Your E.164 formatted phone number used to send SMS
to: numbers, // The list of E.164 formatted phone numbers to which message is being sent
message, // The message being sent
},
{
enableDeliveryReport: true,
tag: "workoutBuilder",
},
);
this.updateMonthlyCount(sendResults.length);
for (const sendResult of sendResults) {
if (sendResult.successful) {
console.log("Success: ", sendResult);
} else {
console.error("Something went wrong when trying to send this message: ", sendResult);
}
}
} catch (ex) {
// no op
}
};
Response:
{
to: 'my cell',
messageId: 'message id',
httpStatusCode: 202,
repeatabilityResult: 'accepted',
successful: true
}

Twilio Check the Verification Token API+postman timeout

I am setting up phone authentication with Twilio, using nodejs....All is working as expected, except when verifying the token. Below is the function which I am using:
verifyPhone: function (req, res) {
client.verify.services('VAxxxxxxxxxxxxxxxx')
.verificationChecks
.create({ to: '+15017122661', code: '123456' })
.then(function (err, verification_check) {
if (err) {
res.status(500).send(err);
} else if (verification_check ==='approved') {
res.status(200).send('Account Verified');
}
})
}
I am checking the endpoint in postman, and it is timing out with no response.
When, I checked in twilio portal, the number status changed to approved.
Any idea why the response is not showing up.
Btw, I turned off SSL certificate
Thanks,
The Twilio Function JavaScript below works for me.
Since Verify v2 is relatively new, make sure your Twilio Helper library is up to date, https://github.com/twilio/twilio-node/releases.
Example to execute function (I have Check for valid Twilio signature turned off for my Twilio function to demo this):
(Example URL to Run Function):
https://mango-abcdef-1234.twil.io/v2start?phoneNumber=%2b15555551234&code=720732
exports.handler = function(context, event, callback) {
const client = context.getTwilioClient();
const code = event.code;
let phoneNumber = event.phoneNumber;
client.verify.services('VAxxxxxxxxxxxxxxxx')
.verificationChecks
.create({to: phoneNumber, code: code})
.then(verification_check => {
console.log(`***VERIFICATION STATUS***: ${verification_check.status}`);
callback(null, `${verification_check.status}`);
})
.catch(err => {
console.log(err);
callback();
});
};
Also recent blog on this topic.
Serverless Phone Verification with Twilio Verify and Twilio Functions

Trying to Send Email Using Alexa and AWS SES. Email will send however Alexa will return and Error

I am writing an Alexa Skill where one of the functions is to request to send an email to a user using AWS SES.
When the utterance is said to send the email, the email will send however Alexa will always reply 'There was a problem with the requested skill's response'.
I have tested to make sure the 'getEmail' intent itself is working and it is.
I have also tried moving the function within the intent but this has the same results.
This is the function to send the email using SES which seems to be working:
function sendEmail (event, context, callback){
var params = {
Destination: {
ToAddresses: ["xyz#gmail.com"]
},
Message: {
Body: {
Text: { Data: "Hi. Here is your email"
}
},
Subject: { Data: "Here is an email"
}
},
Source: "abc#gmail.com"
};
ses.sendEmail(params, function (err, data) {
callback(null, {err: err, data: data});
if (err) {
console.log(err);
context.fail(err);
} else {
console.log(data);
context.succeed(event);
}
});
}
Here is the intent which call the sendEmail() function.
'getEmail': function () {
sendEmail();
var bodyTemplate1 = new Alexa.templateBuilders.BodyTemplate1Builder();
var template1 = bodyTemplate1.setTitle("email").setTextContent(makeRichText("email")).setBackgroundImage(makeImage(image)).build();
this.response.speak("Your email has been sent").renderTemplate(template1).shouldEndSession(true);
this.emit(':responseReady');
},
When I run this I would like for the email to send to the the device and Alexa to just say "Your Email has been sent". At the moment it is just the email that is sending and the device saying "There was a problem with the requested skill's response"
Here is the error message from AWS Cloud
Looking at logs, your callback(null, {err: err, data: data}); is the issue here. From the code that you posted, callback doesn't exist (will be undefined). It doesn't look like you need that there so you can remove it.
AWS SDK - SES.sendEmail
The "callback" is just your function that's passed as the second argument.

Resources