Skip to content

Commit

Permalink
Merge pull request #3347 from haoxiuwen/agora-chat
Browse files Browse the repository at this point in the history
Modify Agora Chat EN Docs
  • Loading branch information
haoxiuwen authored Sep 28, 2023
2 parents 68329c6 + cc0637c commit 9703698
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ ChatClient.getInstance()
You can retrieve the messages in the specified conversation from the local database by specifying the conversation ID and chat type:

```typescript
// Sepcify the conversation ID.
// Specify the conversation ID.
const convId = "convId";
// Whether to create a conversation if the specified one does not exist. If you set it as true, this method always returns a conversation object.
const createIfNeed = true;
Expand All @@ -53,8 +53,8 @@ const convType = ChatConversationType.PeerChat;
// Call getConversation to retrieve the specified conversation.
ChatClient.getInstance()
.chatManager.getConversation(convId, convType, createIfNeed)
.then((message) => {
console.log("Getting conversations succeeds", message);
.then((conversation) => {
console.log("Getting conversations succeeds", conversation);
})
.catch((reason) => {
console.log("Getting conversations fails.", reason);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,19 @@ This section shows how to implement sending and receiving the various types of m
Use the `ChatMessage` class to create a text message, and send the message.

```java
// Call createTextSendMessage to create a text message. Set content as the content of the text message, and conversationId the user ID of the message recipient.
// Call createTextSendMessage to create a text message.
// Set `content` as the content of the text message.
// Set `conversationId` to the user ID of the peer user in one-to-one chat, group ID in group chat, and chat room ID in room chat.
ChatMessage message = ChatMessage.createTextSendMessage(content, conversationId);
// Set the message type using the MessageType attribute in Message.
// You can set `MessageType` as `Chat`, `Group`, or `Room`, which indicates whether to send the message to a peer user, a chat group, or a chat room.
// Set `ChatType` as `Chat`, `GroupChat`, or `ChatRoom` for one-to-one chat, group chat, or room chat.
message.setChatType(ChatMessage.ChatType.GroupChat);
// Send the message
// Send the message.
ChatClient.getInstance().chatManager().sendMessage(message);
```

```java
// Calls setMessageStatusCallback to set the callback instance to get the status of messaging sending. You can update the status of messages in this callback, for example, adding a tip when the message sending fails.
// Call setMessageStatusCallback to set the callback instance to get the status of messaging sending.
// You can update the status of messages in this callback, for example, adding a tip when the message sending fails.
message.setMessageStatusCallback(new CallBack() {
@Override
public void onSuccess() {
Expand Down Expand Up @@ -74,7 +76,7 @@ sendMessage(message);

You can use `MessageListener` to listen for message events. You can add multiple `MessageListener`s to listen for multiple events. When you no longer listen for an event, ensure that you remove the listener.

When a message arrives, the recipient receives an `onMessgesReceived` callback. Each callback contains one or more messages. You can traverse the message list, and parse and render these messages in this callback.
When a message arrives, the recipient receives an `onMessagesReceived` callback. Each callback contains one or more messages. You can traverse the message list, and parse and render these messages in this callback.

```java
MessageListener msgListener = new MessageListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ Follow the steps to create and send a message, and listen for the result of send
```dart
// Sets the message type. Agora Chat supports 8 message types.
MessageType messageType = MessageType.TXT;
// Sets the user ID of the recipient.
// Sets `targetId` to the user ID of the peer user in one-to-one chat, group ID in group chat, and chat room ID in room chat.
String targetId = "tom";
// Sets the chat type. You can set it as a peer user, chat group, or chat room.
// Sets `chatType` as `Chat`, `GroupChat`, or `ChatRoom` for one-to-one chat, group chat, or room chat.
ChatType chatType = ChatType.Chat;
// Creates a message. For different message types, you need to set different parameters.
// Creates a message. Parameters vary with message types.
// Creates a text message.
ChatMessage msg = ChatMessage.createTxtSendMessage(
targetId: targetId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,20 @@ This section shows how to implement sending and receiving the various types of m
Use the `AgoraChatTextMessageBody` class to create a text message, and then send the message.

```objective-c
// Call initWithText to create a text message. Set content as the text content and toChatUsername to the username to whom you want to send this text message.
AgoraChatTextMessageBody *textMessageBody = [[AgoraChatTextMessageBody alloc] initWithText:content];
AgoraChatMessage *message = [[AgoraChatMessage alloc] initWithConversationID:toChatUsername
from:fromChatUsername
to:toChatUsername
body:textMessageBody
ext:messageExt];
// Set the chat type as Group chat. You can also set is as chat (one-to-one chat) or chat room.
// message.chatType = AgoraChatTypeGroupChat;
// Sends the message
[[AgoraChatClient sharedClient].chatManager sendMessage:message
progress:nil
completion:nil];
// Call initWithText to create a text message. Set `content` to the text content.
AgoraChatTextMessageBody *textMessageBody = [[AgoraChatTextMessageBody alloc] initWithText:content];
// Set `conversationId` to the user ID of the peer user in one-to-one chat, group ID in group chat, and chat room ID in room chat.
NSString* conversationId = @"remoteUserId";
AgoraChatMessage *message = [[AgoraChatMessage alloc] initWithConversationID:conversationId
body:textMessageBody
ext:messageExt];
// Set `message.chatType` to `AgoraChatTypeChat` for one-to-one chat, `AgoraChatTypeGroupChat` for group chat, and `AgoraChatTypeChatRoom` for room chat.
// The default value is `AgoraChatTypeChat`.
message.chatType = AgoraChatTypeChat;
// Send the message.
[[AgoraChatClient sharedClient].chatManager sendMessage:message
progress:nil
completion:nil];
```
You can set the priority of chat room messages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,27 @@ class ChatMessageCallback implements ChatMessageStatusCallback {
.catch((reason) => {
// The sending operation fails and the log is printed here.
console.log("send message operation fail.", reason);
});
})
};
```

Use the `ChatMessage` class to create a message, and `ChannelManager` to send the message.

```typescript
// Set the message type. The SDK supports 8 message types. For details, see descriptions in ChatMessageType.
// You can send different types of messages by setting this parameter.
// Set the message type. The SDK supports 8 message types.
const messageType = ChatMessageType.TXT;
// Set the user ID of the message recipient.
// Set `targetId` to the user ID of the peer user in one-to-one chat, group ID in group chat, and chat room ID in room chat.
const targetId = "tom";
// Set the chat type as a peer-to-peer chat, group chat, or chat room. For details, see descriptions in ChatMessageChatType.
// Set `chatType` as `PeerChat`, `GroupChat`, or `ChatRoom` for one-to-one chat, group chat, or room chat.
const chatType = ChatMessageChatType.PeerChat;
// Construct the message. For different message types, you need to set the different parameters.
// Construct the message. Parameters vary with message types.
let msg: ChatMessage;
if (messageType === ChatMessageType.TXT) {
// For a text message, set the message content.
const content = "This is text message";
msg = ChatMessage.createTextMessage(targetId, content, chatType);
} else if (messageType === ChatMessageType.IMAGE) {
// For am image message, set the file path, width, height, and display name of the image file.
// For an image message, set the file path, width, height, and display name of the image file.
const filePath = "/data/.../image.jpg";
const width = 100;
const height = 100;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,20 @@ This section shows how to implement sending and receiving the various types of m
Use the `Message` class to create a text message, and `IChannelManager` to send the message.

```C#
// Call CreateTextSendMessage to create a text message. Set `content` as the content of the text message, and `toChatUsernames` the user ID of the message recipient.
Message msg = Message.CreateTextSendMessage(toChatUsername, content);
// Set the message type using the `MessageType` attribute in `Message`.
// You can set `MessageType` as `Chat`, `Group`, or `Room`, which indicates whether to send the message to a peer user, a chat group, or a chat room.
// Call CreateTextSendMessage to create a text message.
// Set `content` as the content of the text message.
// Set `conversationId` to the user ID of the peer user in one-to-one chat, group ID in group chat, and chat room ID in room chat.
Message msg = Message.CreateTextSendMessage(conversationId, content);
// Set `MessageType` in `Message` as `Chat`, `Group`, or `Room` for one-to-one chat, group chat, or room chat.
msg.MessageType = MessageType.Group;

// Set the priority of chat room messages. The default priority is `Normal`, indicating the normal priority.
msg.MessageType = MessageType.Room;
msg.SetRoomMessagePriority(RoomMessagePriority.High);
// msg.MessageType = MessageType.Room;
// msg.SetRoomMessagePriority(RoomMessagePriority.High);
// Call SendMessage to send the message.
// When sending the message, you can instantiate a `Callback` object to listen for the result of the message sending. You can also update the message state in this callback, for example, by adding a pop-up box that reminds the message sending fails.
// When sending the message, you can instantiate a `Callback` object to listen for the result of the message sending.
// You can also update the message state in this callback, for example, by adding a pop-up box that reminds the message sending fails.
SDKClient.Instance.ChatManager.SendMessage(ref msg, new CallBack(
onSuccess: () => {
Debug.Log($"{msg.MsgId} Message sending succeeds.");
Expand All @@ -59,7 +63,7 @@ SDKClient.Instance.ChatManager.SendMessage(ref msg, new CallBack(

You can use `IChatManagerDelegate` to listen for message events. You can add multiple `IChatManagerDelegates` to listen for multiple events. When you no longer listen for an event, ensure that you remove the delegate.

When a message arrives, the recipient receives an `OnMessgesReceived` callback. Each callback contains one or more messages. You can traverse the message list, and parse and render these messages in this callback and render these messages.
When a message arrives, the recipient receives an `OnMessagesReceived` callback. Each callback contains one or more messages. You can traverse the message list, and parse and render these messages in this callback and render these messages.

```C#
// Inherit and instantiate IChatManagerDelegate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ function sendPrivateText() {
let option = {
// Set the message content.
msg: "message content",
// Set the username of the receiver.
to: "username",
// Set the chat type
// Set the user ID of the recipient for one-to-one chat, group ID for group chat, or chat room ID for room chat.
to: "userId",
// Set `chatType` as `singleChat` for one-to-one chat, `groupChat` for group chat, or `chatRoom` for room chat.
chatType: "singleChat",
};
// Create a text message.
let msg = AC.message.create(option);
// Call send to send the message
// Call `send` to send the message
conn.send(msg).then((res)=>{
console.log("Send message success",res);
}).catch((e)=>{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,20 @@ This section shows how to implement sending and receiving the various types of m
Use the `Message` class to create a text message, and `IChannelManager` to send the message.

```C#
// Call CreateTextSendMessage to create a text message. Set `content` as the content of the text message, and `toChatUsernames` the user ID of the message recipient.
Message msg = Message.CreateTextSendMessage(toChatUsername, content);
// Set the message type using the `MessageType` attribute in `Message`.
// You can set `MessageType` as `Chat`, `Group`, or `Room`, which indicates whether to send the message to a peer user, a chat group, or a chat room.
// Call CreateTextSendMessage to create a text message.
// Set `content` as the content of the text message.
// Set `conversationId` to the user ID of the peer user in one-to-one chat, group ID in group chat, and chat room ID in room chat.
Message msg = Message.CreateTextSendMessage(conversationId, content);
// Set `MessageType` in `Message` as `Chat`, `Group`, or `Room` for one-to-one chat, group chat, or room chat.
msg.MessageType = MessageType.Group;
//Set the priority of chat room messages. The default priority is `Normal`, indicating the normal priority.
msg.MessageType = MessageType.Room;
msg.SetRoomMessagePriority(RoomMessagePriority.High);

// Set the priority of chat room messages. The default priority is `Normal`, indicating the normal priority.
// msg.MessageType = MessageType.Room;
// msg.SetRoomMessagePriority(RoomMessagePriority.High);
// Call SendMessage to send the message.
// When sending the message, you can instantiate a `Callback` object to listen for the result of the message sending. You can also update the message state in this callback, for example, by adding a pop-up box that reminds the message sending fails.
// When sending the message, you can instantiate a `Callback` object to listen for the result of the message sending.
// You can also update the message state in this callback, for example, by adding a pop-up box that reminds the message sending fails.
SDKClient.Instance.ChatManager.SendMessage(ref msg, new CallBack(
onSuccess: () => {
Debug.Log($"{msg.MsgId} Message sending succeeds.");
Expand All @@ -59,7 +63,7 @@ SDKClient.Instance.ChatManager.SendMessage(ref msg, new CallBack(

You can use `IChatManagerDelegate` to listen for message events. You can add multiple `IChatManagerDelegates` to listen for multiple events. When you no longer listen for an event, ensure that you remove the delegate.

When a message arrives, the recipient receives an `OnMessgesReceived` callback. Each callback contains one or more messages. You can traverse the message list, and parse and render these messages in this callback and render these messages.
When a message arrives, the recipient receives an `OnMessagesReceived` callback. Each callback contains one or more messages. You can traverse the message list, and parse and render these messages in this callback and render these messages.

```C#
// Inherit and instantiate IChatManagerDelegate.
Expand Down
2 changes: 2 additions & 0 deletions en-US/markdown/agora-chat/Reference/agora_chat_status_code.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ This status code indicates that the API request is rejected by the server due to
| `403` | `forbidden_op` | "Forbidden operation on group owner!" | The error message returned because the specified operation cannot be performed on chat group owners, such as adding the chat group owner to block list. |
| `403` | `forbidden_op` | "Can not join this group, reason:user: {username} has joined too many groups/chatroom!" | The error message returned because the number of chat groups or chat rooms joined by a user has reached the limit. |
| `403` | `forbidden_op` | "This appKey has create too many groups/chatrooms!" | The number of chat groups or chat rooms created by using an App key has reached the limit. For details, see [Pricing plans](./agora_chat_plan?platform=RESTful). |
| 403 | exceed_limit | "Invitee's contact max count" | The user receiving the friend request has reached the maximum number of contacts allowed.|
| 403 | exceed_limit | "Inviter's contact max count" | The user sending the friend request has reached the maximum number of contacts allowed. |

### 404 Not Found
This status code indicates that the specified resources of the API request could not be found by the server.
Expand Down

0 comments on commit 9703698

Please sign in to comment.