NightMICU
NightMICU

Reputation: 9230

Get the name of the queue a caller is in, Twilio

I am setting up a phone tree using Twilio and Python. I am trying to get the name of the queue that a caller is in to send along with a SMS alert to an agent. I have gathered that the name of the queue is a noun within the <Enqueue> verb but cannot find anything on how to get that name. The code..

This section responds to a <Gather> verb and assigns the caller to a queue based on what they entered.

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

This section tells the caller what their position is in the queue, plays hold music, and sends an SMS message. Where it currently has request.form['QueueSid'] is where I want to place the "friendly name" of the queue - for example, "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)

Thanks!

Upvotes: 2

Views: 668

Answers (1)

NightMICU
NightMICU

Reputation: 9230

It turns out that I needed to use the Twilio client to get details of the queue based on its SID. Those details include what I was looking for, friendly_name. Here is the updated code with the solution -

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

Hope this helps someone.. :)

Upvotes: 2

Related Questions