AWS Pinpoint/SNS: Two-way SMS unsubscribe/resubscribe implementation

1

I'm facing some issues while implementing Two-way SMS unsubscribe/resubscribe using AWS Pinpoint and SNS.

Use Case:
After collecting the user's number, he gets a confirmation SMS. He replies with the YES keyword to opt into the SMS list. He may later opt out by replying with the STOP keyword. After opting out, he still has the option to resubscribe by replying with the START keyword. Furthermore, even after resubscribing, he has an option to unsubscribe again by replying with the STOP keyword, and so on.

Current Implementation:
Similar to the example given in the documentation (https://docs.aws.amazon.com/pinpoint/latest/developerguide/tutorials-two-way-sms.html), I have a lambda function subscribed to the SNS topic which handles the YES and START keywords. Responses to STOP (and HELP) keyword(s) are handled by AWS Pinpoint.

  1. After collecting the user's number, the backend creates a pinpoint endpoint for the user's number, sends him the confirmation SMS, and updates the endpoint opt-out status to ALL.
  2. User replies with YES, his reply is handled by the lambda which updates the endpoint opt-out status to NONE.
  3. User replies with STOP, his reply is handled by pinpoint, which automatically opts him out.
  4. User replies with START, his reply is handled by the lambda which updates the endpoint opt-out status to NONE.

I need help with the following queries:

  1. In step 3 of the above implementation, I've noticed that the user's number gets added to the SNS opt-out list (as checked from AWS Console), but his pinpoint endpoint opt-out status (as checked from aws-cli) is still set to NONE instead of ALL. As expected, I am unable to send SMS to this user. Are there two separate opt-out statuses maintained for pinpoint and SNS as I've observed? If yes, is there in-depth documentation regarding how they get updated?
  2. In step 4 of the above implementation, I've noticed that the user's number does NOT get removed from the SNS opt-out list and his pinpoint endpoint opt-out status remains NONE. Unlike the expected behavior, I am still unable to send SMS to this user. Am I doing the resubscribe implementation correctly?

Please answer the queries and guide me on the correct implementation of my use-case.

asked 3 years ago1436 views
2 Answers
1
Accepted Answer

After further exploration, here's what I found-

Observations

  1. If not using pinpoint and the user's number is shown in the SNS opt-out list, messages sent via SNS publish message will not get delivered.
  2. Irrespective of whether using pinpoint or not, incoming SMS from the user always pass through SNS and are checked for the opt-out keywords like STOP, END, CANCEL, etc. (https://docs.aws.amazon.com/pinpoint/latest/userguide/channels-sms-manage.html). If an opt-out keyword is found, the number is always added to the SNS opt-out list. (Further reading- https://docs.aws.amazon.com/sns/latest/dg/sms_manage.html)
  3. If the 'Self-managed opt-outs' option for the pinpoint long code is disabled and the user's number is shown in the SNS opt-out list,
    3.1. A new pinpoint endpoint cannot be created for that number.
    3.2. Messages sent via existing pinpoint endpoint for that number will not get delivered.
    3.3. Messages sent via SNS publish message will not get delivered.
  4. If the 'Self-managed opt-outs' option for the pinpoint long code is enabled and the user's number is shown in the SNS opt-out list,
    4.1. The previous points 3.1. and 3.2. still hold true.
    4.2. Messages sent via SNS publish message will get delivered because of the enabled 'Self-managed opt-outs' despite the number being added to SNS opt-out list.

Cause of the problem
In my case 'Self-managed opt-outs' option was disabled, which is why pinpoint endpoint opt-out status was irrelevant and SNS opt-out list was taking precedence.

Solution

  1. As can be seen above, keeping 'Self-managed opt-outs' disabled did not satisfy my requirements. So I enabled it.
  2. Pinpoint endpoints could not be used because the SNS opt-out list would always take precedence.
  3. Finally, I'm just using pinpoint for getting the long code with two-way SMS and 'Self-managed opt-outs' enabled. I'm using SNS publish message to send the messages instead of the pinpoint endpoint.
  4. Now that I'm using 'Self-managed opt-outs', one important thing to note here is- I'm maintaining the opt-out status for each user's number on my backend and handling the outgoing message delivery allow/deny at the middleware level.
answered 3 years ago
0

Thank you.

answered 3 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions