Make your bot pro-active

Sometimes we want our bot to give some extra information that the user did not explicitly request, such as special deals, promotions and more. In Teneo, this can be achieved using prompt triggers.

Prompt triggers are tested after the normal flow execution, right before the response is given. If a prompt trigger matches, the flow containing this trigger will be executed and the resulting output will be added to the response. In the example below, the first part of the bot answer comes from the 'User wants to order coffee' flow, while the second, highlighted, part comes from a flow that has a prompt trigger:

User: Could I get a large macchiato?
Bot: Ok, a large macchiato will be ready for pickup in 5 minutes.
It is cookie hour right now! You’ll get a free cookie to go along with your coffee.

On this page, we'll create a simple flow with a prompt trigger that will promote a free cookie for every coffee the customer buys. We are going to do this in two steps:

  1. We will create the flow with a prompt trigger that will always trigger and test it.
  2. Then we are going to further restrict the prompt trigger so it only works from 16:00 to 17:00 everyday and finally test it.

This is what the final flow will look like: Image of the final flow

Create a flow with a prompt trigger

Go ahead and create a new flow and name it: Cookie hour campaign.

Add the prompt trigger

First, we'll add and set up the prompt trigger, then we are going to remove the default trigger which was created with the flow:

  1. Click add 'prompt trigger' in the ribbon.
  2. Name the prompt trigger Cookie hour.
  3. Select the prompt trigger and add true to the its expression field.
  4. Make sure the prompt trigger is set to repeatable - 'Once per session' (it will be chosen by default)
  5. Remove the default trigger.

Note that prompt triggers are not tested against user inputs but instead against a programmatic condition. In the present case, we set this condition to 'true' so that the trigger will always fire.

Add an answer text

Select the output node and add the following answer text It is cookie hour right now! You’ll get a free cookie to go along with your coffee. Give the output node the name It is cookie hour and then save the flow.

Test the flow

Go ahead and test the prompt trigger in try out:

  1. Go to the Try out window
  2. Restart the session
  3. Type Hello there! in the Try out window

The answer text comes from two different flows. The first part of the answer with the greeting is given by a flow in the dialogue resources. However, before returning a response to the user, Teneo always evaluates if there are prompt triggers that should be taken into account to add additional information to the response. Here, this is the case for the prompt trigger of our ‘Cookie hour campaign’ flow and the output of that flow is appended to the answer.

As you may have noticed, if you now type Hello there again in the Try out window, you see that it will not add the information about the ‘Cookie hour campaign’ to the response this time. This is because we chose ‘Repeatable once per session’ when creating the prompt trigger.

Further restrict the prompt trigger

Currently, the expression of the 'Cookie hour' trigger is set to 'true'. This means that the 'Cookie hour' trigger will always trigger, once per session. In the following, we will make sure that the 'Cookie Hour' trigger only fires between the hours 16:00 and 17:00.

In order to make sure the flow triggers only between the hours 16:00 and 17:00, we have to do the following:

  1. Open the 'Cookie hour campaign' flow in edit mode.
  2. Select the prompt trigger
  3. Replace true with:
// get the hour of the day
def currentHour = java.time.LocalDateTime.now().getHour()

// is it cookie hour?
(currentHour == 16)

The prompt trigger will now only work between the hours 16:00 and 17:00

Just as regular triggers, prompt triggers are also ordered. Note however, that the ordering of regular and prompt triggers is managed separately in Teneo. Prompt triggers are always tested after regular triggers.

Save and test your flow

That's it! You can now go ahead and save your flow and test it. Remember, if the time is before 16:00 and after 17:00 it should not prompt you with It is cookie hour right now! You’ll get a free cookie to go along with your coffee.

Before 16:00 and after 17:00:

User: Could I get a large macchiato?
Bot: Ok, a large macchiato will be ready for pickup in 5 minutes.

During Cookie hours:

User: Could I get a large macchiato?
Bot: Ok, a large macchiato will be ready for pickup in 5 minutes.
It is cookie hour right now! You’ll get a free cookie to go along with your coffee.

In this example we use the server time, which is UTC (the results may thus vary depending on where you are).

Was this page helpful?