Recently I had to emit a Custom Event in Bot Framework Composer and extract data when the event fired.
Emitting the custom event is straight forward. You drag and drop the activity into the designer canvas and set some properties.
I couldn’t find the exact syntax though to extract the data being sent from the custom event however.
In this blog post, I show you how to:
- emit a custom event
- setup the trigger to listen for it
- extract the data
Dialog / Begin Dialog
Create a dialog called Custom Event. Add a send a response activity in the Begin Dialog event.
Set the text to a message that indicates we are in the dialog.
Add an Emit a custom event activity and set the following properties:
- Event name: my customEvent
- Event value: {“eventData”: “some data”}
- Bubble event: true
- Handled Property: turn.eventHandled
The canvas should look like this:
Custom Event Trigger
We add a new Custom Event Trigger to the dialog and set the name of the custom event to match the event name from the previous step (myCustomEvent):
Next, we add some activities to check we are in the custom event trigger and extract the data being sent to it.
myCustomEvent
We add an initial a response activity to let us know we’re in the custom event. A second is also included. The second send a response activity extracts the data from the event using the following syntax: ${turn.dialogEvent.value}:
Testing
We can test the chatbot using the Bot Framework Emulator. Here we can see relevant logging messages are display. We can also see the data is extracted from the custom event:
You can then use this data in any additional logic you might want your chatbot to run. For example, this might be a help menu or set of commands.
Leave a Reply