Azure SMS message is not received on phone after a successful response - node.js

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
}

Related

Amazon Pinpoint SMS For India

I am trying to implement Amazon's Pinpoint SMS. There is a special requirement for India to send SMS. I have followed this Documentation and added EntityId and TemplateId as extra parameters to pinpoint.sendMessages. But when I do, I am getting.
UnexpectedParameter: Unexpected key 'EntityId' found in params.MessageRequest.MessageConfiguration.SMSMessage
UnexpectedParameter: Unexpected key 'TemplateId' found in params.MessageRequest.MessageConfiguration.SMSMessage
Code
Refrence: AWS Official Pinpoint SMS Doc
let params = {
ApplicationId: applicationId,
MessageRequest: {
Addresses: {
[destinationNumber]: {
ChannelType: 'SMS'
}
},
MessageConfiguration: {
SMSMessage: {
Body: body,
EntityId: entityID,
Keyword: registeredKeyword,
MessageType: messageType,
OriginationNumber: originationNumber,
SenderId: senderId,
TemplateId: templateID
},
}
}
};
//Try to send the message.
pinpoint.sendMessages(params, function (err, data) {
// If something goes wrong, print an error message.
if (err) {
console.log(err.message);
// Otherwise, show the unique ID for the message.
} else {
console.log(data)
// console.log("Message sent! "
// + data['MessageResponse']['Result'][destinationNumber]['StatusMessage']);
}
});
Migrating AWS-SDK from 2.467.0 to 2.850 solved my issue.

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

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.

AWS SES Error: Email address is not verified

I am trying to send email using aws-sdk ses in nodejs.
While executing the code the response I am getting is:
message:
'Email address is not verified. The following identities failed the check in region US-EAST-1:xxxtestemailxxx#gmail.com',
code: 'MessageRejected'
I have already verified the sender as well as receiver email(destination email in a array).
On SES settings of aws console, it is showing the email is verified. I removed the email and then once again successfully verified it.
Last time(few months back) when I used it, everything was working fine.
Below is the screenshot of my aws console related to SES:
Also when I am sending the test email using aws console, its working fine. This is only happening when I am trying to send email using aws-sdk.
Does anyone knows what is wrong, just to be clear I am also posting the code below:
const send_email = function (email, subject, source, payload) {
console.log(email, subject, source, payload);
let email_param = {
Destination: {
ToAddresses: email
},
// ConfigurationSetName: 'XXXRANDOMTEXT_PLATFORM',
Message: {
Body: {
Html: {
Charset: "UTF-8",
Data: payload
}
// Text: {
// Charset: "UTF-8",
// Data: payload
// }
},
Subject: {
Charset: "UTF-8",
Data: subject
}
},
Source: source
};
let send_email = SES.sendEmail(email_param).promise();
send_email
.then(data => {
return true;
})
.catch(error => {
console.log('sending email error:', error);
return false
});
}
If your AWS account is still in the sandbox mode then you have to verify your sender, receiver etc. Go to the prod mod to have access to the full features.

Sending Emails using a Lambda Function, NodeJS, Mailgun, and testing Params in Postman

I am learning all of this as I go. The goal is to simply send an email using variables, and here's the code that I have so far in test.js:
const mailgunSdk = require('mailgun-js');
const apiKey = 'MAILGUN_API_KEY';
const domain = 'MAILGUN_DOMAIN';
const mailgun = mailgunSdk({
apiKey,
domain
});
exports.handler = async(event, context, callback) => {
//console.log(event.body)
//const data = JSON.parse(event.body)
let response
try {
/* Send email to recicipent */
response = await mailgun.messages().send({
from: 'Reginald Fromington <mg#fromaddress.com>',
to: 'bobloblaw#gmail.com',
subject: 'Hello',
text: event.messageText
})
} catch (e) {
//console.log('Err', e)
return {
statusCode: e.statusCode || 500,
//body: JSON.parse({
// error: e.message
//})
}
}
return {
statusCode: 200,
body: JSON.stringify({
result: response.message
})
}
}
Using Postman, I can actually get a message in my inbox if I have text: as a string, such as text: 'Thank you for your email' if I'm running the function without any params. However, if I want to use a variable, I have no idea how to pass them into the function. I've tried text: event.messageText, text: response.messageText, text: mailgun.messageText, and every possible combination of variables that I could imagine to pull from.
Most of the documentation that I could find is outdated or doesn't address this issue. I also don't really know how to google this issue because again, I'm new to all of this.
Thanks,
-Andrew
Attempting to pass parameters into Lambda Function

Invalid registration token provided. Make sure it matches the registration token the client app receives from registering with FCM

