即时检查 Twilio 客户端的 TwiMl 并将其从 <Start> 更改为 <Connect>

问题描述 投票:0回答:1

在我的 Twilio 控制台中,我有这个 Twiml 作为电话号码

<Response>  
      <Connect>
          <Stream url="wss://123-123-123.ngrok-free.app/ws"></Stream>
      </Connect>
</Response>

当有电话打入该号码时,我想检查特定参数,并据此将其更改为

Start
或反之亦然

<Response>  
      <Start>
          <Stream url="wss://123-123-123.ngrok-free.app/ws"></Stream>
      </Start>
</Response>

从我的想法来看,应该是这些步骤

  1. 现有的

    Response
    对象或 TwiML 配置是什么,以便我可以提取
    Stream Url

  2. 然后使用此代码使用适当的连接标签流更新 TwiMl

    等待 self.twilio_client.calls(self.call_sid).update_async( 方法=“POST”,twiml=response.to_xml() )

我的问题主要是关于第1点。另外,这个方法行得通吗?

twilio twilio-api twilio-twiml
1个回答
0
投票

我能够创建一个新的 webhook,它是一个 HTTP post 调用,该调用的响应是一个有条件的 VoiceResponse XML

这是示例代码

def call_handler(self, request: Request):
    response = VoiceResponse()
    stream = Stream(url=f"{request.host}")
    if condition == True:
        start = Start()
        start.append(stream)
        pause = Pause(length=10)
        response.append(start)
        response.append(pause)
    else:
        start = Connect()
        start.append(stream)
        response.append(start)

    return str(response), 200, "text/xml"
© www.soinside.com 2019 - 2024. All rights reserved.