Skip to main content

Chat Actions

Chat Actions allow you to define and perform custom actions within display cards received from bots. To receive the action event, add an event listener for the ZohoSalesIQ.chatEventChannel Stream using the listen method.

Usage:
In the below example, we register a new action using the registerChatAction API and add an event listener, if not done previously, to receive events when a new action is to be performed. Use the sendEvent() APIs to set the completion status for the action once it is triggered.

Note:
The action button will remain in a loading state until the sendEvent() API is invoked.​

Copied //Register an action
ZohoSalesIQ.registerChatAction("bookTicketAction");

//Add event listener
ZohoSalesIQ.chatEventChannel.listen((event) {
    switch (event["eventName"]) {
      case SIQEvent.performChatAction:
        Map action = event["chatAction"];
        String actionName = action["clientActionName"];
        String actionUUID = action["actionUUID"];
        if (actionName == "bookTicketAction") {
          if (isUserLoggedIn) {
            bookTicket();
            ZohoSalesIQ.sendEvent(SIQSendEvent.completeChatAction,
                  [actionUUID, true, "Tickets booked!"]);
          } else {
            ZohoSalesIQ.sendEvent(SIQSendEvent.completeChatAction,
                [actionUUID, false, "Please login to continue"]);
          }
        } else {
          // By default, the chat action will get timed out after 30 secs if the chat action is in a pending state.
          // Refer - https://www.zoho.com/salesiq/help/developer-guides/flutter-sdk-chat-action-setChatActionTimeout.html
        }
    }
});

Details of the action received within the event data contain the following information:

KeyDescription
nameValue corresponding to the "name" key used in bot script.
labelLabel content of the button.
clientActionNameName of the action with which it was registered.
elementIDElement ID of card.
actionUUIDUnique ID for the action.