Reputation: 580
I am writing a simple program to send SMS using SNS service using the Javascript client.
var AWS = require('aws-sdk');
var sns = new AWS.SNS({
region : 'ap-southeast-1',
accessKeyId: '',
secretAccessKey: ''
});
sns.publish({
Message : "Test message",
PhoneNumber : "Test number"
}, function (err, data) {
if(err) {
console.log("Error - " + err);
}
else {
console.log('Success - ');
console.log(data);
}
});
I get a success and the data looks like
{ ResponseMetadata: { RequestId: '3b4e8c82-976c-55da-b1fa-dcd9ddc7254d' },
MessageId: '47a38cbe-2047-5056-a615-dce56aecc0c1' }
However, the SMS does not get delivered.
What could be the problem?
Upvotes: 8
Views: 10539
Reputation: 71
I had a similar issue using SNS SMS where I was receiving the message_id back from AWS but not getting the delivered text message.
I solved the issue after checking that the region in my api call was set to the same region as my origination number.
Hopefully saving someone else from the same headache.
Upvotes: 1
Reputation: 211
Setting up MessageAttributes for SMSTypes works for me.
{'AWS.SNS.SMS.SMSType': {'DataType': 'String', 'StringValue': 'Promotional'}}
for MessageAttributes in publish function. Your publish function will look like
client.publish(PhoneNumber="YOUR_NUMBER",Message="YOUR_MESSAGE",MessageAttributes={'AWS.SNS.SMS.SMSType': {'DataType': 'String', 'StringValue': 'Transactional'}})
By default, SMSType will be Promotional because of this message won't go on DND numbers.
Reference: here
Upvotes: 3
Reputation: 580
The messages started getting delivered after 24th for fresh requests. The metrics dashboard is showing the data a day stale. On the dashboard It correctly showed that all the SMS deliveries had failed on 21st September, inspite of a positive response from API. This is making me reconsider my decision of using SNS for SMS.
Thanks all who helped.
Upvotes: 5
Reputation: 4993
We need to specify more SNS parameters.
Documentation pages that might help:
try this code
var AWS = require('aws-sdk');
var sns = new AWS.SNS({
region: 'ap-southeast-1',
accessKeyId: '',
secretAccessKey: ''
});
var params = {
Message: 'Test message',
MessageStructure: 'string',
PhoneNumber: 'Test number'
};
sns.publish(params, function (err, data) {
if (err) console.log("error-> " + err + "-" + number + "-" + JSON.stringify(params)); // an error occurred
else console.log("SMS to " + number + " successfull " + JSON.stringify(data)); // successful response
});
You got output like this
{"ResponseMetadata":"RequestId":"2bb91f08-3ef0-5e55-8219-4645645"},"MessageId":"943a1224-042c-576c-936e-sfsdf34535"} {"Message":"hai manaf...r u happy","MessageStructure":"string","PhoneNumber":"+9197********"}.
But i don't get SMS to my DND activated phone number. i still research this issue.
Upvotes: -1