[英]Single Outgoing Call + Conference Call
如何实现单呼出和电话会议?
我有拨出呼叫设置工作:一个 POST 请求到达/voice
端点并且呼叫通过,同样来电。 我已经阅读了会议代码示例,发现它到达了相同的/voice
端点。
我的逻辑是实现一个系统,该系统说明呼出呼叫是单次呼叫还是会议,然后在 if-else 语句中触发该选项。
伪代码,有点:
@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 应用程序上注册。
有没有更好/更好的方法来完成这项工作,或者我错过了什么?
进行出站呼叫时,您将 URL 提供到服务器上的/voice
端点。 如果您当时知道您正在进行单次通话或电话会议,则可以提供不同的 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'
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.