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 is normally done using prompt triggers.

Prompt triggers are tested after the normal flow execution but 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 bots 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 that 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 Prompt flow

First, we'll start with adding a prompt flow, then we are going populate it:

  1. Go ahead and create a new prompt flow by selecting the dropdown menu located in the 'New' section of the ribbon and name it: Cookie hour campaign.
  2. Name the prompt trigger Cookie hour.
  3. Select the prompt trigger and add true to the expression field.
  4. Make sure the prompt trigger is set to repeatable - 'Once per session' (it will be chosen by default and can be changed in 'Advanced Options').

Prompt triggers are not tested against user inputs but instead against a programmatic script expression. In this case, we set the expression 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. 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 checks for prompt triggers which should be taken into account to add additional information to the response. In this case, Teneo finds 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 can see that the information about the ‘Cookie hour campaign’ isn't added to the response this time. This is because we selected ‘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)

Note that Java Locale Time uses UCT.

  1. Hit the 'Save' button.

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.

Test your flow

That's it! You can now go ahead test your flow. 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?