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() methods.

Both SendText() methods send the final message content for publishing.

Method signature

These methods take the following parameters:

channel.SendText(string message)
channel.SendText(string message, SendTextParams sendTextParams)

Input

ParameterTypeRequiredDefaultDescription
messagestringYesn/aText that you want to send to the selected channel.
sendTextParamsSendTextParamsNonew SendTextParams()Parameters to configure sending options (history, posts, metadata, etc.)
 → storeInHistoryboolNotrueIf 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.
 → sendByPostboolNofalseWhen 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.
 → metastringNon/aPublish additional details with the request.
 → mentionedUsersDictionary<int, User>Non/aObject mapping a mentioned user (with name and ID) with the number of mention (like @Mar) in the message (relative to other user mentions). For example, { 0: { id: 123, name: "Mark" }, 2: { id: 345, name: "Rob" } } means that Mark will be shown on the first mention in the message and Rob on the third.

Refer to User Mentions for more details and example.
 → referencedChannelsDictionary<int, Channel>Non/aObject mapping the referenced channel (with name and ID) with the place where this reference (like #Sup) was mentioned in the message (relative to other channel references). For example, { 0: { id: 123, name: "Support" }, 2: { id: 345, name: "Off-topic" } } means that Support will be shown on the first reference in the message and Off-topic on the third.

Refer to Reference channels for more details and example.
 → textLinksList<TextLink>Non/aReturned array of text links that are shown as text in the message. For example, {StartIndex = 0, EndIndex = 13, Link = "www.google.com"}.

Refer to Links for more details and example.
 → quotedMessageMessageNon/aObject 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.

Refer to Quotes for more details and example.

Output

These methods don't return any data.

Basic usage

Send the Hi Everyone! message to the support channel.

// reference the channel where you want to send a text message
if (!chat.TryGetChannel("support", out var channel))
{
Console.WriteLine("Couldn't find channel!");
return;
};

channel.SendText("Hi everyone!")

Other examples

For examples on how to send a message with links, mentioned users, referenced channels, or message quotes, 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.

Last updated on