How can an Agent Originate an SMS message in Amazon Connect !
July 1st, 2024

Pinpoint SMS

For some time now, you have been able to channel SMS messages through the Amazon Connect CHAT API, using Pinpoint services.  Typically, you would create a new project, enable SMS and then use SNS to trigger a lambda function to handle your SMS conversation.  Most recently, AWS has created Pinpoint SMS, a dashboard that enables you to directly integrate SMS services into your Amazon Connect instance, appearing like any other phone number.   This enables you to capture an SMS event directly to a contact flow eliminating the need to use SNS.

How to Originate an SMS in Amazon Connect?

Getting an inbound SMS message into the call center and routed to the next available agent in a specific queue has been a feature for some time.  As high lighed above, it is now even less complex as we can eliminate the use of SNS, enabling a contact flow to trigger the  lambda function that would handle the SMS session.   The real trick, however,  is how can an Agent originate an SMS message?   If an agent could originate an outbound SMS message, how would the return message be routed back to the agent who originally sent it? Origination Options? In this blog we will consider three different strategies that enable an Amazon Connect Agent the ability to ORIGINATE an outbound SMS message.  As noted above, responding to an inbound text message is well documented but originating an SMS message is a real challenge!  (Figuring out how to route the return message to the Agent that originated the message, is yet another challenge! )
  • Option 1 - User a TASK Template
  • Option 2 - Create an HTML Form
  • Option 3 - Create an Email to SMS solution
Each option is successively more complex to configure, each requiring additional AWS services including Lambda and ultimately DynamoDB tables.    Lets take these options one at a time and hopefully learn something as we attempt these different solutions and learn how to configure them.

Can an Agent Launch a Contact flow?

In order for an Agent to originate an SMS message, we needed to find away for an Agent to launch a Contact flow.   The contact flow can string together the steps we need to generate an outbound SMS.  We can turn on logging, trigger a lambda function, pass in the target phone number and message content and hand the message off to Pinpoint SMS for processing.   How can a agent launch a contact flow?  First we considered using a quick connect in which we could modify one of the default handlers to form the contact flow steps we required.  Unfortunately, with the exception of the External quick connect which had no call flow associated with it, the others required the Agent to have an active call before they could trigger the quick connect.  Drat! Foiled again!

Option 1 - Enter the TASK template!

We discovered that TASK templates might be a solution!  Creating a TASK template we found that we could add custom fields!  Yeah! So lets add a field for a phone number and one for message content! Also we might want to know which agent originated the message so we could route the return message back to that agent.   This started to feel like a real solution and but hen reality set in.  The good news was that you could assign the TASK to a contact flow!  This was very powerful, enabling the Agent to enter the phone and message and then send the TASK to the contact flow where we could invoke Lambda to handle the rest.   That is when the bad news surfaced!  There is no way to pass a custom field as a parameter that you could take advantage of in a "Set Contact Attribute" step.  Ah Snap! Digging through the documentation we did find that there are only three variables (at the time of this bog) that can be passed as contact attributes.  These are the TASKid, the Name of the Task and the Description of the TASK.  So to solve our problem, we had to play with words such that NAME would now = phoneNumber and Description would now =the  messageContent.   This worked remarkably well and has become our current solution for enabling Agents to originate an outbound SMS message. Click for Video on the DrVoIP channel! The advantage of this solution is that you do not need to write any code other than the Lambda handler that your contact flow will invoke to send the outbound SMS through Pinpoint.  The entire solution uses existing Amazon Connect resources: Tasks, Contact Flows and the CHAT API behind the scenes.  The downside is the user interface is not intuitive and agents need to remember which field it the real phoneNumber and messageContent field.  It is not a workable solution if you are concerned about routing a return message to the Agent that originated the message.  If those are not concerns, then this is an effective and easy solution to implement.

Option 2 - Use an HTML form

Given the challenges of launching a contact flow, it might be easier to create a pop up HTML form.  When the Agent wants to originate an SMS message, the click a link that presents an HTML form.  The form has a field for the phone number of the recipient,  the message content.  The form also has a field for the Agent ID, which we will discuss further in part 2.    To enable this configuration we need to string together several AWS services:
  • Pinpoint SMS, which we assume you already have setup and handling inbound SMS to your call center instance!
  • We need to build a static website to host our HTML form.   The website will be built in an S3 bucket, in the same region and account as the Amazon Connect instance.
  • The HTML form needs to POST the form contents to an API Gateway.
  • Lastly, the Gateway needs to launch a lambda function to process the  request and provide a hand off to Pinpoint 2 way SMS.

Option 3 - Create an Email to SMS solution

This is the most sophisticated of the three options, but is also the most powerful.  It also is the best solution for enabling a return message to be routed to the Agent that originated the message.   The configuration will require configuring a number of AWS services:
  • You will need access to your DNS records, or you will need to create a new domain in Route53, the AWS DNS service.
  • We will be creating a subdomain.  As our domain is our new subdomain will be SMS.DrVoIP.Com.
  • This subdomain will add a MX record in the appropriate DNS.   The MX record will point to an SMTP service, in this case using AWS Simple Email Services (SES).
  • SES will have an email receiving rule that will route any incoming email to this subdomain, to an SNS topic.
  • The SNS topic will trigger a Lambda function.
  • We need a Lambda function that will process the event and parse the recipient phone number, message content and the FROM field of the incoming email.  We will discuss the FROM field part 2 of this blog.

How to get the return message back to the originating Agent?

The next challenge was getting the return SMS message routed back to the Agent who originated the message to begin with.  As noted above, the CHAT stream does not provide a way of extracting attributes.   For example, lets assume your chat conversation asks the visitor (keyboard or SMS) what is the order number they are enquiring about?   You would like to extract that number from the conversation, assign it to a contact attribute so you could automate the retrieval of that information. Snap, in general, that is the limitation of using the CHAT API.

Routing a return SMS message to the Agent that originated the message, is a subject we will explore in Part 2 of this blog on Amazon Connect SMS channel management!