如何实现一个单独的对外电话和电话会议?
我已经完成了向外呼叫的设置: POST请求到达/voice端点,呼叫通过,同样也是传入呼叫。我已经阅读了会议代码示例,并看到它到达了同一个/voice端点。
我的逻辑是实现一个系统,该系统声明传出呼叫是单个的还是会议的,然后在if- gets语句中触发该选项。
伪码,有点:
@app.route('/voice', methods=['POST'])
def voice():
option = flask.request.get_json()['option']
if option == 'single':
#outgoing_call code
else:
#conference_call code我的{{domain}}/voice在TWIML应用程序上注册。
是否有一个好/更好的方法来完成这件事,还是我遗漏了什么?
发布于 2022-06-12 04:34:48
在进行出站调用时,可以向服务器上的/voice端点提供URL。如果您知道您正在进行单个电话或电话会议,则可以提供不同的URL,以便在呼叫连接时执行不同的操作。例如:
from flask import Flask, Response
from twilio.twiml.voice_response import VoiceResponse, Dial
@app.route("/conference", methods=["POST"])
def conference():
response = VoiceResponse()
dial = Dial()
dial.conference("Conference")
response.append(dial)
return Response(str(response), mimetype="text/xml")
@app.route("/voice", methods=["POST"])
def single():
response = VoiceResponse()
dial = Dial()
dial.number("+123456789")
response.append(dial)
return Response(str(response), mimetype="text/xml") 然后,在创建调用时,根据您想要发生的情况使用不同的端点:
import os
from twilio.rest import Client
account_sid = os.environ['TWILIO_ACCOUNT_SID']
auth_token = os.environ['TWILIO_AUTH_TOKEN']
client = Client(account_sid, auth_token)
if (SINGLE_CALL_CONDITIONAL):
url = "https://example.com/voice
else:
url = "https://example.com/conference"
call = client.calls.create(
url=url,
to='+14155551212',
from_='+15017122661'
)https://stackoverflow.com/questions/72576120
复制相似问题