Skip to content

Commit

Permalink
Updates to concept-events-and-triggers.md
Browse files Browse the repository at this point in the history
  • Loading branch information
WashingtonKayaker committed Jan 14, 2020
1 parent 4fec79d commit be5a55a
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 48 deletions.
109 changes: 61 additions & 48 deletions docs/concept-events-and-triggers.md
Original file line number Diff line number Diff line change
@@ -1,81 +1,94 @@
# Events and triggers
In Bot Framework Composer, each dialog includes a set of triggers (event handlers) that contain instructions for how the bot will respond to inputs received when the dialog is active. When a bot receives a message, an event of the type `activityReceived` is fired. As the message is processed by the recognizer and passes through the dialog system, other events of different types are fired. If an event handler is found to handle an incoming event, that event is considered handled, and processing of further event handlers stops. If no event handler is found, the event will pass through the bot with no additional actions taken.
In the Bot Framework Composer, each [dialog](./concept-dialog.md) includes one or more event handlers called _triggers_. Each trigger contains one or more _actions_. Actions are the instructions that the bot will execute when the dialog receives any event that it has a trigger defined to handle. Once a given event is handled by a trigger, no further action is taken on that event. Some event handlers have a condition specified that must be met before it will handle the event and if that condition is not met, the event is passed to the next event handler. If an event is not handled in a child dialog, it gets passed up to its parent dialog to handle and this continues until it is either handled or reaches the bots main dialog. If no event handler is found, it will be ignored and no action will be taken.

On the navigation pane, click **New Trigger** and you will see the trigger menu in Composer as follows:
To see the trigger menu in Composer, select **New Trigger** in the navigation pane.

![trigger_menu](./media/dialog/trigger_menu.png)
![trigger_menu](./media/dialog/trigger_menu.gif)

## Anatomy of a trigger
The basic idea behind a trigger (event handler) is "When (_event_) happens, then do (_actions_)". The trigger is a conditional test on an incoming event, while the actions are one or more programmatic steps the bot will take to fulfill the user's request.
The basic idea behind a trigger (event handler) is "When (_event_) happens, do (_actions_)". The trigger is a conditional test on an incoming event, while the actions are one or more programmatic steps the bot will take to fulfill the user's request.

