我正在尝试使用AWS Pinpoint将SMS消息发送到特定的电话号码。
这是到目前为止我在nodejs中所拥有的:
var AWS = require('aws-sdk');
AWS.config.update({region: 'us-east-1'});
var pinpoint = new AWS.Pinpoint({apiVersion: '2016-12-01'});
pinpoint.sendMessages(XXX);
我对输入XXX的内容感到非常困惑。 https://docs.aws.amazon.com/cli/latest/reference/pinpoint/send-messages.html输入很长。电话号码去哪儿了?一个简单的例子将不胜感激。
答案 0 :(得分:0)
这终于奏效了。 [电话]是电话号码,例如[15553451234]:
var AWS = require('aws-sdk');
// Set region
AWS.config.update({region: 'us-east-1'});
var pinpoint = new AWS.Pinpoint({apiVersion: '2016-12-01'});
var params = {
ApplicationId: 'ecba683ea3ee4af1bba3176a70ac1e71',
MessageRequest : {
Addresses : {
[telephone] : {
"BodyOverride": message,
"ChannelType": "SMS",
}
},
MessageConfiguration : {
SMSMessage:
{
Body : message,
MessageType : "TRANSACTIONAL"
}
}
}
};
var publishTextPromise = await pinpoint.sendMessages(params).promise();
答案 1 :(得分:0)
这是我们为处理答案所做的工作,存储在DynamoDB中:
const doc = require('dynamodb-doc');
const dynamo = new doc.DynamoDB();
exports.handler = async (event) => {
// TODO implement
console.log(JSON.stringify(event));
var pinpointResponse = JSON.parse(event.Records[0].Sns.Message);
var phoneNumber = pinpointResponse.originationNumber.substring(2);
var message = pinpointResponse.messageBody;
console.log("phoneNumber", phoneNumber);
console.log("message", message);
//Insert into DynamoDB
var InsertParams = {
TableName : "ChatHistory",
Item : {
"phoneNumber" : phoneNumber + "",
"Answer" : message
}
};
var AWSNew = require('aws-sdk');
AWSNew.config.update({region: 'us-east-2'});
var docClient = new AWSNew.DynamoDB.DocumentClient();
await docClient.put(InsertParams).promise();
const response = {
statusCode: 200,
body: JSON.stringify('SUCCESS'),
};
return response;
};