1

I am trying to send a SMS message using AWS Pinpoint to a specific phone number. Here is what I have so far in 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);

I am very confused by what needs to go into XXX. https://docs.aws.amazon.com/cli/latest/reference/pinpoint/send-messages.html has a long input. Where does the phone number go? A simple example would be greatly appreciated.

Peter Chikov
  • 172
  • 3
  • 16

2 Answers2

4

This is what finally worked. [Telephone] is the number, for example [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();
Peter Chikov
  • 172
  • 3
  • 16
  • it looks like you have experience with aws pinpoint. Could you help look at the question I am linking below. Thanks. https://stackoverflow.com/questions/55226785/how-do-i-store-aws-pinpoint-messages-to-rds – Samuel Nde Mar 18 '19 at 22:44
  • @SamuelNde: Please look at the other answer I just added. I don't think it's good enough to put as a valid answer to your question but it might help you. – Peter Chikov Mar 19 '19 at 20:07
  • Got you man. I am using python (though I have a good understanding of java). Could you please post your answer as an answer to my question? Here is the question. https://stackoverflow.com/questions/55226785/how-do-i-store-aws-pinpoint-messages-to-rds – Samuel Nde Mar 19 '19 at 21:30
  • I have no experience with Python hence would have a hard time translating the code to python. – Peter Chikov Apr 04 '19 at 19:15
  • No problem @PeterChikov. Thanks for the follow up. – Samuel Nde Apr 04 '19 at 20:01
0

This is what we did to handle the answer, stores in 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;
};
Peter Chikov
  • 172
  • 3
  • 16
  • Thanks for your quick response man. Could you move the answer to my question https://stackoverflow.com/questions/55226785/how-do-i-store-aws-pinpoint-messages-to-rds. – Samuel Nde Mar 19 '19 at 21:33