In this lesson, we will explore event management in Colang 2.0. Understanding how to handle events is crucial for creating responsive and dynamic conversational agents. We'll cover the event channel and how to create and match events to control the bot's behavior.
In Colang 2.0, the event channel is a central hub where all relevant events in the interactive system are communicated. This channel allows different components to read from and write to it, making it possible to coordinate complex interactions. Events that are important for modeling the interaction between the user and the bot are transmitted through this channel.
By leveraging the event channel, you can define interaction patterns that respond to specific events, enabling the bot to act appropriately based on user inputs and system states.
You can define and send events using the send
statement. This allows you to model actions or states in your flows.
For example, to send an event:
ButtonPressed
is the event type.counter=3
is a parameter for the event.as $ref
assigns the event to a variable for later reference.
While testing your flows, you can also manually trigger events by typing /EventName
or /EventName(params)
in the console. For example:
When you send an event (either in a flow or manually triggered), it is posted to the event channel, making it available for other flows to match and handle. This mechanism enables you to coordinate different parts of your bot’s logic and manage the flow of interaction based on the events you define.
To respond to specific events, use the match
statement to listen for and handle events from the event channel. For example, if you previously sent an event like:
You can match and handle this event as follows:
ButtonPressed
is the event type, matching the one sent.counter=3
ensures you are matching the event with the same parameter value.as $button_event_ref
assigns the matched event to a variable for later use.
A flow can be structured to handle these custom events in sequence:
This allows for precise control over the bot's behavior in response to your custom events, using consistent event names and parameters as those used in the send
statements.
Events in Colang 2.0 are named using PascalCase and often follow specific patterns:
- Action Initiation:
Start<ActionName>
- Action Commencement:
<ActionName>Started
- Action Completion:
<ActionName>Finished
For instance, the UtteranceBotAction
includes the following events:
StartUtteranceBotAction(script="Hello")
UtteranceBotActionStarted
UtteranceBotActionFinished(final_transcript="Hi")
Similarly, user actions like UtteranceUserAction
have corresponding events:
UtteranceUserActionStarted
UtteranceUserActionFinished(final_transcript="Hi")
You can match and handle these pre-defined events in your flows just like custom events. For example:
This listens for the completion of a bot utterance with a specific transcript.
Here’s an example that combines everything you’ve learned—creating, sending, and matching both custom and pre-defined events:
This flow listens for a custom user event, triggers a pre-defined bot action, waits for its completion, and then sends a custom event to mark the process as complete.
In this lesson, you learned how to manage events in Colang 2.0. You now know how to use the event channel and create and match both custom and built-in events to make your conversational agents more responsive and natural. These tools are essential for building advanced, interactive bots.
