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

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

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)

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)

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?