Let's walk through creating your first application, Hello Monkey. We'll use Python to construct this example, but almost any web development language could be used.
Now, open a file called
run.py and add the following lines:
from flask import Flask from twilio.twiml.voice_response import VoiceResponse app = Flask(__name__) @app.route("/", methods=['GET', 'POST']) def hello_monkey(): """Respond to incoming requests.""" resp = VoiceResponse() resp.say("Hello Monkey") return str(resp) if __name__ == "__main__": app.run(debug=True)
Then run Flask in the terminal:
# If you are using virtualenv, you should run source bin/activate now to # activate your environment. $ python run.py * Running on http://127.0.0.1:5000/
You should be able to open a web browser to
http://localhost:5000. If you
view the page source code, you should see the following text:
<?xml version="1.0" encoding="UTF-8"?> <Response> <Say>Hello Monkey</Say> </Response>
Great! If Twilio reads this URL when someone calls your Twilio number, the caller will hear "Hello Monkey" played back to them. Now we need to get Twilio to request this URL when calls come in.
At this point in the tutorial, you will need to find a way to expose your server to the public Internet, so Twilio can find it.
Here are some tutorials that may be able to help you:
For the rest of the tutorial, we will assume your server is available at example.com.
Copy and paste the URL of your server into the "Voice" URL on the Numbers page of your Twilio Account. This way, Twilio will fetch instructions from that URL when people dial your Twilio number.
Now call your Twilio number! You should hear a voice say "Hello Monkey" in response. When you call, Twilio will fetch your URL, and execute the XML instructions listed above. Then Twilio will hang up, because there are no more instructions.