使用 AWS Pinpoint 向特定 phone 号码发送短信
Sending a SMS message using AWS Pinpoint to a specific phone number
我正在尝试使用 AWS Pinpoint 向特定 phone 号码发送短信。
这是我到目前为止在 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 有一个长输入。 phone 号码去哪儿了?一个简单的例子将不胜感激。
这终于奏效了。 [电话]为号码,例如[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();
这就是我们处理答案的方式,存储在 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;
};
我正在尝试使用 AWS Pinpoint 向特定 phone 号码发送短信。
这是我到目前为止在 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 有一个长输入。 phone 号码去哪儿了?一个简单的例子将不胜感激。
这终于奏效了。 [电话]为号码,例如[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();
这就是我们处理答案的方式,存储在 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;
};