0

I want to be able to send a text message to some number and then (upon receiving the text) basically just send a post request off to a different service after receiving the text. Does anyone know of a service I could use to set this up? Would like for it to be as fast as possible

JR3652
  • 435
  • 1
  • 4
  • 13
  • Could you please clarify your question? Are you asking how to send a POST request when _sending_ the text, or when _receiving_ a text? Feel free to edit your question to clarify what you are seeking. – John Rotenstein Dec 21 '19 at 03:26
  • my bad! send a post request off after receiving the message, just edited to clarify – JR3652 Dec 21 '19 at 03:44
  • Currently reading through [this](https://docs.aws.amazon.com/sns/latest/dg/sns-lambda-as-subscriber.html) which seems along the lines of what i'm looking for maybe – JR3652 Dec 21 '19 at 03:45
  • Sorry, but I'm still confused. Who/what is "receiving the text"? For example, if the message is sent to somebody's cell phone, are you wanting the cell phone to send a POST request? – John Rotenstein Dec 21 '19 at 03:49
  • Sorry no, I'm imagining the receiver to be some cloud service. So basically, it would be a cell phone would send a text message to a specified number and when that number receives a text message a corresponding post request to a different service would be sent off – JR3652 Dec 21 '19 at 03:59
  • Right now I'm thinking of something like aws pinpoint/sns set up that will receive a text message and then shoot off a request to some lambda service. I'm just not fully sure of how to get that pinpoint/sns to lambda connection configured – JR3652 Dec 21 '19 at 04:00

1 Answers1

1

Here's a summary of the steps to setup a sample app:

  1. Navigate to Amazon SNS Service → Topics
  2. Enter Name and create a new Topic
  3. For the newly created topic, create a subscription where the Protocol is AWS Lambda (see image1 below)
  4. Navigate to Amazon Pinpoint Service, create new Pinpoint application
  5. Enable SMS & voice feature for this Pinpoint application
  6. Get a new Long Code (long code price is $1/month)
  7. For the long code, Enable two-way SMS, select the Choose an existing SNS topic option and select the SNS topic created in Step 2 above (see image2 below)
  8. Finally, now you can send a message to that phone number from your phone and it will trigger your lambda function. In your lambda function, you can send a POST request to a different service or do whatever else. You can also respond back to the user's message - see example below.

Here's an example of how to send a message using Amazon Pinpoint in Java:

public void sendSMS(String pinpointPhoneNumber, String userPhoneNumber, String messageContent) {
    // define who the message is going to and via what platform
    Map<String, AddressConfiguration> addressMap = new HashMap<>();
    addressMap.put(userPhoneNumber, new AddressConfiguration().withChannelType(ChannelType.SMS));

    SMSMessage smsMessage = new SMSMessage();
    smsMessage.setOriginationNumber(pinpointPhoneNumber);
    smsMessage.setMessageType(MessageType.TRANSACTIONAL);
    smsMessage.setBody(messageContent);

    // add sms message to the direct message config
    // this can have many other types of messages
    DirectMessageConfiguration directMessageConfiguration = new DirectMessageConfiguration()
        .withSMSMessage(smsMessage);

    // put the phone numbers and all messages in here
    MessageRequest messageRequest = new MessageRequest()
        .withAddresses(addressMap)
        .withMessageConfiguration(directMessageConfiguration);

    // create send request
    SendMessagesRequest sendMessagesRequest = new SendMessagesRequest()
        .withApplicationId("put-pinpoint-app-id-here")
        .withMessageRequest(messageRequest);

    // send the message
    AmazonPinpoint pinpointClient = AmazonPinpointClientBuilder.standard().build();
    SendMessagesResult sendMessagesResult = pinpointClient.sendMessages(sendMessagesRequest);
    MessageResponse messageResponse = sendMessagesResult.getMessageResponse();
}

Creating SNS Topic Subscription to Lambda Function Two-way SMS config for Amazon Pinpoint

ᴛʜᴇᴘᴀᴛᴇʟ
  • 4,466
  • 5
  • 39
  • 73
  • I ended up using twilio following [this tutorial](https://www.twilio.com/docs/sms/tutorials/how-to-receive-and-reply-python-amazon-lambda), but this is a nice and thorough response. Thanks! – JR3652 Dec 21 '19 at 16:13