Creating the Flask chatbot service
A webhook is an automated message, sent from apps. The Flask framework helps us to easily define webhooks.
Flask framework can be used to create a basic skeleton webhook as follows:
from flask import Flask
app = Flask(__name__)
@app.route('/bot’, methods=['POST'])
def bot():
# add webhook logic here and return a response
if __name__ == '__main__':
app.run()
The code above creates an application that defines the /bot endpoint which listens to POST requests.
Each incoming message from Twilio will invoke this endpoint.
Quick resources on Flask:
If you are not familiar with Flask, its documentation has a quick start section that should bring you up to speed quickly. If you want a more in-depth learning resource then I recommend you follow this tutorial: Flask Mega-Tutorial.
If you have successfully followed through, we are all set for building a chatbot!
5
