Messages

Import messages

Imports one or more messages into a conversation.

You can only import messages sent by conversation participants. You can't import messages sent by guests or system messages.

Imported messages don't trigger notifications. Moreover, changes due to importing messages aren't synchronized back to active clients. If a user is currently reading a conversation that you're importing messages into, they need to reload before they see the imported messages.

Import messages with attachments

To import messages with attachments into a conversation, do the following:

  1. Upload the file. You'll receive an attachmentToken in response.
  2. Specify the attachmentToken when importing the message.

The message is now imported with its attachment.

Duplicates

Duplicate messages aren't removed. If you've sent or imported the same message twice, the message shows up twice, even if the messages have the same timestamp.

Test and live mode

Import your data into the TalkJS test mode first to check if everything works as expected, before you import your data into live mode.

If anything goes wrong while testing your import, you can use the Reset all data button on the Settings page of your dashboard to irrevocably delete all messages, conversations, and users.

post/v1/{appId}/import/conversations/{conversationId}/messages

Request

Path parameters

appIdstring required
Example:abcd1234

A unique identifier of your TalkJS app. You can find your app ID on the Settings page of your dashboard.

conversationIdstring required
Example:0123456789abcdef

A unique identifier of a conversation.

Request body

textstring required

The body text of the message.

senderstring required

Unique identifier of the user who sent the message

timestampinteger required

Timestamp when this message was posted, expressed as the number of milliseconds since the UNIX epoch (1970-1-1, 00:00:00 UTC).

readBystring[] required

An array of user ID of users who have read this message.

Note: readBy is only used for conversations with at most 300 participants. For conversations with 301 or more participants, the readBy field will be empty.

typestring required

The type of message this concerns. Imported messages can only be of the type "UserMessage".

attachmentTokenstring

Optional token to identify a file to attach to this message. To obtain an attachment token, first upload the file with the 'Upload a file' resource.

customobject nullable required

A custom object with key-value pairs that you want to associate with a message. Both keys and values must be strings. You can access a custom property in for example API responses, webhook events, and themes.

Example request

[
  {
    "text": "Great! Let's do that",
    "sender": "alice",
    "timestamp": 1629972494633,
    "readBy": [
      "zayneb",
      "sebastian"
    ],
    "type": "UserMessage",
    "attachmentToken": "aBcdeFGHijKLMNoPQrsT0123456789",
    "custom": {
      "priority": "high"
    }
  }
]

Response

Empty response

object required

Empty response

Changes

No recorded changes to this operation across all 1 revision of this API.