1

I am creating a Twilio Autopilot program that works on the SMS channel. Currently, I set up the sms channel using the messaging URL and webhooks according to the instructions in the SMS setup section here: https://www.twilio.com/docs/autopilot/guides/how-to-build-a-chatbot. This works, but I am trying to find a way to retrieve the phone number from the incoming SMS to try and match it to a user to provide context to the bot ahead of time. Is there any way to accomplish this? I am coding this in Python but any advice would be appreciated regardless of language.

brrrrrrrrr
  • 13
  • 3

1 Answers1

0

The Autopilot webhook request is documented here and shows the parameters that are sent with each request.

In this case, you are looking for the UserIdentifier parameter in the incoming request, which, in the case of voice or SMS channels, will be the user's phone number.

Note that the request is made in the application/x-www-form-urlencoded format.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • Thanks for the response @philnash, I totally overlooked that. After grabbing the request data, I get it in the form of a MultiDict, where the nested dictionaries are just a string. Like this: {"key": "{key2: {key3 : val3}}", "key4": "val4"} where "{key2: {key3 : val3}}" is an entire string. Is there any way to convert this to a json, or parse it more easily? – brrrrrrrrr Jul 19 '22 at 15:25
  • 1
    The `Memory` parameter is sent as a JSON string, and you will need to parse that yourself. You can do so with the built in `json` module and `json.loads` method. – philnash Jul 19 '22 at 17:25