Я пытаюсь создать бота, чтобы, когда кто-нибудь отправлял ему сообщение о типе пищи, бот отвечал адресом, в котором подают эту пищу. Однако я пытаюсь установить контекст, чтобы разговор мог проходить более тщательно.
Я попытался вложить оператор if, и он заставляет его отображать сообщение, но ему придется полагаться на оператор if, прежде чем он будет истинным, прежде чем проверять последующие.
from flask import Flask, request
from twilio.twiml.messaging_response import MessagingResponse
from intents import fallback_intent, getLocation
import random
app = Flask(__name__)
location_fallback = ['What kind of restaurant are you seeking?', 'What kind? Nearby, Cheap or The best?']
welcome = ['hello', 'what\'s up', 'hey','hi', 'what\'s happening?']
near = ['near', 'nearby']
cheap = ['cheap', 'good for my pockets']
good = ['good', 'top rated']
intro_resp = ['''Hey! Welcome to Crave! This interactive platform connects you to the top foodies in the world! We provide you with the best food places where ever you are. The instructions are simple:
1. Save our number in your Phone as Crave.
2. Text us and tell us what type of food you are craving!
This is from python''', '''
Welcome to Crave! Are you ready to get some food for today?
1. Save our number in your Phone as Crave.
2. Text us and tell us what type of food you are craving!
''']
@app.route('/sms', methods=['GET','POST'])
def sms():
num = request.form['From']
msg = request.form['Body'].lower()
resp = MessagingResponse()
#welcome intent
if any(word in msg for word in welcome):
if any(near_word in msg for near_word in near):
resp.message('These are the location of places near you!')
print(str(msg.split()))
return str(resp)
elif any(cheap_word in msg for cheap_word in cheap):
resp.message('These are the location of places that are low cost to you!')
return str(resp)
elif any(good_word in msg for good_word in good):
resp.message('These are the best places in town!')
return str(resp)
else:
location_fallback[random.randint(0,1)]
resp.message(intro_resp[random.randint(0, 1)])
print(str(msg.split()))
return str(resp)
else:
resp.message(fallback_intent())
print(str(msg))
return str(resp)
if __name__ == '__main__':
app.run(debug=True)
Я хочу, чтобы пользователь сказал «привет» или что-то, связанное с инициацией бота, затем я хочу, чтобы бот попросил пользователя спросить, какую пищу он хочет. Затем бот спросит, какие параметры для ресторана они хотели бы (т.е. закрыть, дешево или хорошо). Затем пользователь ответит соответствующим образом, а затем бот должен использовать эти параметры для поиска ближайшего ресторана с этими атрибутами.