Send and receive messages
Requires Message Persistence
To store data about messages, you must enable Message Persistence for your app's keyset in the Admin Portal and set the desired message retention period.
Send
Send a message to a previously defined channel using the sendText()
method.
sendText()
prepares the final message content for publishing, including text, any attached files, metadata, mentioned users, or referenced channels (defined in and passed from the message draft).
Encrypt/Decrypt messages and files
Chat SDK supports the PubNub's AES-CBC 256-bit crypto module used to automatically encrypt and decrypt messages and files. Learn how to configure your Chat SDK instance to enable the module in your app.
Method signature
This method takes the following parameters:
channel.sendText(
message: string,
options?: SendTextOptionParams
// {
// storeInHistory?: boolean,
// sendByPost?: boolean,
// meta?: any,
// ttl?: number,
// quotedMessage?: Message,
// files?: FileList | File[] | FileInput[]
// }
): Promise<unknown>
Input
* required
Parameter | Description |
---|---|
message *Type: string Default: n/a | Text that you want to send to the selected channel. |
options Type: SendTextOptionParams Default: n/a | This object holds the configuration options. |
options →storeInHistory Type: boolean Default: true | If true , the messages are stored in Message Persistence. If storeInHistory is not specified, the Message Persistence configuration specified on the Admin Portal keyset is used. |
options →sendByPost Type: boolean Default: false | When true , the SDK uses HTTP POST to publish the messages. The message is sent in the BODY of the request instead of the query string when HTTP GET is used. The messages are also compressed to reduce their size. |
options →meta Type: any Default: n/a | Publish additional details with the request. |
options →ttl Type: number Default: n/a | Defines if / how long (in hours) the message should be stored in Message Persistence.
|
options →quotedMessage Type: Message Default: n/a | Object added to a message when you quote another message. This object stores the following info about the quoted message: { timetoken: quotedMessage.timetoken, text: quotedMessage.text, userId: quotedMessage.userId } , where timetoken is the time when the quoted message was published, text contains the original message content, and userId is the identifier of the user who published the quoted message. |
options |