1

我关注了多个 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)
4

1 回答 1

0

如果您参考了 1-2 年前的视频教程,请验证您的依赖项是最新的!我在 Heroku requirements.txt 文件中指定的 Twilio 依赖版本不是最新的,这个过时的依赖被确定为我最初查询的原因(我无法发送短信)。

可以通过以下方式指定某个依赖项的“大于”版本:

代替:

flask==0.9
twilio==3.1

考虑:

flask>=0.9
twilio>=3.1

因为>=语法将允许您拉取任何大于该 xx 依赖的版本。请注意,在某些情况下,您的项目可能需要特定的较旧(不是最新)依赖版本。

这可能会通过使用virtualenv

激活虚拟环境后声明依赖项将允许您虚拟隔离依赖项并创建项目特定的互斥依赖项。

于 2014-12-03T20:53:51.807 回答