我正在使用Twilio和Python设置电话树。我正在尝试获取呼叫者所在队列的名称以及向代理发送SMS警报。我已经收集到队列的名称是<Enqueue>
动词中的名词,但是找不到关于如何获得该名称的任何内容。代码..
此部分响应<Gather>
动词,并根据用户输入的内容将呼叫者分配到队列。
@app.route('/open', methods=['POST'])
def open():
response = twiml.Response()
if request.form['Digits'] == "1":
response.enqueue("general", waitUrl="/wait")
elif request.form['Digits'] == "2":
response.enqueue("current", waitUrl="/wait")
return str(response);
此部分告诉来电者他们在队列中的位置,播放保持音乐以及发送短信。它目前在request.form['QueueSid']
的位置是我想放置的友好名称&#34;队列 - 例如,&#34; general。&#34;
@app.route('/wait', methods=['POST'])
def wait():
response = twiml.Response()
response.say("You are %s in the queue." % request.form['QueuePosition'])
response.play("http://com.twilio.music.classical.s3.amazonaws.com/BusyStrings.mp3")
account_sid = "*****"
auth_token = "*****"
client = TwilioRestClient(account_sid, auth_token)
client.sms.messages.create(to="+15555555555", from_="+15555555554", body="A caller is in the call queue - %(num)s in queue %(queue)s" % {"num": request.form['From'], "queue" : request.form['QueueSid']})
return str(response)
谢谢!
答案 0 :(得分:1)
事实证明,我需要使用Twilio client
根据其SID获取队列的详细信息。这些细节包括我在寻找的内容,friendly_name
。以下是解决方案的更新代码 -
@app.route('/wait', methods=['POST'])
def wait():
response = twiml.Response()
response.say("You are %s in the queue." % request.form['QueuePosition'])
response.play("http://com.twilio.music.classical.s3.amazonaws.com/BusyStrings.mp3")
account_sid = "*****"
auth_token = "*****"
client = TwilioRestClient(account_sid, auth_token)
queue = client.queues.get(request.form['QueueSid']) #Get the queue based on SID
friendlyName = queue.friendly_name; #Obtain the queue's Friendly Name
client.sms.messages.create(to="+15555555555", from_="+15555555554", body="A caller is in the call queue - %(num)s in queue %(queue)s" % {"num": request.form['From'], "queue" : friendlyName}) #SMS with caller ID and queue's friendly name
return str(response)
希望这有助于某人...... :)