【发布时间】:2023-03-04 19:42:01
【问题描述】:
我对下面的代码/项目有以下问题。
-
Twilio:我应该使用什么作为语音/消息传递的 webhook URL?我目前都在使用 ngrok url,并且我都配置为 POST。这是正确的吗?还是应该是 GET?
-
我相信我需要在下面创建一个静态 ngrok url 并使其 https://
/voice -- 我需要获取付费版本使这个静态?
我相信在做了这两件事之后,应用程序应该可以工作,因为代码可以正常工作。
(另外,如果您有任何链接,以便我更好地了解这些应用程序以及它们的使用方式,那就太棒了。)
(电话和钥匙已编辑)
##API info for initiaiting the call
from twilio.rest import Client
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = '5dXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
client = Client(account_sid, auth_token)
call = client.calls.create(
url='https://your-ngrok-url.ngrok.io/voice',
to='+19511231234',
from_='+12311231234'
)
##this gathers user input from the caller
from flask import Flask
from twilio.twiml.voice_response import VoiceResponse, Gather
app = Flask(__name__)
@app.route("/voice", methods=['GET', 'POST'])
def voice():
# Start a TwiML response
resp = VoiceResponse()
gather = Gather(num_digits=1, action='/gather')
gather.say('Hello, this is Alice from your marketing company. I am calling to test the lines for an upcoming campaigm. Please press 1 as confimation of receipt of this test.')
resp.append(gather)
resp.redirect('/voice')
return str(resp)
@app.route('/gather', methods=['GET', 'POST'])
def gather():
"""Processes results from the <Gather> prompt in /voice"""
# Start TwiML response
resp = VoiceResponse()
# If Twilio's request to our app included already gathered digits,
# process them
if 'Digits' in request.values:
# Get which digit the caller chose
choice = request.values['Digits']
# <Say> a different message depending on the caller's choice
if choice == '1':
resp.say("Thank you, goodbye!")
return str(resp)
elif choice == '2':
resp.say("Sorry, I don't understand that choice. Please press 1")
return str(resp)
else:
# If the caller didn't choose 1 or 2, apologize and ask them again
resp.say("Sorry, I don't understand that choice. Please press 1.")
# If the user didn't choose 1 or 2 (or anything), send them back to /voice
resp.redirect('/voice')
return str(resp)
【问题讨论】: