Skip to main content
Version: 5.7.0

PostChatMessage

Sends a potentially richer member chat message. By convention, content should contain a field named text for plain-text content. Returns the id of the message created.

ServiceOperation
chatPOST_CHAT_MESSAGE

Method Parameters

ParameterDescription
channelIdThe chat channel to post to
contentJsonThe json content of the message. Split into chatMessage and jsonRich for plain text and json content respectively.
recordInHistorySet to false if the message shouldn't be recorded to history. Useful for sending non-conversational messages, like when users join a room, etc.

Usage

http://localhost:3000
string channelId = "22817:gl:CHAT_TRADE"; // APP_ID:CHANNEL_TYPE:CHANNEL_ID
string text = "Looking to sell a couch for 105 gold coins.";
Dictionary<string, object> sellItem = new Dictionary<string, object>
{
{"ITEM_TYPE", "COUCH"},
{"ITEM_ID", "d05a5b9d-374e-41e2-a498-c7387bf15c76"},
{"PRICE", "105"},
{"CURRENCY", "GOLDCOINS"}
};
Dictionary<string, object> rich = new Dictionary<string, object>
{
{"SELL_ITEM", sellItem}
};
var contentJson = JsonFx.Json.JsonWriter.Serialize(new Dictionary<string, object>
{
{"rich", rich},
{"text", text}
});

bool recordInHistory = true;
SuccessCallback successCallback = (response, cbObject) =>
{
Dictionary<string, object> jsonMessage =
(Dictionary<string, object>) JsonFx.Json.JsonReader.Deserialize(response);
Dictionary<string, object> jsonData = (Dictionary<string, object>) jsonMessage["data"];

var msgId = jsonData["msgId"].ToString();
string logMessage = string.Join(" | ", new[] {msgId});
Debug.Log(logMessage); // 783733181125648
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("[PostChatMessage Failed] {0} {1} {2}", status, code, error));
};

_bc.ChatService.PostChatMessage(channelId, contentJson, recordInHistory,
successCallback, failureCallback);
JSON Response
{
"status": 200,
"data": {
"msgId": "783347769003570"
}
}
Common Error Code

Status Codes

CodeNameDescription
40601RTT_NOT_ENABLEDRTT must be enabled for this feature
40603CHAT_UNRECOGNIZED_CHANNELThe specified channel is invalid