Chat

index

Methods

addUsers

tsaddUsers (channelId: string, users: string[]) : Promise<Status> ;

add users to channel

emits user:add event

Parameters

channelId

channel id

tsstring
users

an array of user ids

tsstring[]
Returns
tsPromise<Status>

configure

tsconfigure (channelId: string, config: ChatConfig) : Promise<Status> ;

update channel configuration

emits cnl:config event

Parameters

channelId

channel id

tsstring
config

new configuration

tsChatConfig
Returns
tsPromise<Status>

create

tscreate (channelId: string, config?: ChatConfig) : Promise<Status> ;

create a new channel

emits cnl:add event

Parameters

channelId

channel id

tsstring
config ?

channel configuration

tsChatConfig
Returns
tsPromise<Status>

delUsers

tsdelUsers (channelId: string, users: string[]) : Promise<Status> ;

remove user from channel

users removed won't be able to join again unless added

emits user:del event

Parameters

channelId

channel id

tsstring
users

an array of user ids

tsstring[]
Returns
tsPromise<Status>

delete

tsdelete (channelId: string, reason?: string) : Promise<Status> ;

delete a channel

emits cnl:del event

Parameters

channelId

channel id

tsstring
reason ?

optionally tell others the reason

tsstring
Returns
tsPromise<Status>

deleteMessage

tsdeleteMessage (channelId: string, messageId: string, soft?: boolean) : Promise<Status> ;

delete a message

Parameters

channelId

channel id

tsstring
messageId

message id

tsstring
soft ?

either delete message completely or replace with deleted message

tsboolean
Returns

true if deleted else false | rejects if not message author

tsPromise<Status>

editMessage

tseditMessage (channelId: string, messageId: string, content: string) : Promise<Status> ;

edit a message

Parameters

channelId

channel id

tsstring
messageId

message id

tsstring
content

new message

tsstring
Returns

status response | rejects if not message author

tsPromise<Status>

get

tsget (channelId: string) : Promise<any> ;

get channel info

Parameters

channelId

channel id

tsstring
Returns
tsPromise<any>

getMessages

tsgetMessages (start: string | Date, limit?: number, channels?: string | string[], direction?: "reverse" | "forward") : Promise<{ [channelId : string] : Message[] }> ;

Get messages in a channel(s) | if no channel id is provided saved messages from all user channels are returned by default 50 per query and a max of 150 at once

useful when scrolling through old messages not in user's device

this works only when cloud storage is enabled

Parameters

start

start from, can be either a message id or a date to start get from

tsstring | Date
limit ?

number of messages | defaults to 50

tsnumber
channels ?

channel id , if undefined returns messages from all user's saved channels undefined by default you can also specify a channel or an array of channels to get messages from.

tsstring | string[]
direction ?

direction to fecth message either forward or reverse

ts"reverse" | "forward"
Returns

messages in channels grouped by channel id

tsPromise<{ [channelId : string] : Message[] }>

getUsers

tsgetUsers (channelId: string) : Promise<User[]> ;

get channel users

Parameters

channelId

channel id

tsstring
Returns

users in channel

tsPromise<User[]>

join

tsjoin (channelId: string) : Promise<any> ;

join an existing channel

emits user:join event

Parameters

channelId

channel id

tsstring
Returns
tsPromise<any>

leave

tsleave (channelId: string) : Promise<Status> ;

leave a channel

emits user:left event

Parameters

channelId

channel id

tsstring
Returns
tsPromise<Status>

list

tslist (pagination?: Pagination, publicOnly?: boolean) : Promise<any[]> ;

list channels

Parameters

pagination ?

pagination

tsPagination
publicOnly ?

list public channels, when channel discovery is enabled. by default this is false and will alway return the user's joined channels

tsboolean
Returns
tsPromise<any[]>

modUsers

tsmodUsers (channelId: string, users: string[], mode: number) : Promise<Status> ;

moderate users in channel

emits user:mod event

check concepts for more about permissions

Parameters

channelId

channel id

tsstring
users

an array of users

tsstring[]
mode
tsnumber
Returns
tsPromise<Status>

on

tson < K extends keyof ChatEventMap > (event: K, handler:  (ev: ChatEventMap[K]) => any ) : void ;

listen for chat events and messages

Parameters

event

event

tsK
handler

handler function

ts (ev: ChatEventMap[K]) : any ;
Returns
tsvoid

react

tsreact (channelId: string, messageId: string, reaction: string) : Promise<{ id: string; }> ;

send a reaction to a message

Parameters

channelId

channel id

tsstring
messageId

message id

tsstring
reaction

reaction

tsstring
Returns

the derivery status of the message

tsPromise<{ id: string; }>

send

tssend (channelId: string, message: string | SendMessage) : Promise<{ id: string; }> ;

send a message in a channel

Parameters

channelId

channel id

tsstring
message

message to send

tsstring | SendMessage
Returns

the message id

tsPromise<{ id: string; }>

update

tsupdate (channelId: string, data: any) : Promise<Status> ;

update channel data

Parameters

channelId

channel id

tsstring
data

data

tsany
Returns
tsPromise<Status>