Teneo Developers

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:

prompt-flow-done

Create a Prompt flow

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

  1. Go to the Flows folder and add a new flow.
  2. Name the flow Cookie hour campaign.
  3. Next to the existing User Intent trigger, click on the Plus icon to add a new trigger. Select a Prompt trigger.
  4. Delete the original User Intent trigger.
  5. Name the prompt trigger Cookie hour.
  6. Add true to the expression field.

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 Tryout:

  1. Go to the Tryout window.
  2. Type Hello there! in the Tryout 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 Tryout window, you can see that the information about the ‘Cookie hour campaign’ isn't added to the response this time. This is because prompt triggers will only trigger once per session by default.

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.
  2. In the prompt trigger, replace true with:

groovy

1// get the hour of the day
2def currentHour = java.time.LocalDateTime.now().getHour()
3
4// is it cookie hour?
5(currentHour == 16)
6

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.

Note that prompt triggers are always tested after regular triggers in Teneo.

Test your flow

That's it! You can now go ahead test your flow. Remember, if the time is before 16:00 or 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 hour:

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 therefore vary depending on where you are).