问题描述
我正在尝试按照以下链接创建一个Python chatbot。由于某种原因,每当我将其连接到启用了SMS的twilio号码时。它无法回答问题。理想情况下,我可以向它发送问题。如果它包含在两个词典之一中找到的单词,则从第三个词典发送答案。请指教。谢谢!
https://www.twilio.com/blog/build-a-sms-chatbot-with-python-flask-and-twilio
# Import Modules Here:
import time
import requests
from flask import Flask,request
from twilio.twiml.messaging_response import MessagingResponse
# Import Dictonaries:
from Answer import * # Contains AnswerDict which is a dictionary of answers
from WordDict import * # Contains WordDictOne and WordDictTwo
# Flask Script:
app = Flask(__name__)
@app.route('/bot',methods=['POST'])
def bot():
incoming_msg = request.values.get('Body','').lower()
resp = MessagingResponse()
msg = resp.message()
responded = False
###################################################################################
msg.body("Hi there! \n Welcome to chatbot 2.0")
msg.body("What is your name? ")
# Waits for 3 seconds for user to respond...
time.wait(3)
msg.body("What is your Zip Code?")
# @Ibrahiim
# Database must be able to collect response to the above question and categorise keyword count based on this.
# Only the first 3 digits are relevent for out purposes
msg.body("What would you like to kNow? ")
for keyword in WordDictOne:
if keyword in incoming_msg:
msg.body(AnswerDict["climateChange"])
responded=True
for keyword in WordDictTwo:
if keyword in incoming_msg:
msg.body(AnswerDict["StudentLoans"])
responded = True
if not responded:
msg.body("Sorry,I didn't understand that!")
return str(resp)
if __name__ == "__main__":
app.run()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)