Conversation (Chat)
You can view how a chat object can be created for a one-to-one conversation or a group chat with multiple members.
This is called whenever the current user receives a new message.
chat.onMessage((message) => {
//do something with message
})
Response
Field | Type | Description |
---|---|---|
message | the message that has been received. |
This is called whenever a participant of the conversation starts typing.
chat.onTypingStarted((user) => {
//do something when a user starts typing
})
Response
Field | Type | Description |
---|---|---|
user | the user that started typing |
This is called whenever a participant of the conversation stops typing.
chat.onTypingStopped((user) => {
//do something when a user stops typing
})
Response
Field | Type | Description |
---|---|---|
user | the user that stopped typing |
Messages retrieved in a conversation are paginated to 25 messages at a time.
async/await
callback
const { messages , page , totalMessages , totalPages } = await chat.getMessages(1 /** page to query **/ )
chat.getMessages(1 /** page to query **/ ,({ messages , page , totalMessages , totalPages })=>{
//do something with the messages
})
Parameters
Field | Type | State | Description |
---|---|---|---|
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
Field | Type | Description |
---|---|---|
messages | array of messages | |
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 |
To send a message, call a function on the chat object.
const message = {
text: "Hello World!"
}
const callback = (data)=> { /**
handle messages received
Ï */}
chat.sendMessage(message, callback)
Message
ParametersField | Type | State | Description |
---|---|---|---|
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
Field | Type | Description |
---|---|---|
data | the message that was sent |
Get the id of the conversation, returns a
string
const id = chat.getId()
Get the title of the conversation, returns a
string
const title = chat.getTitle()
Get the avatar of the chat, returns a
string
which is the url to the avatarconst avatar = chat.getChatAvatar()
const message = chat.getLastMessage()
const users = await chat.getMembers()
Get an array of ids of all the members of this conversation
const userIds = await chat.getMemberIds()
Call this function to notify everyone who is a participant of the conversation that the current user has started typing
chat.startTyping()
Call this function to notify everyone who is a participant of the conversation that the current user has stopped typing
chat.stopTyping()
Last modified 21h ago