-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
33 lines (24 loc) · 884 Bytes
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from flask import Flask, request
from twilio.twiml.messaging_response import MessagingResponse
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
import os
chatbot = ChatBot("Anticorruption",
read_only=True,
logic_adapters=['chatterbot.logic.BestMatch'],
database_uri=os.environ.get('DATABASE_URL'))
trainer = ListTrainer(chatbot)
for knowledge in os.listdir('base'):
BotMemory = open('base/' + knowledge, 'r').readlines()
trainer.train(BotMemory)
app = Flask(__name__)
@app.route("/", methods=["POST"])
def bot():
incoming_msg = request.values.get('Body', '').lower()
response = MessagingResponse()
msg = response.message()
bot_response = chatbot.get_response(incoming_msg)
msg.body(str(bot_response))
return str(response)
if __name__ == '__main__':
app.run()