Chat Actions

Chat Actions allows you to define custom actions that can be invoked when a user clicks on them inside the chat. 

Creating Custom Actions:
An action is created by providing a name and an implementation block. You can create an action by creating an instance of the SIQChatAction class.​

Example:
Let's create a custom action for booking tickets. Here, we check the login status of the user who performs the trigger action. A success message is shown if the user is logged in saying that the action is completed successfully. If not, an error message is shown indicating that the user has to login to continue.

let bookTicketAction = SIQChatAction(name: "bookTicketAction") { (arguments, handler) in
    // Your custom action code goes here
    // An example action being handled
    if userLoggedIn{ handler.success(message: "Ticket Booked!") }     else{ handler.faliure(message: "Please login to continue") } }

Note:

When an action is performed, an activity indicator is added to let the users know that the action is in progress. If an action is in progress, it is essential to call the success or the failure method on the handler to mark an action as completed. If not, the action will timeout after a set limit. The default timeout period is set to 30 seconds.

The arguments function parameter is an instance of SIQChatActionArguments class, its properties are listed below

typeclient_action
identifiername of the action defined in the bot script
elementIDelement ID of the message card
labellabel value of the action

The handler function parameter is an instance of the SIQChatActionHandler class and has the following methods.

success(message: String? = nil)
failure(message: String? = nil)

Providing a message while making the success or failure method call is optional.

Once an action is created, use the ChatAction.register API to register the created action in the SDK.