0
votes

I would like to know if it's possible to use the user_name with Autopilot from the incoming post requests from Slack.

I've tried checking the documents but I'm not able to find any reference to handling incoming requests for Autopilot. Perhaps it isn't supported but does anyone know if it's possible?

2

2 Answers

0
votes

Twilio developer evangelist here.

The documentation for handling incoming requests is here: https://www.twilio.com/docs/autopilot/actions/autopilot-request.

You should receive a UserIdentifier with the request which identifies the user in the platform the request came from. In the case of incoming phone calls or sms messages the identifier is the user's phone number. I haven't tested, but I assume that this would either be a user name from Slack, or an identifier you can use with the Slack API to find the user name.

Let me know if that helps at all.

0
votes

I ended up being able to use the response data from Autopilot and found I was able to get the useridentifier from the json response as such:

user_name = request.form['UserIdentifier']

This has then allowed me to send direct messages via the incoming webhooks application in slack as using the above user name as the value for the channel key as follows.

payload={'text':"Ok, I'm working on it. I'll let you know when your request is ready.", "channel":user_name}
        webhook_url= 'https://hooks.slack.com/services/<slack id>/<slack id>'

        response = requests.post(
        webhook_url, data=json.dumps(payload),
        headers={'Content-Type': 'application/json'})

        if response.status_code != 200:
            raise ValueError(
                'Request to slack returned an error %s, the response is:\n%s'
                % (response.status_code, response.text)
            )