简体   繁体   中英

Twilio unable to embed webhook into studio flow and have it send me message

I wrote a simple script to send a text to a user when the user sends a text first. When I link the phone number directly to webhook, it all works fine; but when I embed the webhook as a http request in studio flow, the function gets ran (I had debugging print statements that got ran) but the messages doesn't get sent to the user. Can anyone tell me why that is?

For reference, here is my code

 from flask import Flask, request from twilio.twiml.messaging_response import MessagingResponse from tags import get_relevant_tags app = Flask(__name__) @app.route('/sms', methods=['POST']) def sms_reply(): resp = MessagingResponse() resp.message("a") return str(resp) if __name__ == '__main__': app.run() 

Twilio developer evangelist here.

When you use an HTTP request as part of a Twilio Studio flow, the response is received by the flow itself, rather than being used to control the messages sent to the user.

If you don't need any outside input from whatever server is running that code, then I recommend replacing the HTTP request with a send message widget from Studio.

If you are doing some outside processing on your server that you need as part of the flow then I recommend you return the result as JSON with the message you want to send embedded. Something like:

from flask import Flask, request, jsonify

@app.route('/sms', methods=['POST'])
def sms_reply():
    message = get_awesome_message()
    return jsonify(message=message)

Then, within the Studio flow, once that request returns successfully, further widgets, includng a send message widget, can then use the results by calling on widgets.MY_WIDGET_NAME.parsed . Check out further detail on using the HTTP request widget in the documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM