Twilio 发送多条消息来唱数字 - python

时间:2021-05-10 07:57:26

标签: python twilio sms

我无法向一个号码发送多个回复。

收到 1 条回复,2 条消息。

"你好吗?我是来帮助你的。"

from flask import Flask, request, render_template
from twilio.twiml.messaging_response import MessagingResponse

app = Flask(__name__)


@app.route('/bot', methods=['POST'])
def bot():
    incoming_msg = request.values.get('Body', '').lower()
    resp = MessagingResponse()
    msg = resp.message()
    responded = False
    if 'Hi' in incoming_msg:
        response = "How are you?"
        msg.body(response)
        
        response2 = "I'm here to help you."
        msg.body(response2)

        responded = True

    if not responded:
        msg.body('BYE')

    return str(resp)

if __name__ == '__main__':
    app.run()

1 个答案:

答案 0 :(得分:0)

具有多个 <Body> 名词的 Twilio 消息将被连接,参见 documentation

<块引用>

您要发送的消息的文本。必须少于 1600 个字符。如果在单个 <Body> 中使用了多个 <Message> 元素,则这两个元素的内容将连接在一起成为一个 Body 值。

即使用 MessagingResponse 您只能发送一个单个回复。如果您真的想发送多个回复,您需要使用 client.messages.create(...) 创建第一个回复,然后通过您的 webhook 返回第二个回复。