# Chat messages

In order to send and receive chat messages, necessary object declarations and chat window functions must be prepared. If you are not ready, learn how to create one and come back. Go to preparation section

# Send message

JSONObject param = new JSONObject();
param.put("message", "Hello");
param.put("mimeType", "text");

channel.sendMessage(param, new ChannelCallback() {
    @Override
    public void callback(Object o, VChatCloudException e) {
        if (e != null) {
            Log.d(TAG,"message transmission error");
        }
    }
});
1
2
3
4
5
6
7
8
9
10
11
12
  • Parameter value

    value identifier Description
    message String message to send
    mimeType String message type (text: plain text, emoji_img: emoji)
  • result value

    value identifier Description
    code String error code
    message String error message

# code to apply to the project

    # New message event

    // ChatActivity.java
    public void onNotifyMessage(JSONObject data) { // message event
        Log.d("Chat message", data);
    }
    
    1
    2
    3
    4
    • Push result value

      | value | identifier | Description | | ------------ | ------ | -------------------------------------------------- -------------------------------------------------- --------- | | nickName | String | Nickname of the user entering the chat room who sent the message | | roomId | String | Channel Key issued after creating a chat room | | clientKey | String | A unique key for setting the access terminal that sent the message | | message | String | message sent | | mimeType | String | message type (text: plain text, emoji: emoji) | | messageDt | String | Sent Date | | messageCount | String | Number of Chat Room Messages Sent | | grade | String | Rating of the user who sent the message ( Check User Rating Table ) |

    # code to apply to the project

    // ChatActivity.java
    public void onNotifyMessage(JSONObject data) { // message event
        Message msg = new Message(data);
        msg.setType("msg");
    
        messageExposure(msg, false);
    }
    
    1
    2
    3
    4
    5
    6
    7

    # Send a message to a specific user

    JSONObject json = new JSONObject();
    json.put("receivedClientKey", 'target user key');
    json.put("message", "message content");
    json.put("mimeType", "text");
    channel.sendWhisper(json, new ChannelCallback() {
        @Override
        public void callback(Object o, VChatCloudException e) {
            if (e != null) {
                Log.d(TAG,"message transmission error");
            }
            $RecyclerView.smoothScrollToPosition($Adapter.getItemCount());
        }
    });
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    • Parameter value
    value identifier Description
    message String message to send
    mimeType String Message type (text: plain text, emoji: emoji)
    receivedClientKey String Receiving user's connection terminal setting unique key
    • result value

      -err

      value identifier Description
      code String error code
      message String error message

      -msg

      | value | identifier | Description | | ----------------- | ------ | -------------------------------------------------- -------------------------------------------------- --------- | | roomId | String | Channel Key issued after creating a chat room | | nickName | String | Nickname of the user entering the chat room | | clientKey | String | A unique key for setting the access terminal that sent the message | | message | Date | Sent messages | | mimeType | String | Message type (text: plain text, emoji: emoji) | | messageDt | String | Sent Date | | messageCount | String | Number of Chat Room Messages Sent | | receivedNickName | String | Nickname of the user receiving the message | | receivedClientKey | String | A unique key to set access terminals that receive messages | | grade | String | Rating of the user who sent the message ( Check User Rating Table ) |

    # code to apply to the project

    @Override
    public void onClick(DialogInterface dialog, int which) {
        Log.d(TAG, "Yes Btn Click");
    
        // Receive text value and leave log
        String value = et.getText().toString();
        Log.d(TAG, value);
        JSONObject json = new JSONObject();
        json.put("receivedClientKey", message.getClientKey());
        json. put("message", value);
        json.put("mimeType", "text");
        channel.sendWhisper(json, new ChannelCallback() {
            @Override
            public void callback(Object o, VChatCloudException e) {
                if (e != null) {
                    Log.d(TAG,"message transmission error");
                }
                $RecyclerView.smoothScrollToPosition($Adapter.getItemCount());
            }
        });
        dialog. dismiss(); //close
    }
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22

    # Private whisper message event

    public void onPersonalWhisper(JSONObject data) { // Personal Whisper event
        Log.d("Whisper", data);
    }
    
    1
    2
    3
    • Push result value

      | value | identifier | Description | | ----------------- | ------ | -------------------------------------------------- -------------------------------------------------- --------- | | roomId | String | Channel Key issued after creating a chat room | | nickName | String | Nickname of the user entering the chat room | | clientKey | String | A unique key for setting the access terminal that sent the message | | message | Date | Sent messages | | mimeType | String | Message type (text: plain text, emoji: emoji) | | messageDt | String | Sent Date | | messageCount | String | Number of Chat Room Messages Sent | | receivedClientKey | String | A unique key to set access terminals that receive messages | | grade | String | Rating of the user who sent the message ( Check User Rating Table ) |

    # code to apply to the project

    public void onPersonalWhisper(JSONObject data) { // Personal Whisper event
        Message msg = new Message(data);
        msg.setType("preWhisper");
    
        messageExposure(msg, false);
    }
    
    1
    2
    3
    4
    5
    6
    Copyright 2022. E7Works Inc. & JOYTUNE Corp. All Rights Reserved.