Klat
  • TalkPlus SDK
  • Android
    • Getting Started
    • Callback
    • User
      • Create User / Login
      • Update User Information
      • Block / Unblock
      • Logout
      • Delete User
    • Channel
      • Create / Delete Channel
      • View Channel
      • Updating Channel
      • Viewing Channel LIst
      • Manage Channel Members
      • Join / Leave Channel
      • Messaging
      • Hide / Show Channel
      • Freeze / Unfreeze Channel
      • Transfer Channel Ownership
      • Channel Push Notification Settings
      • Channel Member Data
    • Push Notification
    • Sample Application
    • What's New
  • iOS
    • Getting Started
    • Callback
    • User
      • Create / Login
      • Update User Information
      • Block / Unblock
      • Logout
      • Delete User
    • Channel
      • Create / Delete Channel
      • View Channel
      • Updating Channel
      • View Channel List
      • Manage Channel Members
      • Join / Leave Channel
      • Messaging
      • Hide / Show Channel
      • Freeze / Unfreeze Channel
      • Transfer Channel Ownership
      • Channel Push Notification Settings
      • Channel Member Data
    • Push Notification
    • Sample Application
    • What's New
  • Unity
    • Getting Started
    • Callback
    • User
      • Create User / Login
      • Update User Information
      • Block / Unblock
      • Logout
      • Delete User
    • Channel
      • Create / Delete Channel
      • View Channel
      • Updating Channel
      • View Channel List
      • Manage Channel Members
      • Join / Leave Channel
      • Messaging
      • Hide / Show Channel
      • Freeze / Unfreeze Channel
      • Transfer Channel Ownership
      • Channel Push Notification Settings
      • Channel Member Data
    • Push Notification
    • Sample Application
  • JavaScript
    • Getting Started
    • Realtime Event
    • Pagination
    • User
      • Create User / Login
      • Update User Information
      • Block / Unblock
      • Logout
      • Delete
    • Channel
      • Create / Delete Channel
      • View Channel
      • Updating Channel
      • View Channel List
      • Manage Channel Members
      • Join / Leave Channel
      • Messaging
      • Hide / Show Channel
      • Freeze / Unfreeze Channel
      • Transfer Channel Ownership
      • Channel Push Notification Settings
      • Channel Member Data
    • Push Notification (FCM)
    • Sample Application
    • What's New
  • Flutter
    • Getting Started
    • Callback
    • User
      • Create User / Login
      • Update User Information
      • Block / Unblock
      • Logout
      • Delete User
    • Channel
      • Create Channel
      • View Channel
      • Updating Channel
      • View Channel List
      • Manage Channel Members
      • Join / Leave Channel
      • Messaging
      • Hide / Show Channel
      • Freeze / Unfreeze Channel
      • Transfer Channel Ownership
      • Channel Push Notification Settings
      • Channel Member Data
    • Push Notification (FCM)
  • REST API
    • Getting Started
    • API
      • Users
        • Create User
        • Login (using login token)
        • View User
        • Update User
        • Activate / Deactivate
        • Enable / Disable Push Notification
        • Delete User
        • View Users
        • View Channels
        • Block / Unblock
      • Channel
        • Create Channel
        • View Channel
        • Update Channel
        • Delete Channel
        • View Channel List
        • Manage Channel Members
        • Messaging
        • Hide / Show Channel
        • Channel Freeze / Unfreeze
        • Transfer Channel Ownership
        • Channel Push Notification Settings
      • Bot
        • Create Bot
        • View Bot List
        • View Bot
        • Update Bot
        • Delete Bot
        • View Joined Channel List
        • Messaging
        • Join / Leave Channel
    • Push Notification
    • Rate Limit
  • MISC
    • Webhooks
    • SDK Rate Limit
    • Error Code
    • FAQ
      • Function
      • Spec
Powered by GitBook
On this page
  • 1. Get Messages
  • 2. View Messages With File Upload
  • 3. Send Message
  • 4. View Message
  • 5. Reply To Message
  • 6. Mark As Read
  • 7. React To Message
  • 8. Message Translation
  • 9. Get Unread Message Count
  • 10. Delete Message
  1. JavaScript
  2. Channel

Messaging

PreviousJoin / Leave ChannelNextHide / Show Channel

Last updated 11 months ago

If you need translation feature, see below.

Message translation feature is provided through Google Cloud Translation. To use this feature, register an appropriate Google Cloud Service Account Key on our dashboard.

  • To enable message translation, provide the language code (ISO-639) in translationTargetLanguage parameter when logging in.

  • Supported languages (ISO-639) can be found .

  • 'translations' field in message object contains translated texts. Use language code as key to retrieve the text.

1. Get Messages

Messages are sorted by most recent (default).

Setting translationTargetLanguage parameter returns messages with translated text.

  • Use this to translate channel messages from the past.

  • For realtime message translation, see .

const resp = await client.getMessages({
    channelId: 'my_channel',
    order: 'latest', // default: 'latest'. Use 'oldest' to order by oldest messages first
    limit: 10, // how many messages to fetch, default: 20, max: 50
});

if (resp.hasNext) {
    const lastMessageId = resp.messages[resp.messages.length - 1].id;
    
    const moreResp = await client.getMessages({
        channelId: 'my_channel',
        lastMessageId: lastMessageId,
        limit: 10,
    });
}

