1 回答
TA贡献1836条经验 获得超5个赞
Twilio 开发人员布道者在这里。
如果您希望使用 Flask 和 ngrok 获取入站/传入呼叫的当前呼叫 SID,您可以在 Flask 中使用request.form['CallSid']如下所示request。
from twilio.twiml.voice_response import VoiceResponse
from flask import Flask, request
app = Flask(__name__)
@app.route("/voice", methods=['GET', 'POST'])
def voice():
resp = VoiceResponse()
# Read a message aloud to the caller
resp.say("hello world!", voice='alice') #example, I added this line and it's unneeded
call_sid = request.form['CallSid']
print(call_sid)
return str(resp)
如果您从 Twilio 客户端进行出站呼叫,您可以通过以下方式获取当前呼叫 SID:
from twilio.rest import Client
client = Client(YOUR-TWILIO_ACCOUNT_SID, YOUR-TWILIO_AUTH_TOKEN)
call = client.calls.create(
to= 'NUMBER-TO-CALL',
from_ = 'YOUR-TWILIO-NUMBER',
url = 'http://demo.twilio.com/docs/classic.mp3'
)
print(call.sid)
希望这可以帮助!
添加回答
举报