Every trigger contains the following components:
- A trigger name that can be changed in the property panel
- Possible **Condition** (specified using the [common expression language](https://github.com/microsoft/BotBuilder-Samples/tree/master/experimental/common-expression-language)), must evaluate to be "true" for the event to fire
- Actions defined to fire when the event is triggered
A trigger contains the following properties:

The screenshot below shows the definition of an **Intent** trigger that is configured to fire whenever the "cancel" intent is detected. It is possible to add a condition to the event - this expression which follows the [common expression language](https://github.com/microsoft/BotBuilder-Samples/tree/master/experimental/common-expression-language), if specified, must evaluate to be "true" for the event to fire.
| trigger property | Description |
| ---------------- | ------------------------------------------------------- |
| Name | The trigger name can be changed in the property panel. |
| Actions | The set of instructions that the bot will execute. |
| Condition | The condition can be created or updated in the property panel and is ignored if left blank, otherwise it must evaluate to _true_ for the event to fire. Conditions must follow the the [Common Language Expression](https://github.com/microsoft/BotBuilder-Samples/tree/master/experimental/common-expression-language) syntax. If the condition is ignored or evaluates to false, processing of the event continues with the next trigger. |

![anatomy_trigger](./media/events_triggers/anatomy_trigger.png)
This trigger is named _cancel_ and appears in the dialog flow as the first node under the _Events and triggers_ dialog in the navigation pane. Actions within a trigger occur in the context of the active dialog.

This event will appear in the dialog as a node at the top of the editor. Actions within this trigger occur in the context of the active dialog. These steps control the main functionality of a bot.
The screenshot below shows the properties of an **Intent recognized** trigger named cancel that is configured to fire whenever the "cancel" [intent](./concept-language-understanding.md#intents) is detected as shown in the properties panel. In this example the **Condition** field has been left blank, so no conditions are required in order to execute this trigger.

![cancel_trigger](./media/events_triggers/cancel_trigger.png)


## Types of triggers
There are different types of triggers. They all work in a similar manner, and in some cases, can be interchanged. This section will cover the different types of triggers and when should we use them. Read more to learn how to [define triggers](how-to-define-triggers.md).
There are different types of triggers that all work in a similar manner, and in some cases can be interchanged. This section will cover the different types of triggers and when you should use them. See the [define triggers](howto-defining-triggers.md) article for additional information.

### Intent triggers
Intent triggers work with recognizers. There are two intent triggers in Composer: **Intent recognized** and **Unknown intent**. After the first round of events is fired, the bot will pass the incoming message through the recognizer. If an intent is detected, it will be passed into the event handler with any **entity values** contained in the message. If no intent is detected by the recognizer, an **Unknown intent** event will fire, which handles intents not handled by a trigger.

You should use _intent triggers_ when you want to:
- Trigger major features of your bot using natural language.
- Recognize common interruptions like "help" or "cancel" and provide context-specific responses.
- Extract and use entity values as parameters to your dialog.

For additional information see how to define an [Intent recognized](how-to-define-triggers.md#intent-recognized) trigger or an [Unknown intent](how-to-define-triggers.md#unknown-intent) trigger in the article titled _How to define triggers_.

### Dialog events
The base type of triggers are dialog triggers. Almost all events start as dialog events which are related to the "lifecycle" of the dialog. Currently there are four different dialog triggers in Composer: **Dialog started (Begin dialog event)**, **Dialog cancelled (Cancel dialog event)**, **Error occurred(Error event)** and **Re-prompt for input(Reprompt dialog event)**. Most dialogs will include a trigger configured to respond to the `BeginDialog` event, which fires when the dialog begins and allows the bot to respond immediately.
The base type of triggers are dialog triggers. Almost all events start as dialog events which are related to the "lifecycle" of the dialog. Currently there are four different dialog triggers in Composer:

Use dialog triggers when you want to:
- Take actions immediately when the dialog starts, even before the recognizer is called
- Take actions when a "cancel" signal is detected
- Take automatic action on every message as it is received or sent
- Evaluate the raw content of the incoming activity
1. **Dialog started (Begin dialog event)**
2. **Dialog cancelled (Cancel dialog event)**
3. **Error occurred(Error event)**
4. **Re-prompt for input(Reprompt dialog event)**

See how to define dialog events [here](how-to-define-triggers.md#dialog-events).
Most dialogs include a trigger configured to respond to the `BeginDialog` event, which fires when the dialog begins. This allows the bot to respond immediately.

### Intent triggers
Intent triggers work with recognizers. There are two intent triggers in Composer: **Intent recognized** and **Unknown intent**. After the first round of events is fired, the bot will pass the incoming activity through the configured recognizer. If an intent is detected, it will be passed onto the matching handler along with any **entity values** the message contains. If an intent is not detected by the recognizer, any configured **Unknown intent** trigger will fire. This will only fire if no matching intent handler is found. **Unknown intent** handles any intent that is not handled by a trigger.
You should use _dialog triggers_ to:
- Take actions immediately when the dialog starts, even before the recognizer is called.
- Take actions when a "cancel" signal is detected.
- Take action on messages received or sent.
- Evaluate the content of the incoming activity.

Use intent triggers when you want to:
- Trigger major features of your bot using natural language
- Recognize common interruptions like "help" or "cancel" and provide context-specific responses
- Extract and use entity values as parameters to your dialog or a child dialog
For additional information on how to define dialog events, see the [dialog events](how-to-define-triggers.md#dialog-events) section of the article on how to define triggers.

See how to define an **Intent recognized** trigger [here](how-to-define-triggers.md#intent-recognized) and how to define an **Unknown intent** trigger [here](how-to-define-triggers.md#unknown-intent).

### Activities
Activity trigger is used to handle activities such as when a user joins and the bot begins a new conversation. **Greeting (ConversationUpdate activity)** is a trigger of this type and you can use it to send a greeting message. When you create a new bot, the **Greeting (ConversationUpdate activity)** trigger is initialized by default in the main dialog. This specialized option is provided to avoid handling an event with a complex condition attached. **Message events** is a type of Activity trigger to handle message activities.

Use **Activities** trigger when you want to:
- Take actions when a user begins a new conversation with the bot
- Take actions on receipt of an activity with type `EndOfConversation`
- Take actions on receipt of an activity with type `Event`
- Take actions on receipt of an activity with type `HandOff`
- Take actions on receipt of an activity with type `Invoke`
- Take actions on receipt of an activity with type `Typing`

Use **Message events** when you want to:
- Take actions when a message is updated (on receipt of an activity with type `MessageUpdate`)
- Take actions when a message is deleted (on receipt of an activity with type `MessageDelete`)
- Take actions when a message is reacted (on receipt of an activity with type `MessageReaction`).
Activity triggers are used to handle activities such as when a new user joins and the bot begins a new conversation. **Greeting (ConversationUpdate activity)** is a trigger of this type and you can use it to send a greeting message. When you create a new bot, the **Greeting (ConversationUpdate activity)** trigger is initialized by default in the main dialog. This specialized option is provided to avoid handling an event with a complex condition attached. **Message events** is a type of Activity trigger to handle message activities.

You should use **Activity triggers** when you want to:
- Take actions when a user begins a new conversation with the bot.
- Take actions on receipt of an activity with type `EndOfConversation`.
- Take actions on receipt of an activity with type `Event`.
- Take actions on receipt of an activity with type `HandOff`.
- Take actions on receipt of an activity with type `Invoke`.
- Take actions on receipt of an activity with type `Typing`.

For additional information, see [Activities](how-to-define-triggers.md#activities) trigger in the article titled _How to define triggers_.

See how to define an **Activities** trigger [here](how-to-define-triggers.md#activities).
### Message events
**Message event** triggers allow you to react to the different message events such as when a message is updated or deleted or when someone reacts to a message (for example, some of the common message reactions include a Like, Heart, Laugh, Surprised, Sad and Angry reactions).

You should use **Message events** when you want to:
- Take actions when a message is updated (on receipt of an activity with type `MessageUpdate`).
- Take actions when a message is deleted (on receipt of an activity with type `MessageDelete`).
- Take actions when a message is reacted (on receipt of an activity with type `MessageReaction`).

### Custom event
**Custom event** is a trigger to handle **Emit a custom event**. Bots can emit user-defined events using **Emit a custom event** which will fire this trigger. If you define an **Emit a custom event** and it fires, any **Custom event** in any level of dialogs will catch it and trigger corresponding actions.
You can create and fire (_emit_) your own events by creating an action associated with any trigger, then you can handle that custom event in any dialog in your bot by defining a **Custom event** event handler.

Use **Custom event** when you want to:
- handle a pre-defined **Emit a custom event**
Bots emit your user-defined events using **Emit a custom event**. If you define an **Emit a custom event** and it fires, any **Custom event** in any dialog will catch it and execute the corresponding actions.

See how to define a **Custom event** [here](how-to-define-triggers.md#custom-event).
For additional information, see [Custom event](how-to-define-triggers.md#custom-event) in the article titled _How to define triggers_.

## Further reading
- [Adaptive dialog: Recognizers, generators, triggers and inputs](https://github.com/microsoft/BotBuilder-Samples/blob/master/experimental/adaptive-dialog/docs/recognizers-rules-steps-reference.md#Rules)
- [Adaptive dialog: Recognizers, rules, steps and inputs](https://github.com/microsoft/BotBuilder-Samples/blob/master/experimental/adaptive-dialog/docs/recognizers-rules-steps-reference.md#Rules)
- [.lu format file](https://github.com/microsoft/botbuilder-tools/blob/master/packages/Ludown/docs/lu-file-format.md)
- [RegEx recognizer and LUIS recognizer](https://github.com/microsoft/BotBuilder-Samples/blob/master/experimental/adaptive-dialog/docs/recognizers-rules-steps-reference.md#regex-recognizer)

## Next
- Learn [conversation flow and memory](./concept-memory.md)
- Learn [how to define triggers](how-to-define-triggers.md)
- [conversation flow and memory](./concept-memory.md)
- [how to define triggers](how-to-define-triggers.md)

Binary file added docs/media/dialog/trigger_menu.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/media/events_triggers/anatomy_trigger.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/media/events_triggers/cancel_trigger.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit be5a55a

Please sign in to comment.