Response

{
  "messages": [
    {
      "id": "5f7d5e407d138500010000ce",
      "channelId": "my_channel",
      "userId": "user456",
      "username": "user456",
      "profileImageUrl": "http://cdn.test.com/456.jpg",
      "type": "text",
      "text": "Hello",
      "data": {},
      "fileUrl": "http://cdn.test.com/123.jpg",
      "mentions": [],
      "parentMessage": {}, // message to reply to
      "parentMessageId": "",
      "reactions": {"happy": ["user1"]},
      "createdAt": 1583921400
    }
  ],
  "hasNext": false
}

2. View Messages With File Upload

View messages with file attachment.

Messages are sorted by most recent (default).

Setting translationTargetLanguage parameter returns messages with translated text.

  • Use this to translate channel messages from the past.

const resp = await client.getFileMessages({
    channelId: 'my_channel',
    limit: 10,
});

3. Send Message

The following message types are supported: text, hidden, custom.

  • Push notification is not sent for hidden message type.

  • admin, admin_hidden message type can only be sent from TalkPlus dashboard or by calling REST API.

  • You can enter up to 10 key-value pairs in data field. The maximum size of key is 128 characters and the maximum size of value is 1024 characters. Both key and value must be strings.

  • Both message text and data cannot be empty when sending a message.

  • The maximum size of message text is 8192 characters.

  • The maximum file upload size is 15MB.

  • Emojis supported by UTF-8 can be used in message text.

  • For custom emojis, required values can be put into message text then parsed directly.

await client.sendMessage({
    channelId, 
    type: 'text', 
    text: 'hello?', 
    data: {imageUrl: 'http://image.cdn.com/123.jpg'},
    mentions: ['user1', 'user2'] // optional. mentioning another user
});
const resp = await client.sendMessage({ 
    channelId, 
    type: 'text', 
    text: 'hello?', 
    data: {imageUrl: 'http://image.cdn.com/123.jpg'}, 
    translationTargetLanguages: ['ko', 'de'], 
});

const message = resp.message; 
console.log(message.translations);
<input type="file" onchange="sendFile(this)" >

<script>
    async function sendFile(input) {
        // 파일 업로드
        await client.sendMessage({
            channelId, 
            type: 'text', 
            text: '안녕하세요?', 
            data: {meta: 'my meta data'},
            file: input.files[0], // 업로드 가능한 최대 파일 사이즈는 15MB입니다.
        });
    }
</script>
await client.sendMessage({
    channelId, 
    type: 'custom', 
    fileUrl: 'http://somedomain.com/file_somewhere_in_the_cloud.jpeg',
    translationTargetLanguage: 'ko', // optional
});

4. View Message

View a single message.

const resp = await client.getMessage({
    channelId, 
    messageId: 'someMessageId',
});

5. Reply To Message

Reply to another message.

await client.sendMessage({
    channelId, 
    type: 'text', 
    text: 'hello?', 
    parentMessageId: 'anotherMessageIdThatIamReplyingTo',
    data: {imageUrl: 'http://image.cdn.com/123.jpg'},
});

6. Mark As Read

You can mark a channel as read.

await client.markAsRead({channelId: 'my_channel'}); 

7. React To Message

You can add/remove reaction to a message.

  • reaction must be alphanumeric and between 1 and 64 characters long.

  • Each message can have up to 10 reaction types.

  • Each reaction type can contain up to 100 user IDs.

// add reaction to message
await client.addMessageReaction({
    channelId: 'my_channel', 
    messageId: 'my_message',
    reaction : 'happy',
});

// remove reaction
await client.removeMessageReaction({
    channelId: 'my_channel', 
    messageId: 'my_message',
    reaction : 'happy',
});

// reactions field is visible in message object
const msgListResp = await client.getMessages({channelId: 'someChannelId'});
console.log(msgListResp.messages[0].reactions);
/*
{
    "happy": [
        "user1",
        "user2"
    ],
    "sad": [
        "user3"
    ]
}
*/

8. Message Translation

Message translation feature is provided through Google Cloud Translation. To use this feature, register an appropriate Google Cloud Service Account Key on our dashboard.

  • To enable message translation, provide the language codes (ISO-639) in targetLanguages parameter.

await client.translateMessage({
    channelId: 'my_channel', 
    messageId: 'target_messageId',
    targetLanguages: ['en', 'de'], // translate to en, de
}); 

9. Get Unread Message Count

You can find out how many channel members have not read a particular message.

const channelGetResp = await client.getChannel({channelId: 'demo channel'});
const channelObject = channelGetResp.channel;

const msgResp = await client.getMessages({channelId: 'my channel'});
const messageObject = msgResp.messages[0]; // assume that message array is not empty in this example

const msgUnreadCount = client.getMessageUnreadCount({channel: channelObject, message: messageObject});
console.log(`msgUnreadCount: ${msgUnreadCount}`); // integer result

10. Delete Message

You can delete your own message.

await client.deleteMessage({channelId: 'my_channel', messageId: 'messageId_to_delete'}); 

For realtime message translation, see .

Supported languages (ISO-639) can be found .

here
this
this
here