2

我正在使用 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);

此部分告诉呼叫者他们在队列中的位置、播放等待音乐并发送 SMS 消息。它当前request.form['QueueSid']所在的位置是我想要放置队列的“友好名称”的位置 - 例如,“general”。

@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)

谢谢!

4

1 回答 1

2

事实证明,我需要使用 Twilioclient根据其 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)

希望这可以帮助某人.. :)

于 2013-03-26T22:01:11.673 回答