Twilio 대기열을 만들려고 여러 YouTube 동영상을 따라 왔지만 다음은 자습서와 거의 동일한 코드입니다.하지만 대기열은 지정된 대기열에 알려지기 전에 종료됩니다. 대기열에있는 사용자의 번호 (SMS를 통해). SMS 코드를 주석 처리했으며 대기열 응용 프로그램이 정상적으로 작동했습니다. 제가 언급 한 튜토리얼 동영상은 1 년 전에 작성되었습니다. 디버깅 할 때 내 계정 SID와 토큰을 식별 할 수있는 방법을 설명했습니다.twilio 대기열 : SMS 메시지에서 파이썬 코드 종료
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)