Pending actions II
Having defined your policy() function, it's now time to write a send_message() function which takes both a pending action and a message as its arguments and leverages the policy() function to determine the bot's response.
Your policy(intent) function from the previous exercise has been pre-loaded.
This exercise is part of the course
Building Chatbots in Python
Exercise instructions
- Define a function called
send_message()which takes in two arguments:pendingandmessage. - Pass in the interpretation of
messageas an argument topolicy()and unpack the result into the variablesactionandpending_action. - If the
actionis"do_pending"andpendingis notNone, print thependingresponse. Else, print theaction. - Inside the definition of the
send_messages()function, call yoursend_message()function withpendingandmsgas arguments. Then, hit 'Submit Answer' to send the messages and see the results.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Define send_message()
def ____(____, ____):
print("USER : {}".format(message))
____, ____ = ____
if ____ == "____" and pending is not None:
print("BOT : {}".format(____))
else:
print("BOT : {}".format(____))
return pending_action
# Define send_messages()
def send_messages(messages):
pending = None
for msg in messages:
pending = ____
# Send the messages
send_messages([
"I'd like to order some coffee",
"ok yes please"
])