Session Ready
Exercise

Pending state transitions

You'll often need to briefly deviate from the flow of a conversation, for example to authenticate a user, before returning to the topic of discussion.

In these cases, it's often simpler - and easier to debug - if you save some actions/states as pending rather than adding ever more complicated rules.

Here, you're going to define a policy_rules dictionary, where the keys are tuples of the current state and the received intent, and the values are tuples of the next state, the bot's response, and a state for which to set a pending transition.

Instructions
100 XP
  • Complete the policy_rules dictionary by filling in the values:
    • A user starts in the INIT state.
    • If the user is in the INIT state and tries to place an order, you should ask for their number and create a pending transition to the AUTHED state.
    • This is the only policy rule which creates a pending transition, so the others simply have a pending state value of None.
  • The pending state has been added as the second argument of the send_message() function, which now returns the new state as well as the pending state. Call this send_message() function inside send_messages(), unpacking the output into the variables state and pending.
  • Hit 'Submit Answer' to send the messages to the bot!