Message Actions

Apart from just sending messages, there are various other actions that you may want your users to be able to perform within the chat UI.

Configuring Actions and Permissions

You can configure which actions a user is able to take based on their role. For each action, you can choose on which messages users with this role can perform it.

  • None (this action is not available to users with this role)
  • Their own messages
  • All messages

Within the role editor, you can also define custom actions for each role. To do so, give it a name and a label, and click "add action". The label is used in the actions menu. The name is used to refer to this action within the JavaScript SDK. When the user selects a custom action, an event is triggered within the JavaScript SDK, that you can listen for, and use to run whatever code you want in response.

Handling Custom Message Actions

To do something in response to a user selecting a custom action, you need to listen for them using our JavaScript SDK. Use the onCustomMessageAction method on the Chatbox, Inbox or Popup to listen for custom message actions. For example, if you've defined an action named "report" for a user's role, you can handle it as follows:

chatbox.onCustomMessageAction('report', (event) => {
// Send the message to your backend here, so a moderator can review it.
console.log('Reported message with id:', event.message.id);
});

Troubleshooting

The Action Menu Does Not Show up

The message action menu is rendered as part of your theme. Our default theme comes with this menu already set up, but if you're using a legacy theme, or you customized a theme before this feature was released, then it doesn't contain the menu yet. To render the menu button, you'll need to add this tag to the UserMessage template of your theme:

<ActionMenu class="action-menu"><Icon type="horizontalDots" /></ActionMenu>

The ActionMenu tag renders a button which, when clicked, shows the message actions popup menu. You can pass a class that you can use to style the button. Any children of this element will also be rendered. The default theme contains a number of styles to make the menu work well in various circumstances (attachmeznts, sender's name shown or not, etc). You can see the markup of the latest default theme by creating a new theme. You can then copy the new markup and styles to your existing theme where applicable. You can also customize some of the menu's styling in the layout section of your theme. Feel free to reach out via our support chat if you need help getting this to work.

There's No Indication That a Message Has Been Edited

When we added message editing, we updated our built-in theme to show "(edited)" after a message that has been edited. But if you made changes to the UserMessage or MessageBody components of your theme, then you won't see those updates. Here's how to add the edit indicator to your theme:

The UserMessage now receives an editedAt prop, which is null for new messages, and will hold the edit timestamp if the message has been edited. Let's pass this to the MessageBody, so it can display the edit indicator:

<MessageBody body="{{ body }}" timestamp="{{ timestamp }}" editedAt="{{ editedAt }}" floatTimestamp="auto" showStatus="{{ sender.isMe }}"
isLongEmailMessage="{{isLongEmailMessage}}" darkenMenuArea="{{ darkenMenuArea }}" isSystemMessage="{{ false }}" />

Then in the MessageBody component, we'll use this new prop to display the indicator. Locate the part of the template that renders the message's text by searching for the string "{{ body.formattedText }}". After that part, add the following snippet:

<span t:if="{{editedAt}}" class="edited-indicator">({{strings.EDITED_INDICATOR}})</span>

This will render a span with class edited-indicator if the message has been edited. In this snippet strings.EDITED_INDICATOR is the text "edited", translated to the current user's locale.

Replies don't show up

See Upgrade guide