Menu

WebChat Actions

This guide is for Flex UI 1.x and channels that use Programmable Chat and Proxy. If you are using Flex UI 2.x or you are starting out, we recommend that you build with Flex Conversations.

What is the Actions Framework?

The Actions Framework allows you to implement programmatic changes in Flex WebChat UI that are triggered upon certain events. You can register events before or after an action fires, or replace the behavior of an action.

What can you do with the Actions Framework?

  • Replace native actions
  • Invoke actions from your custom components
  • Tap into before and after action events
  • Register your custom actions and use them in your custom components

Find out more about actions framework in Flex UI - Actions Framework

WebChat Actions

General

  • StartEngagement - payload: {formData?: any} - post form data to the startEngagement url to proceed to the in-engagement state.
  • RestartEngagement - remove the user from the chat channel and return them to a pre-engagement stage.
  • ToggleChatVisibility - toggle chat widget visibility between minimized and expanded view.
  • MinimizeChat - minimize chat widget

Chat:

These Actions need either channel or channelSid parameter.

  • SendMessage - payload: {channel?: ChannelState, channelSid?: string, body: string, messageAttributes?: any} - sends message with body to channel defined by ChannelState.
  • SetInputText - payload: {channel?: ChannelState, channelSid?: string, body: string} - sets message edit field to body in chat UI for channel ChannelState.
  • SendTyping - payload: {channel?: ChannelState, channelSid?: string} - sends typing indicator execution to other party in the channel.

Example of using an "after" Action event

Posting a message on behalf of the user into the chat, after the conversation was initiated, by tapping into StartEngagement post action event

FlexWebChat.Actions.on("afterStartEngagement", (payload) => {
  const { channelSid } = manager.store.getState().flex.session;
  manager.chatClient.getChannelBySid(channelSid)
    .then(channel => {
      channel.sendMessage("My awesome message");
    })
})

Rate this page:

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.

Thank you for your feedback!

Please select the reason(s) for your feedback. The additional information you provide helps us improve our documentation:

Sending your feedback...
🎉 Thank you for your feedback!
Something went wrong. Please try again.

Thanks for your feedback!

thanks-feedback-gif