我关注了多个 YouTube 视频,试图创建一个 Twilio 队列,以下是我的代码,几乎与教程相同,但是呼叫队列在通知队列中用户的指定号码(通过 SMS)之前结束。我已经注释掉了 SMS 代码,并且队列应用程序运行良好。我提到的教程视频是 1 年前的。在调试时,我已经注释掉了一种识别我的帐户 SID 和令牌的可能方法。
from flask import Flask
from flask import request
from flask import url_for
from twilio import twiml
from twilio.rest import TwilioRestClient
import os
#from flask import render_template
# Declare and configure application
app = Flask(__name__) #, static_url_path='/static')
#app.config.from_pyfile('local_settings.py')
# Configure this number to a toll-free Twilio number to accept incoming calls.
@app.route('/caller', methods=['POST']) #'GET'
def caller():
response = twiml.Response()
response.say("Thank you for calling the call center.")
response.pause(length = "1")
response.say ("Please hold.")
response.enqueue("Queue", waitUrl='/wait')
return str(response)
# Configure waiting room to notify user of current position in the queue and
# play the sweet, soothing sounds of Twilio's coffeeshop collection.
@app.route('/wait', methods=['POST']) #'GET'
def wait():
response = twiml.Response()
response.pause(length = "1")
response.say("You are number %s in the queue." % request.form['QueuePosition'])
response.play("XXXXXXXXXXXXYYYYYYYYYYYZZZZZZZZZZZZZ")
##response.play("http://com.twilio.music.guitars.s3.amazonaws.com/" \
## "Pitx_-_Long_Winter.mp3")
#client = TwilioRestClient("XXXXXXYYYYYZZZZ","XXXXXXYYYYYYYZZZZ")
#client.sms.message.create(body="You have a customer waiting in your call center queue. Please call to help.", to="+XYYYYYZZZ", from_="+XXXXXYYYYZZZZ")
#message = client.messages
account_sid = "XXXXYYYYZZZ"
auth_token = "XXXXXYYYYYYZZZZ"
client = TwilioRestClient(account_sid, auth_token)
message = client.messages.create("You have a customer waiting in your call center queue. Please call to help.",
to="+XXXXYYYYZZZZ", # Replace with your phone number
from_="+XXXXXYYYYZZZZ") # Replace with your Twilio number
#response.redirect('/wait')
#print message.sid
return str(response)
# Connect to support queue - assign to Twilio number for agent to call.
@app.route('/agent', methods=['POST']) #'GET'
def agent():
response = twiml.Response()
with response.dial() as dial:
dial.queue("Queue")
return str(response)
# If PORT not specified by environment, assume development config.
if __name__ == '__main__':
port = int(os.environ.get("PORT", 5000))
#if port == 5000:
app.debug = True
app.run(host='0.0.0.0', port=port)