Send and receive messages
Requires Message Persistence
Enable Message Persistence on your keyset in the Admin Portal to store messages.
Send
Use SendText() to send a message to a channel. The method handles text content and metadata. To send messages with user mentions, quoted messages, or file attachments, use MessageDraft instead.
Method signature
These methods take the following parameters:
1channel.SendText(string message)
1channel.SendText(string message, SendTextParams sendTextParams)
Input
| Parameter | Description |
|---|---|
message *Type: stringDefault: n/a | Text that you want to send to the selected channel. |
sendTextParamsType: SendTextParamsDefault: new SendTextParams() | Parameters to configure sending options. |
→ storeInHistoryType: boolDefault: 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. |
→ sendByPostType: boolDefault: 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. |
→ metaType: Dictionary<string, object>Default: new() | Publish additional details with the request. |
→ customPushDataType: Dictionary<string, string>Default: new() | Custom key-value pairs to include in push notification payloads. Use this to send additional data along with your push notifications. Refer to Mobile Push Notifications for more details. |
Mentions, quotes, and files
To send a message with user mentions, a quoted message, or file attachments, use MessageDraft and call draft.Send(). These features are set directly on the MessageDraft object and are not available through SendTextParams.
Output
An awaitable Task.
Sample code
Send the Hi Everyone! message to the support channel.
1
Other examples
For examples on how to send a message with links, mentioned users, referenced channels, message quotes, or files, head to the relevant docs.
Receive
To receive messages on a given channel, you must connect to the channel and start listening to message events.