{"id":18067,"date":"2018-11-23T18:50:40","date_gmt":"2018-11-23T18:50:40","guid":{"rendered":"https:\/\/developer.kore.ai\/v8-1\/?post_type=docs&#038;p=15475"},"modified":"2022-01-31T11:21:44","modified_gmt":"2022-01-31T11:21:44","slug":"event-based-bot-actions","status":"publish","type":"post","link":"https:\/\/developer.kore.ai\/v8-1\/docs\/bots\/advanced-topics\/event-based-bot-actions\/","title":{"rendered":"Event Based Bot Actions"},"content":{"rendered":"<section class=\"l-section wpb_row height_auto\"><div class=\"l-section-h i-cf\"><div class=\"g-cols vc_row type_default valign_top\"><div class=\"vc_col-sm-12 wpb_column vc_column_container\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<p>Bot Events are triggered when specific actions occur during bot conversation or when specific events are triggered on bot channels.<\/p>\n<p>For example, when a user clicks the Get Started button to initiate a chat with your FB Messenger bot, it triggers the Facebook Welcome event. You can use this event to customize the welcome greeting such as personalizing it with the user\u2019s first and last names, capturing additional information from users, and updating back-end systems.<\/p>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h2><span class=\"ez-toc-section\" id=\"Bot_Behavior\">Bot Behavior<\/span><\/h2>\n<p>Developers can define bot behavior when an event is triggered using one of the following options:<\/p>\n<h4>Run a task<\/h4>\n<p>Select a Dialog task (Standard or Hidden ) to be invoked when the event triggers. Once the event is triggered, the dialog starts executing. If it is interrupted because of other intent detections, the Hold and Resume settings come into play. During execution, if the selected Dialog is not published in the bot, the event is discarded.<\/p>\n<p>In some cases, the Dialog may not be available to the user during a conversation for various reasons such as the task is not yet published or suspended or simply not assigned to the user. In such cases, the bot throws an error message that the task is not currently available for execution. Developers can preempt such situations by testing the bot in Debug mode. Debug Console shows full details about the error, including the reason for the non-availability of the task.<\/p>\n<h4>Run a script<\/h4>\n<p>Define a JavaScript to run when the event triggers. The script can make use of all applicable components such as session, context objects, bot variables, and bot functions. You can also fix the code using the Debug mode.<\/p>\n<h4>Show a message<\/h4>\n<p>Define a simple or advanced message to the user when the event triggers. It supports all messaging formatting features available in the Bots Platform, including multiple messages with channel override options.<\/p>\n<p>Multilingual bot behavior:<\/p>\n<ul>\n<li>You can define language-specific messages;<\/li>\n<li>If a message is deleted from an Event for a specific language then it will be removed from all other languages of the bot;<\/li>\n<li>If a message is added for a language then the message would be added in all other languages using the same content;<\/li>\n<li>If a message is modified in a language, then the modifications will be applied for that language alone.<\/li>\n<\/ul>\n<p><a href=\"\/v8-1\/docs\/bots\/advanced-topics\/sdks\/message-templates\/\">Learn more about message formatting and templates<\/a>.<\/p>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h2><span class=\"ez-toc-section\" id=\"Event_Types\">Event Types<\/span><\/h2>\n<p>You can configure the following events to trigger responses:<\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Event <\/b><\/td>\n<td><b>Trigger<\/b><\/td>\n<\/tr>\n<tr>\n<td>Welcome Event<\/td>\n<td>On receiving the first message from the user from any channel.<\/td>\n<\/tr>\n<tr>\n<td>Facebook Welcome Event<\/td>\n<td>On receiving Welcome Event from Facebook Messenger. This event takes precedence over Welcome Event if both are configured for a bot.<\/td>\n<\/tr>\n<tr>\n<td>Telephony Welcome Event<br \/>(Available post v8.0 release)<\/td>\n<td>\n<p>On receiving a user&#8217;s call from a voice channel like IVR, Twilio, or Audio Codes. <a href=\"#Twilio_Voice\">See below for details<\/a>.<\/p>\n<p>(previously called Twilio Voice Welcome Event)<\/td>\n<\/tr>\n<tr>\n<td>Telegram Welcome Event<\/td>\n<td>On receiving the Welcome Event from Telegram. This event takes precedence over Welcome Event if both are configured for a bot.<\/td>\n<\/tr>\n<tr>\n<td>On Connect<\/td>\n<td>Every time a user converses over Web \/ Mobile SDK channels. The event will be triggered irrespective of whether the user has started the conversation or not.<br \/>Note that this event applies ONLY for Web\/Mobile SDK channel and takes precedence over the Welcome event of both are configured.<\/td>\n<\/tr>\n<tr>\n<td>End of Conversation<br \/>(Available post v7.1 release)<\/td>\n<td>On reaching the end of conversation. <a href=\"#End_of_Conversation\">See below for details<\/a>.<\/td>\n<\/tr>\n<tr>\n<td>Task Execution Failure<br \/>(Available post v6.40 release)<\/td>\n<td>\n<p>On encountering an error in dialog task execution like:<\/p>\n<ul>\n<li>an error in the execution of the bot,<\/li>\n<li>service call failure,<\/li>\n<li>unable to reach the server<\/li>\n<li>error in invoking agent node in case of Human-agent transfer,<\/li>\n<li>Knowledge Graph Task failures,<\/li>\n<li>Webhook node failures,<\/li>\n<li>Dialog related to a sub-dialog node not available,<\/li>\n<li>exceptions in parsing the bot message.<\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr>\n<td>RCS Opt-in Event<br \/>(Available post v7.1 release)<\/td>\n<td>On receiving the message that a user has opted for the RCS Messaging channel.<\/td>\n<\/tr>\n<tr>\n<td>RCS Opt-out Event<br \/>(Available post v7.1 release)<\/td>\n<td>On receiving the message that a user has opted out of RCS Messaging channel.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h2><span class=\"ez-toc-section\" id=\"Configuration\">Configuration<\/span><\/h2>\n<p>Follow these steps to configure a bot event:<\/p>\n<ol>\n<li>On the bot main menu, from\u00a0<b>Natural Language<\/b> <b>&gt; Default Conversations <\/b>select\u00a0<strong>Event Handlers<\/strong>.<\/li>\n<li>On the Events page, select one of the events. The Event Configuration window slides open.<\/li>\n<li>Select one of these options to define how to proceed when the selected event is detected:\n<ul>\n<li><strong>Initiate Task<\/strong>,<\/li>\n<li><strong>Run Script<\/strong>,<\/li>\n<li><strong>Show Message<\/strong>.<\/li>\n<\/ul>\n<p><a ref=\"magnificPopup\" href=\"\/wp-content\/uploads\/sites\/18\/events.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-17280\" src=\"\/wp-content\/uploads\/sites\/18\/events.png\" alt=\"\" width=\"820\" height=\"461\" \/><\/a><\/li>\n<\/ol>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h2><span class=\"ez-toc-section\" id=\"Settings\">Settings<\/span><\/h2>\n<p>The settings option allows you to:<\/p>\n<ul>\n<li><strong>Manage Variable Namespaces<\/strong> (introduced in ver8.0) to associate the Variable Namespaces to be used with the Event Handler. This option will be visible only when the Variable Namespace is enabled for the bot. For more information, see <a href=\"\/v8-1\/docs\/bots\/bot-settings\/bot-management\/managing-namespace\/\" target=\"_blank\" rel=\"noopener noreferrer\">Managing Namespace<\/a>.<\/li>\n<\/ul>\n<p><a ref=\"magnificPopup\" href=\"https:\/\/s3-us-east-2.amazonaws.com\/kore-wordpress\/developer.kore.ai\/v8-1\/wp-content\/uploads\/sites\/18\/20201124101615\/VM_manageNamespaceEvent.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/s3-us-east-2.amazonaws.com\/kore-wordpress\/developer.kore.ai\/v8-1\/wp-content\/uploads\/sites\/18\/20201124101615\/VM_manageNamespaceEvent.png\" alt=\"\" width=\"1347\" height=\"271\" \/><\/a><\/p>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h2><span class=\"ez-toc-section\" id=\"Additional_Notes\">Additional Notes<\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"Task_Execution_Failure_Event\">Task Execution Failure Event<\/span><\/h3>\n<ul>\n<li>This event is available from the v6.40 release.<\/li>\n<li>By default, this event is always enabled with the Show Message option. This event cannot be disabled.<\/li>\n<li>This bot-level behavior can be overridden for specific tasks by defining task-specific failure event from the dialog task settings. <a href=\"\/v8-1\/docs\/bots\/bot-builder\/develop\/defining-bot-tasks\/using-the-dialog-builder-tool\/#dialog-settings\">Refer here for how<\/a>.<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Welcome_Event\">Welcome Event<\/span><\/h3>\n<p>Users can initiate bot conversations in varied ways, from a simple greeting to directly expressing an intent or asking an FAQ. To facilitate a scope for the developer to customize the bot response based on the user choice, the Welcome event comes with additional options when you choose Initiate Task or Show Message as the event configurations. For example, if the first user utterance maps to a bot task, should the bot execute the event-based task or the user intent first?<br \/>\nAs a developer, you can define the bot priority when the user starts the bot conversation with a greeting, task, or FAQ from the options listed below:<\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Event Configuration<\/b><\/td>\n<td><b>Options<\/b><\/td>\n<\/tr>\n<tr>\n<td>Initiate Task<\/td>\n<td>\n<ul>\n<li>Greetings \/ Small Talk\n<ul>\n<li>Respond to greetings or small talk and initiate Welcome Event dialog<\/li>\n<li>Discard user message and initiate Welcome Event dialog<\/li>\n<\/ul>\n<\/li>\n<li>FAQ\n<ul>\n<li>Respond to FAQ and initiate Welcome Event dialog<\/li>\n<li>Discard user message and initiate Welcome Event dialog<\/li>\n<\/ul>\n<\/li>\n<li>Task\n<ul>\n<li>Initiate user-requested task and discard Welcome Event dialog<\/li>\n<li>Initiate Welcome Event dialog and add the user-requested task to Follow-up Intents<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>If the Task is unavailable to the user for any reason such as the task is not yet published or suspended or simply not assigned to the user, in such cases, the bot throws an error message that the task is not currently available for execution.<\/td>\n<\/tr>\n<tr>\n<td>Show Message<\/td>\n<td>\n<ul>\n<li>Greetings \/ Small Talk\n<ul>\n<li>Respond to greetings or small talk and display Welcome Event message<\/li>\n<li>Respond to greetings or small talk and discard Welcome Event message<\/li>\n<\/ul>\n<\/li>\n<li>FAQ\n<ul>\n<li>Respond to FAQ and display Welcome Event message<\/li>\n<li>Respond to FAQ and discard Welcome Event message<\/li>\n<\/ul>\n<\/li>\n<li>Task\n<ul>\n<li>Display Welcome Event message and run the user-requested task<\/li>\n<li>Discard Welcome Event message and run the user-requested task<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"alert alert-info\"><b>Note: <\/b>The Bot Builder platform no longer supports Welcome Message. If you have defined a Welcome Message in previous versions of the platform, the upgraded version automatically creates a corresponding Welcome event and On Connect event to ensure backward compatibility.<\/div>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3><span class=\"ez-toc-section\" id=\"End_of_Conversation\">End of Conversation<\/span><\/h3>\n<p><span style=\"text-decoration: underline\">Note<\/span>: Introduced in ver7.1<\/p>\n<p>End of Conversation is triggered when the bot is not expected to send any message to the user or receive any message from the user.<\/p>\n<p>A new flag indicating the reason for ending the task, added to the <em>end of task<\/em> event, will help in deciding the end of the conversation behavior. Client-side implementations of BotKits, RTM, and Webhook channels can use this reason for task completion flag in the context, to determine an appropriate course of action.<\/p>\n<p>On triggering this event, the context will be updated with the following details:<\/p>\n<ul>\n<li>Reason for triggering event (see the table below)<\/li>\n<li>Name of the task that has just ended. If its a FAQ then the task name will be given set to \u2018FAQ\u2019<\/li>\n<\/ul>\n<table>\n<tbody>\n<tr>\n<td><b>Scenario<\/b><\/td>\n<td><b>End of Conversation Flag<\/b><\/td>\n<\/tr>\n<tr>\n<td>Reached the last node of the dialog<\/td>\n<td>Fulfilled<\/td>\n<\/tr>\n<tr>\n<td>The task is canceled by the user<\/td>\n<td>Canceled<\/td>\n<\/tr>\n<tr>\n<td>Error in task or FAQs execution (without Task Failure Event, no hold tasks)<\/td>\n<td>Failed<\/td>\n<\/tr>\n<tr>\n<td>Linked dialog completed without returning to the parent dialog<\/td>\n<td>Fulfilled_LinkedDialog<\/td>\n<\/tr>\n<tr>\n<td>On answering a FAQ<\/td>\n<td>Fulfilled<\/td>\n<\/tr>\n<tr>\n<td>Successful event execution with Run Script or Show Message (no tasks on hold)<\/td>\n<td>Fulfilled_Event<\/td>\n<\/tr>\n<tr>\n<td>Error in executing an event with Run Script or Show Message (no tasks on hold)<\/td>\n<td>Failed_Event<\/td>\n<\/tr>\n<tr>\n<td>User declines to resume on-hold task (when no other task is on hold<\/td>\n<td>Canceled<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>IVR Impact<\/strong><\/p>\n<p>You may also use this event to define how and when the calls should be terminated for voice-based channels. The IVR implementation has been enhanced to enable the closure of the session\/call only when the \u2018end of conversation\u2019 is completed. <a href=\"\/v8-1\/docs\/bots\/advanced-topics\/ivr-integration\/ivr-integration\/#Bot_Settings\" target=\"_blank\" rel=\"noopener noreferrer\">See here for how<\/a>.<\/p>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3><span class=\"ez-toc-section\" id=\"Telephony_Welcome_Event\">Telephony Welcome Event<\/span><\/h3>\n<p><span style=\"text-decoration: underline\">Note<\/span>: Introduced in ver8.0<br \/>\nReplaces Twilio Voice Welcome Event.<\/p>\n<p>This event is triggered upon receiving the voice call to the platform from any voice channel. This event will be triggered every time a user\u2019s call reaches the platform, and not just for the first time.<\/p>\n<p>It has two options &#8211; \u2018<em>Run a Dialog<\/em>\u2019 and \u2018<em>Voice Call Properties<\/em>\u2019.<\/p>\n<ul>\n<li>Run a Dialog &#8211; Select a task to be triggered from the drop-down list provided<\/li>\n<li>Voice Call Properties can be set as follows:\n<ul>\n<li>Define at least one \u2018Initial Prompts\u2019<\/li>\n<li>Prompts for Timeout, and No Match can be defined<\/li>\n<li>Under Advanced Controls, settings for Timeout, No. of Retries, and Barge-in can be defined.<br \/>\n<a href=\"\/v8-1\/docs\/bots\/bot-builder-tool\/dialog-task\/voice-call-properties\/\" target=\"_blank\" rel=\"noopener noreferrer\">See here for details<\/a>.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div><\/div><\/div><\/div><\/div><\/div><\/section>\n","protected":false},"excerpt":{"rendered":"Bot Events are triggered when specific actions occur during bot conversation or when specific events are triggered on bot channels. For example, when a user clicks the Get Started button to initiate a chat with your FB Messenger bot, it triggers the Facebook Welcome event. You can use this event to customize the welcome greeting...","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"class_list":["post-18067","post","type-post","status-publish","format-standard","hentry","category-advanced-topics"],"_links":{"self":[{"href":"https:\/\/developer.kore.ai\/v8-1\/wp-json\/wp\/v2\/posts\/18067","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/developer.kore.ai\/v8-1\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/developer.kore.ai\/v8-1\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/developer.kore.ai\/v8-1\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/developer.kore.ai\/v8-1\/wp-json\/wp\/v2\/comments?post=18067"}],"version-history":[{"count":19,"href":"https:\/\/developer.kore.ai\/v8-1\/wp-json\/wp\/v2\/posts\/18067\/revisions"}],"predecessor-version":[{"id":29803,"href":"https:\/\/developer.kore.ai\/v8-1\/wp-json\/wp\/v2\/posts\/18067\/revisions\/29803"}],"wp:attachment":[{"href":"https:\/\/developer.kore.ai\/v8-1\/wp-json\/wp\/v2\/media?parent=18067"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/developer.kore.ai\/v8-1\/wp-json\/wp\/v2\/categories?post=18067"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/developer.kore.ai\/v8-1\/wp-json\/wp\/v2\/tags?post=18067"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}