我是twilio和flask的新手,我试图用下面的代码在twilio中进行外呼。
@
app.route("/", methods=['GET'])
def call():
account_sid = 'abcd'
auth_token = '123'
client = Client(account_sid, auth_token)
auth = ('1000', '1000pqr')
call = client.calls.create(
to='+919874561230',
from_='+14567891230',
url='http://demo.twilio.com/docs/voice.xml'
)
print(call.sid)
return jsonify({"success": 1, 'message': 'SSSSSS'})
if __name__ == "__main__":
app.run(debug=True, port=5005)
一切工作完美,但我想通过弹性sip中继进行呼叫,这意味着上面显示的呼叫方向为Outgoing API我想要Trunking Terminating。
要通过弹性SIP中继进行呼叫,您需要将client.calls.create()
方法中的from_
参数更新为您的SIP URI。
下面是一个如何更新代码以使用弹性SIP中继URI的示例:
@app.route("/", methods=['GET'])
def call():
account_sid = 'abcd'
auth_token = '123'
client = Client(account_sid, auth_token)
auth = ('1000', '1000pqr')
call = client.calls.create(
to='+919874561230',
from_='sip:your-sip-uri@your-twilio-trunking-domain',
url='http://demo.twilio.com/docs/voice.xml'
)
print(call.sid)
return jsonify({"success": 1, 'message': 'SSSSSS'})
if __name__ == "main":
app.run(debug=True, port=5005)
将your-sip-uri
和your-twilio-trunking-domain
替换为您的弹性SIP中继连接的SIP URI和Trunking Domain。此外,请确保您已在Twilio控制台中正确配置了SIP中继。