|
| 1 | +# Required Libraries: twilio, flask |
| 2 | + |
| 3 | +from flask import Flask, request |
| 4 | +from twilio.twiml.messaging_response import MessagingResponse |
| 5 | + |
| 6 | +app = Flask(__name__) |
| 7 | + |
| 8 | +@app.route("/bot", methods=['POST']) |
| 9 | +def bot(): |
| 10 | + incoming_msg = request.values.get('Body', '').lower() |
| 11 | + resp = MessagingResponse() |
| 12 | + msg = resp.message() |
| 13 | + responded = False |
| 14 | + |
| 15 | + if 'hello' in incoming_msg: |
| 16 | + msg.body('Hello! How can I assist you today?') |
| 17 | + responded = True |
| 18 | + |
| 19 | + if 'help' in incoming_msg: |
| 20 | + msg.body('Sure, how can I help you?') |
| 21 | + responded = True |
| 22 | + |
| 23 | + if not responded: |
| 24 | + msg.body('Sorry, I didn\'t get that. Can you please clarify?') |
| 25 | + |
| 26 | + return str(resp) |
| 27 | + |
| 28 | +if __name__ == "__main__": |
| 29 | + app.run(debug=True) |
0 commit comments