PostChatMessageSimple
Sends a text-only member chat message on behalf of the user. This method provides convenience by simplifying message construction. Returns the id of the message that was created.
Service | Operation |
---|---|
chat | POST_CHAT_MESSAGE_SIMPLE |
Method Parameters
Parameter | Description |
---|---|
channelId | The chat channel to post to |
chatMessage | Simple string content for the message. Will be placed inside of a text field of the content section. |
recordInHistory | Set 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
- C#
- C++
- Objective-C
- Java
- JavaScript
- Dart
- Cloud Code
- Raw
string channelId = "22817:gl:CHAT_GROUPFINDER"; // APP_ID:CHANNEL_TYPE:CHANNEL_ID
string chatMessage = "Hey, I am looking for new and experienced users to join our group.";
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("[PostChatMessageSimple Failed] {0} {1} {2}", status, code, error));
};
_bc.ChatService.PostChatMessageSimple(channelId, chatMessage, true, successCallback,
failureCallback);
const char *channelId = "55555:gl:bcDev";
const char *chatMessage = "Hello world";
bool recordInHistory = true;
_bc->getChatService()->postChatMessageSimple(channelId, chatMessage, recordInHistory, this);
NSString *channelId = @"55555:gl:bcDev";
NSString *chatMessage = @"Hello world";
bool recordInHistory = true;
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[[_bc chatService] postChatMessageSimple:channelId
chatMessage:chatMessage
recordInHistory:recordInHistory
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
String channelId = "22817:gl:CHAT_GROUPFINDER"; // APP_ID:CHANNEL_TYPE:CHANNEL_ID
String chatMessage = "Hey, I am looking for new and experienced users to join our group.";
boolean recordInHistory = true;
this; // implements IServerCallback
_bc.getChatService().postChatMessageSimple(channelId, chatMessage, recordInHistory, this);
public void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, JSONObject jsonData)
{
System.out.print(String.format("Success | %s", jsonData.toString()));
}
public void serverError(ServiceName serviceName, ServiceOperation serviceOperation, int statusCode, int reasonCode, String jsonError)
{
System.out.print(String.format("Failed | %d %d %s", statusCode, reasonCode, jsonError.toString()));
}
var channelId = "22817:gl:CHAT_GROUPFINDER"; // APP_ID:CHANNEL_TYPE:CHANNEL_ID
var chatMessage = "Hey, I am looking for new and experienced users to join our group.";
var recordInHistory = true;
_bc.chat.postChatMessageSimple(channelId, chatMessage, recordInHistory, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
var channelId = "22817:gl:CHAT_GROUPFINDER";
var chatMessage = "Hey, I am looking for new and experienced users to join our group.";
var recordInHistory = true;
ServerResponse result = await _bc.chatService.postChatMessageSimple(channelId:channelId, chatMessage:chatMessage, recordInHistory:recordInHistory);
if (result.statusCode == 200) {
print("Success");
} else {
print("Failed ${result.error['status_message'] ?? result.error}");
}
var chatProxy = bridge.getChatServiceProxy();
var postResult = chatProxy.postChatMessageSimple( channelId, "Helloooo!!!", true );
if (postResult.status == 200 ) {
// Success!
}
{
"service": "chat",
"operation": "POST_CHAT_MESSAGE_SIMPLE",
"data": {
"channelId": "55555:gl:bcDev",
"text": "Hello world",
"recordInHistory": true
}
}
JSON Response
{
"status": 200,
"data": {
"msgId": "783822917533185"
}
}
Common Error Code
Status Codes
Code | Name | Description |
---|---|---|
40601 | RTT_NOT_ENABLED | RTT must be enabled for this feature |
40603 | CHAT_UNRECOGNIZED_CHANNEL | The specified channel is invalid |