Created
August 28, 2011 22:38
-
-
Save saghul/1177331 to your computer and use it in GitHub Desktop.
Hello world Plivo example using Flask
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################ | |
# host/port binding for http server | |
HOST = '0.0.0.0' | |
PORT = 5000 | |
############################################ | |
from flask import Flask, render_template | |
import plivohelper | |
import os | |
response_server = Flask("ResponseServer") | |
response_server.debug = True | |
""" | |
This is a simple example which demonstrate how easy you can build a light HTTP | |
server using Flask which will return formatted XML to command the Plivo Server | |
By default the HTTP Server will be listening on http://127.0.0.1:5000 | |
The following URLs are implemented: | |
* /answered/ | |
* /hangup/ | |
""" | |
@response_server.route('/heartbeat/', methods=['POST']) | |
def heartbeat(): | |
return "OK" | |
@response_server.route('/hangup/', methods=['POST']) | |
def hangup(): | |
return "OK" | |
@response_server.route('/answered/', methods=['POST']) | |
def answered(): | |
r = plivohelper.Response() | |
r.addSpeak("Hello world") | |
print "RESTXML Response => %s" % r | |
return render_template('response_template.xml', response=r) | |
if __name__ == '__main__': | |
if not os.path.isfile("templates/response_template.xml"): | |
print "Error : Can't find the XML template : templates/response_template.xml" | |
else: | |
response_server.run(host=HOST, port=PORT) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment