2013-03-26 61 views
1

我使用Twilio和Python設置電話樹。我正在嘗試獲取調用者發送的隊列的名稱以及SMS警報給代理。我已經收集到,隊列的名稱是<Enqueue>動詞中的一個名詞,但找不到有關如何獲取該名稱的任何內容。代碼..獲取調用者所在隊列的名稱,Twilio

本節迴應<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']的地方是我想放置隊列的「友好名稱」的地方 - 例如「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) 

謝謝!

回答

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) 

希望這可以幫助別人.. :)