Skip to main content
Version: 5.7.0

GetRecentChatMessages

Returns a list of max \<n> messages from history.

ServiceOperation
chatGET_RECENT_MESSAGES

Method Parameters

ParameterDescription
channelIdThe chat channel to retrieve messages from
maxReturnMaximum number of messages to return

Usage

http://localhost:3000


string channelId = "22817:gl:CHAT_TRADE"; // APP_ID:CHANNEL_TYPE:CHANNEL_ID
int maxReturn = 25;
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 messages = (Dictionary<string, object>[]) jsonData["messages"];

foreach (Dictionary<string, object> message in messages)
{
var content = (Dictionary<string, object>)message["content"];
var item = (Dictionary<string, object>)content["SELL_ITEM"];

string itemType = item["ITEM_TYPE"].ToString();
string itemId = item["ITEM_ID"].ToString();
string price = item["PRICE"].ToString();
string currency = item["CURRENCY"].ToString();
string logMessage = string.Join(" | ", new[] {itemType, itemId, price, currency});
Debug.Log(logMessage); // COUCH | d05a5b9d-374e-41e2-a498-c7387bf15c76 | 105 | GOLDCOINS
}
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("[GetRecentChatMessages Failed] {0} {1} {2}", status, code, error));
};

_bc.ChatService.GetRecentChatMessages(channelId, maxReturn, successCallback, failureCallback);
JSON Response
{
"data": {
"messages": [{
"date": 1530649082684,
"ver": 1,
"msgId": "783692330334210",
"from": {
"id": "a7b7de02-8432-4547-8c40-9af94537fce0",
"name": "RedBomber",
"pic": null
},
"chId": "22817:gl:CHAT_TRADE",
"content": {
"text": "Looking to sell a couch for 105 gold coins.",
"rich": {
"SELL_ITEM": {
"ITEM_TYPE": "COUCH",
"ITEM_ID": "d05a5b9d-374e-41e2-a498-c7387bf15c76",
"PRICE": "105",
"CURRENCY": "GOLDCOINS"
}
}
}
},
{
"date": 1530650080029,
"ver": 1,
"msgId": "783692840974851",
"from": {
"id": "805cc012-0bf1-40a0-9716-b896d8f4c424",
"name": "Chantel",
"pic": null
},
"chId": "22817:gl:CHAT_TRADE",
"content": {
"text": "For that couch, how about 25 gems instead?"
}
},
{
"date": 1530650218944,
"ver": 1,
"msgId": "783692912099332",
"from": {
"id": "a7b7de02-8432-4547-8c40-9af94537fce0",
"name": "RedBomber",
"pic": null
},
"chId": "22817:gl:CHAT_TRADE",
"content": {
"text": "Sold!"
}
}]
},
"status": 200
}
Common Error Code

Status Codes

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