Chat

broadcast()

Broadcasts a message in the chat.
Message will be displayed to all the recipients of the chat

use cases : sending custom media (video, audio, GIFs), polls, call to actions

usage :

Chat.broadcast({
  text: 'Hello world',
  html: '<p>Hi</p>'
})

👍

The html property uses the template system. We recommend you to use our UI Kit to build your HTML templates.

ParamType Description
text?StringThe text of the message
html?StringAn HTML template that will be rendered below the text

@returns An instance of the created Message that you can use to delete the message or be notified whenever the HTML posts message

send()

Adds a message in the chat.
Message will be sent locally, only to the connected user

14161416

use cases : sending user specific content (video, audio, GIFs), polls, call to actions, forms

usage :

Chat.send({
  user: {
    firstName: 'Michael'
  },
  text: 'Hello world',
  html: '<p>Hi</p>'
})

👍

The html property uses the template system. We recommend you to use our UI Kit to build your HTML templates.

ParamType Description
userHashA hash with informations about the sender (firstName, lastName, avatarUrl)
textStringThe text of the message
htmlStringAn HTML template that will be rendered below the text

@returns An instance of the created Message that you can be used to delete the message or be notified whenever the HTML posts message

listen()

Be notified whenever the current user or all users post messages in the chat.

use cases : chat bots, forwarding messages to another API (slack, intercom), language filter, translations, notifying moderators of specific things

usage :

Chat.listen(message => {
  console.log(`Someone said ${message}`)
}, { everyone: true })
ParamType Description
callbackFunction(message)Function that will be called whenever the user posts a message
options{ everyone?: boolean }If everyone is true messages coming from other users will also be caught

intercept()

Intercept Chat messages matching a specific regex.
Once intercepted, the message will not be displayed in the chat.

use cases : custom chat commands, trigger actions, chat bots, forwarding messages to another API (slack, intercom), language filter, translations, notifying moderators of specific things

usage :

Chat.intercept(/lol/, (message) => console.log(`someone said ${message}`))
ParamType Description
matcherRegExpA regular expression that represents the messages to be intercepted
callbackFunction(message)A function that will be called whenever a message that matches your criteria is intercepted

registerCommand()

430430

Register a chat command in the commands menu. This API is a great way to provide quick actions and shortcuts for team members willing to boost their productivity and can be used to execute various actions involving the chat (sharing custom content, files, videos, etc).

Chat.registerCommand({
   command: 'dm',
   label: 'Send a message',
   params: ['name', 'message']
   onTrigger: ({ params }) => {
      console.log(`${params.name} said ${params.message}`
   }
})
ParamTypeDescription
commandStringThe command name, users will type "/" followed by the value of this param
labelStringThe description of your command
paramsArray<String>The list of parameters that your command will receive
onTriggerFunction<ChatCommandTrigger>Function called whenever a user types your command even if params are missing

Types

ChatCommandTrigger
ParamTypeDescription
paramsObjectAn object containing one key per param sent to the command
variablesHashHash of variables you can interpolate into the HTML template
rawCommandStringThe raw message content, including command name
validBooleanWhether all parameters have been filled
mentionsArray<{ replacedWith: string, user: User }>List of users that have been mentioned using the @name syntax
scopeStringThe scope in which your message has been sent

registerMessageAction()

Register an entry in the context menu of a chat message.
Can be used to trigger any action (sharing custom content, files, videos, etc)

614614

use cases: message translation, actions specific to the user who sent the message

usage:

Chat.registerMessageAction({
  label: 'Translate this message',
  imageSource: 'http://image/image.png',
  onClick: (message) => console.log('someone clicked this button')
})
ParamTypeDescription
labelstringThe label of the action
iconstringAn icon from the https://feathericons.com library (not recommended)
imageSourcestringURL of an icon (png, svg) that will be displayed next to your button
onClickFunctionFunction called whenever someone clicks on your button

Buttons.registerChatShareButton()

Register an entry in the Share menu of the chat.
Can be used to trigger any action (sharing custom content, files, videos, etc)

12521252

use cases : trigger actions that will affect the chat (sending files, starting workflows, etc)

usage :

Chat.Buttons.registerChatShareButton({
  label: 'Share a Document',
  imageSource: 'http://image/image.png',
  onClick: () => console.log('someone clicked this button')
})
ParamType Description
labelStringThe label of the action 
iconStringAn icon from the icons list
imageSourceStringURL of an icon (png, svg) that will be displayed next to your button 
onClickFunctionFunction called whenever someone clicks on your button 

What’s Next
Did this page help you?