0
votes
import os

from flask import Flask
from flask import request
from flask import url_for
from flask import render_template 
from twilio.rest import TwilioRestClient


from twilio import twiml

Declare and configure application

app = Flask(__name__, static_url_path='/static')

ACCOUNT_SID = "AACxxxxx" 
AUTH_TOKEN = "xxxxxx"

client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)

Configure this number to a toll-free Twilio number to accept incoming calls.

@app.route('/caller', methods=['GET', 'POST'])
def caller():
    response = twiml.Response()
    response.say("Thank you for calling" \
            "Please hold.")
    response.enqueue("Queue Demo", 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=['GET', 'POST'])
def wait():
    response = twiml.Response()
    twilio_client.sms.messages.create(
    to="+44xxxxxxxxxx", 
    from_="+44xxxxxxxxxx", 
    body="Hey Jenny! Good luck on the bar exam!", 
)

    response.say("You are number %s in line." % request.form['QueuePosition'])
    response.play("https://s3-us-west-2.amazonaws.com/" \
            "twilio/music1.mp3")
    response.redirect('/wait')
    return str(response)

Connect to support queue - assign to Twilio number for agent to call.

@app.route('/agent', methods=['GET', 'POST'])
def agent():
    response = twiml.Response()
    with response.dial() as dial:
        dial.queue("Queue Demo")
    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 = False
    app.run(host='0.0.0.0', port=port)

Why does it not send the sms?

1

1 Answers

0
votes

Ok I resolved it, so if you are using python on twilio, this is the code to have your phone system that answers the call, puts the caller on hold playing music and then sends you an sms then you can call the number to help the caller.

Here it is:

import os

from flask import Flask
from flask import request
from flask import url_for
from flask import render_template 
from twilio.rest import TwilioRestClient

from twilio import twiml

Declare and configure application

app = Flask(__name__, static_url_path='/static')

Configure this number to accept incoming calls.

@app.route('/caller', methods=['GET', 'POST'])
def caller():
    response = twiml.Response()
    response.say("Thank you for calling " \
            "Please hold.")
    response.enqueue("Queue Demo", waitUrl='/wait')

    return str(response)

Configure the waiting room to notify the user of their current position in the queue and play the holding music or marketing message.

@app.route('/wait', methods=['GET', 'POST'])

    def wait():
        response = twiml.Response() 
        response.say("You are number %s in line." % request.form['QueuePosition'])
        response.play("https://s3-us-west-2.amazonaws.com/" \
                "triptorigatwilio/eventpremrigaholdmusic1.mp3")
        response.redirect('/wait')

Notify agent of call via SMS

client = TwilioRestClient("your account sid...AC...", "your account auth token...xxxx")
client.sms.messages.create(
to="put number to send sms here", 
from_="put the twilio number to send sms from here", 
body="A caller is in the queue. Call now to help them.",  
)

return str(response)

Connect to support queue - assign to Twilio number for agent to call.

@app.route('/agent', methods=['GET', 'POST'])
def agent():
    response = twiml.Response()
    with response.dial() as dial:
        dial.queue("Queue Demo")
    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)

Don't forget to configure your active numbers in twilio. The number the caller calls should point to /caller and the number for the agent calls should point to /agent. Good luck...