I got this code from my client iOS app on XCode console
Firebase registration token: diWY78iar8s:APA91bHJAzXe384OEYvfk4bKsyS1NQvteph7DwG7JRIMm_HuXg8EeNllVrsSi0v9W_Gh95ezbOStp3ZWuWl0AzFKxMaCOjN81yiz7A5qhkONrd7lP2CTkUbFErw28r3ONTLvo8c8sO7h
diWY78iar8s:APA91bHJAzXe384OEYvfk4bKsyS1NQvteph7DwG7JRIMm_HuXg8EeNllVrsSi0v9W_Gh95ezbOStp3ZWuWl0AzFKxMaCOjN81yiz7A5qhkONrd7lP2CTkUbFErw28r3ONTLvo8c8sO7h
NodeJS
console.log("START");
var FCM = require('fcm-node');
var serverKey = require('/Users/bheng/Desktop/Apps/APNS/node/mhn-app-firebase-adminsdk-bs45c-5ac3770488.json')
var fcm = new FCM(serverKey)
var collapseKey = 'new_message';
var message = {
to: 'diWY78iar8s:APA91bHJAzXe384OEYvfk4bKsyS1NQvteph7DwG7JRIMm_HuXg8EeNllVrsSi0v9W_Gh95ezbOStp3ZWuWl0AzFKxMaCOjN81yiz7A5qhkONrd7lP2CTkUbFErw28r3ONTLvo8c8sO7hdiWY78iar8s:APA91bHJAzXe384OEYvfk4bKsyS1NQvteph7DwG7JRIMm_HuXg8EeNllVrsSi0v9W_Gh95ezbOStp3ZWuWl0AzFKxMaCOjN81yiz7A5qhkONrd7lP2CTkUbFErw28r3ONTLvo8c8sO7h',
data: {
cpeMac: '000000000000',
type: 'malware'
},
notification: {
title: 'Hello baby',
body: 'Nice body',
tag: collapseKey,
icon: 'ic_notification',
color: '#18d821',
sound: 'default',
},
};
fcm.send(message, function(err, response){
if (err) {
console.log("Something has gone wrong!")
console.log(JSON.stringify(err));
} else {
console.log("Successfully sent with response: ", JSON.stringify(response))
}
})
console.log("END");
Result
When I run it
node app.js
I kept getting
START
END
Successfully sent with response: {"results":[{"error":{"code":"messaging/invalid-registration-token","message":"Invalid registration token provided. Make sure it matches the registration token the client app receives from registering with FCM."}}],"canonicalRegistrationTokenCount":0,"failureCount":1,"successCount":0,"multicastId":7577724855311354000}
How would one go about debugging this further?
your token has some additional random string such as
to: 'diWY78iar8s:APA91bHJAzXe384OEYvfk4bKsyS1NQvteph7DwG7JRIMm_HuXg8EeNllVrsSi0v9W_Gh95ezbOStp3ZWuWl0AzFKxMaCOjN81yiz7A5qhkONrd7lP2CTkUbFErw28r3ONTLvo8c8sO7hdiWY78iar8s:APA91bHJAzXe384OEYvfk4bKsyS1NQvteph7DwG7JRIMm_HuXg8EeNllVrsSi0v9W_Gh95ezbOStp3ZWuWl0AzFKxMaCOjN81yiz7A5qhkONrd7lP2CTkUbFErw28r3ONTLvo8c8sO7h',
just remove : diWY78iar8s: from your token string
console.log("START");
var FCM = require('fcm-node');
var serverKey = require('/Users/bheng/Desktop/Apps/APNS/node/mhn-app-firebase-adminsdk-bs45c-5ac3770488.json')
var fcm = new FCM(serverKey)
var collapseKey = 'new_message';
var message = {
to: 'APA91bHJAzXe384OEYvfk4bKsyS1NQvteph7DwG7JRIMm_HuXg8EeNllVrsSi0v9W_Gh95ezbOStp3ZWuWl0AzFKxMaCOjN81yiz7A5qhkONrd7lP2CTkUbFErw28r3ONTLvo8c8sO7hdiWY78iar8s:APA91bHJAzXe384OEYvfk4bKsyS1NQvteph7DwG7JRIMm_HuXg8EeNllVrsSi0v9W_Gh95ezbOStp3ZWuWl0AzFKxMaCOjN81yiz7A5qhkONrd7lP2CTkUbFErw28r3ONTLvo8c8sO7h',
data: {
cpeMac: '000000000000',
type: 'malware'
},
notification: {
title: 'Hello baby',
body: 'Nice body',
tag: collapseKey,
icon: 'ic_notification',
color: '#18d821',
sound: 'default',
},
};
fcm.send(message, function(err, response){
if (err) {
console.log("Something has gone wrong!")
console.log(JSON.stringify(err));
} else {
console.log("Successfully sent with response: ", JSON.stringify(response))
}
})
console.log("END");
Response from FCM :
Successfully sent with response: { results: [ { messageId: '0:1543448946734425%479ec0e2479ec0e2' } ],
canonicalRegistrationTokenCount: 0,
failureCount: 0,
successCount: 1,
multicastId: 6133765431734591000 }
One of the interesting reasons for invalid registration is: that device have a different token. Maybe you are trying to use a past token.
In my case what happened was I was getting the FCMRegistrationToken from my colleague via Discord and the Ctrl+C Ctrl+V was modifying the token. On obtaining the token via email solved the issue.

Resources