Two-Way SMS Using Amazon Pinpoint

Reading Time: 3 minutes

SMS is the simplest way to reach out to your users. Compared to other communication channels such as email and push notifications. SMS messaging is extremely convenient — users don’t need to authenticate, download the application, or go to the website. They simply receive your message on their device.

In this blog, I will explain what Two-Way SMS is, how we can easily implement using Amazon Pinpoint. Here is the Architecture diagram of the Two-Way SMS AWS infrastructure that we will use for setting up Two-Way Infrastructure.

Two-Way SMS

Overview

SMS are typically sent person-to-person, but they are also sent business-to-person. Businesses typically send text messages programmatically.

When a business sends a text message to a customer, it tends to be a one-way SMS.

Businesses can also send two-way messages to customers when they want to receive a response that provides them with actionable next steps. For example, in Pizza’s offer use case, the outbound message to the customer could include an option to respond “yes to ‘confirm’ “. The customer text response would come back to the Pizza app, and they can then take action based on the response.

Two-Way SMS

In this Two-Way SMS infrastructure, we will use the following aws resources:

  • Pinpoint (To send and receive SMS)
  • SNS (To Receive User Reply)
  • SQS (To get the User Reply from SNS Topic)

How 2 Way SMS will work?

We need to create an application written in java or any other language that sends sms through pinpoint and received a reply from SQS.

Our application sends SMS through pinpoint to the user’s mobile number. Once the user gets the SMS, he/she can reply to the same long or shortcode then pinpoint receive a reply and send to the SNS topic and SNS Topic writes that reply message to the AWS SQS Queue finally Our Application is polling for that SQS queue to get the replies from users, once the application gets the reply we can automatically respond to the user.

Setup Two-Way AWS Infrastructure using AWS Console

Create SQS Queue

  1. Open the Amazon SQS console at https://console.aws.amazon.com/sqs/.
  2. Choose Create queue.
  3. On the Create queue page, ensure that you set the correct region to us-east-1
  4. Enter a Name for your queue to two-way-sms
  5. Define an Access policy.
{
  "Version": "2012-10-17",
  "Id": "sqspolicy",
  "Statement": [
    {
      "Sid": "First",
      "Effect": "Allow",
      "Principal": "*",
      "Action": "sqs:SendMessage",
      "Resource": "arn:aws:sqs:us-east-1:ACCOUNT-ID:two-way-sms",
      "Condition": {
        "ArnEquals": {
          "aws:SourceArn": "arn:aws:sns:us-east-1:ACCOUNT_ID:two-way-sms"
        }
      }
    }
  ]
}
  1. Click on Create Queue

Create SNS Topic

  1. Open the Amazon SNS console at https://console.aws.amazon.com/sns/v3/home.
  2. On the Amazon SNS dashboard, under Common actions, choose Create Topic.
  3. In the Create new topic dialog box, for Topic name, enter a name for the topic two-way-sms
  4. Choose Create topic.
  5. Copy the Topic ARN for the next task.
  6. Click on Create topic

Subscribe to an SNS topic

  1. Open the Amazon SNS console at https://console.aws.amazon.com/sns/v3/home.
  2. In the navigation pane, choose Subscriptions, Create subscription.
  3. In the Create subscription dialog box
    1. For Topic ARN, enter the ARN of the topic.(paste the topic ARN that you created in the previous task)
    2. For Protocol, choose Amazon SQS.
    3. For Endpoint, enter the ARN of the queue. (arn:aws:sqs:us-east-1:ACCOUNT_ID:two-way-sms)
  4. Choose Create subscription.

Create Pinpoint Application

  1. Open the Amazon Pinpoint console at https://console.aws.amazon.com/pinpoint/
  2. On the All projects page, choose Create a project.
  3. For Project name, enter a name two-way-sms
  4. Choose Create.
  5. Under Project features, in the SMS and voice section, choose Configure.
  6. Choose Enable the SMS channel for this project.
  7. Choose Save changes.
  8. Click on settings and Choose SMS and voice
  9. Click Request Long Code
  10. Enter the Cuntry name to get the country long code
  11. Click ok, then a long code is created for you
  12. Click on the created long code under number settings
  13. Expand the Two-way SMS tab and choose Enable two-way SMS
  14. In the Incoming messages destination Choose an existing SNS topic
  15. Select the SNS topic that you have created in the previous step
  16. Click on Save

Now you save successfully setup the Two-Way SMS infrastructure on AWS, you just need to use the pinpoint SDK to send the sms and SQS SDK to receive the reply, and then you can play with the code when you get the reply.

References:

Thank you for sticking to the end. If you like this blog, please do show your appreciation by giving thumbs-ups and share this blog and give me suggestions on how I can improve my future posts to suit your needs. Follow me to get updates on different technologies.

For more blogs reach us at blog.knoldus.com

Written by 

Azmat Hasan is a Software Consultant at Knoldus Software LLP. He has done MCA from CDAC Noida in 2019. He has good knowledge of DevOps technologies i.e docker, Ansible, CI/CD(Jenkins, Bamboo), Kubernetes, Monitoring(Prometheus, Grafana), Logging(ELK Stack), etc. He is a self-motivated, enthusiastic person who believes in striving to achieve what we can sustain over a longer period of time, instead of working for short term benefits. He believe in working together to create synergy.

1 thought on “Two-Way SMS Using Amazon Pinpoint4 min read

Leave a Reply