Conversation (Chat)
A conversation(chat) object lets you have conversations with 1 or more Users.
You can view how a chat object can be created for a one-to-one conversation or a group chat with multiple members.
Event Listeners
Listen for new messages
This is called whenever the current user receives a new message.
chat.onMessage((message) => {
//do something with message
})
Response
Listen for message updated
This is called whenever a message gets updated in the chat.
chat.onMessageUpdated((message) => {
//do something with the updated message
})
Response
Listen for message deleted
This is called whenever a message gets deleted.
chat.onMessageDeleted((messageId) => {
//do something
})
Response
messageId
String
the id of the message that has been deleted.
Listen for typing started
This is called whenever a participant of the conversation starts typing.
chat.onTypingStarted((user) => {
//do something when a user starts typing
})
Response
Listen for typing stopped
This is called whenever a participant of the conversation stops typing.
chat.onTypingStopped((user) => {
//do something when a user stops typing
})
Response
Listen for message seen events
This is called whenever a message has been seen by a participant in a conversation
chat.onMessageSeen((messageId) => {
//do something when a message is seen
})
Response
messageId
string
the id of the message that has been seen
Listen for user status changes (online/offline)
This is called whenever the status of a user in a conversation changes from online to offline or vice versa.
chat.onMemberStatusChanged((memberId,status) => {
//do something when a user status changes
})
Response
memberId
string
the id of the user who's status has changed
status
enum
the status of the user. an enum of either ONLINE
or OFFLINE
Functions
Get Messages
Messages retrieved in a conversation are paginated to 25 messages at a time.
const { messages , page , totalMessages , totalPages } = await chat.getMessages(1 /** page to query **/ )
Parameters
page
number
optional
query a specific page of messages, each page contains 25 messages. if null
or undefined
then the most recent 25 messages are returned
Response
page
number
shows the current page of messages. each page contains 25 messages
totalMessages
number
shows the total number of messages that exist
totalPages
number
shows the total number of pages of messages that exist. each page contains 25 messages
Send Message
To send a message, call a function on the chat object.
const message = {
text: "Hello World!"
}
const callback = (data)=> { /**
do something
*/}
chat.sendMessage(message, callback)
Message
Parameters
text
string
optional
the text of the message
file
File
optional
upload a file as an attachment
metadata
json object
optional
an optional key value pair for any additional message information such as custom font size, font type, or JSON
formatted string. accepts string,number and boolean values
Callback
Update Message
const message = {
text: "Updated Hello World!"
}
const callback = (data)=> { /**
do something
*/}
chat.updateMessage(messageId, message, callback)
Parameters
messageId
string
required
the id of the message to be updated
Message
Parameters
text
string
optional
the text of the message
file
File
optional
upload a file as an attachment
metadata
json object
optional
an optional key value pair for any additional message information such as custom font size, font type, or JSON
formatted string. accepts string,number and boolean values
Callback
Delete Message
chat.deleteMessage(messageId)
Parameters
messageId
string
the Id of the message to delete
Get ID
Get the id of the conversation, returns a string
const id = chat.getId()
Get Title
Get the title of the conversation, returns a string
const title = chat.getTitle()
Get Conversation Avatar
Get the avatar of the chat, returns a string
which is the url to the avatar
const avatar = chat.getChatAvatar()
Get recent message
Get the most recent message sent in the conversation. Returns a Message
object.
const message = chat.getLastMessage()
Get Members
Get an array of all the users of this conversation
const users = await chat.getMembers()
Get MemberIds
Get an array of ids of all the members of this conversation
const userIds = await chat.getMemberIds()
Get Metadata
get an optional key value pair for any additional chat information.
const metadata = chat.getMetadata()
Set Metadata
Add any additional chat information.
await chat.setMetaData(metadata)
Parameters
metadata
json object
required
an optional key value pair for any additional chat information. Accepts string, number and boolean values
Add member to group chat
Add a member to a group chat
await chat.addMember(username)
Add member to group chat by ID
add a member to a group chat using a member ID
await chat.addMemberById(userId)
Remove member from group chat
Remove a member from a group chat
await chat.removeMember(username)
Remove member from group chat by ID
Remove a member from a group chat using a member ID
await chat.removeMemberById(userId)
Notify everyone typing started
Call this function to notify everyone who is a participant of the conversation that the current user has started typing
chat.startTyping()
Notify everyone typing stopped
Call this function to notify everyone who is a participant of the conversation that the current user has stopped typing
chat.stopTyping()
Set Message Seen
Call this function to notify participants of the conversation that a message has been seen. (useful when handling message seen states).
chat.setSeen(messageId)
Parameters
messageId
string
optional
the id of the message. If left null or undefined then the last message in the conversation is set as seen by the connected user.
Last updated
Was this helpful?