Level up your Twilio API skills in TwilioQuest, an educational game for Mac, Windows, and Linux. Download Now

Menu

Expand
Rate this page:

Thanks for rating this page!

We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

Actions

What is Actions Framework?

The Actions Framework allows you to implement programmatic changes in Flex 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 Actions Framework?

  • Replace native actions
  • Invoke actions from your custom components
  • Tap into pre and post 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 the chat widget between minimized and expanded view.
  • MinimizeChat - toggle the chat widget between minimized and expanded view.

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 "afterAction" 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 browsing the Twilio tag on Stack Overflow.