1

我正在尝试使用 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输入很长。电话号码去哪儿了?一个简单的例子将不胜感激。

4

2 回答 2

3

这就是最终奏效的方法。[电话] 是号码,例如 [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();
于 2018-12-03T16:18:02.653 回答
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;
};
于 2019-03-19T20:05:17.983 回答