Skip to content

Commit 2f7cdaf

Browse files
committed
Update README.md
1 parent 3d83b6c commit 2f7cdaf

File tree

1 file changed

+82
-3
lines changed
  • rest-api/migrate-data-from-sendbird-to-talkjs

1 file changed

+82
-3
lines changed
Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,85 @@
11
# How to migrate from Sendbird to TalkJS example
22

3-
This example project accompanies the tutorial [How to migrate from Sendbird to TalkJS](https://talkjs.com/resources/how-to-migrate-data-from-sendbird-to-talkjs/).
3+
This example project provides a script that imports Sendbird data into TalkJS. For more details on how to export your data from Sendbird, see the accompanying tutorial, [How to migrate from Sendbird to TalkJS](https://talkjs.com/resources/how-to-migrate-data-from-sendbird-to-talkjs/).
44

5-
> [!TIP]
6-
> [Download this example project as a zip file](https://github.com/talkjs/talkjs-examples/releases/latest/download/rest-api.migrate-data-from-sendbird-to-talkjs.zip)
5+
You can test the import script with the example data provided, or run it on your own data that you export from Sendbird.
6+
7+
> [!TIP] > [Download this example project as a zip file](https://github.com/talkjs/talkjs-examples/releases/latest/download/rest-api.migrate-data-from-sendbird-to-talkjs.zip)
8+
9+
## Prerequisites
10+
11+
To run this example project, you need:
12+
13+
- A [TalkJS account](https://talkjs.com/dashboard/login)
14+
- [Node.js](https://nodejs.org/en)
15+
- [npm](https://www.npmjs.com/)
16+
17+
## How to run the example
18+
19+
1. Clone or [download this project](https://github.com/talkjs/talkjs-examples/releases/latest/download/rest-api.migrate-data-from-sendbird-to-talkjs.zip).
20+
2. In `config.js`, update `<APP_ID>` and `<SECRET_KEY>` with your TalkJS app ID and API secret key, which you can find on the Settings tab of the [dashboard](https://talkjs.com/dashboard). Use your [test environment](https://talkjs.com/docs/Features/Environments/) credentials to test your import, and only import to your live environment when you're happy with the results.
21+
3. Run `npm install` in the top-level directory of the project to install dependencies.
22+
23+
To test the import script on the sample data for the tutorial:
24+
25+
1. Copy the files in `example-data` into the corresponding directories in `sendbird-data`.
26+
2. Run `npm start` to run the import.
27+
3. Test the import:
28+
1. In `script.js`, fill in `<APP_ID>` with your TalkJS app ID.
29+
2. Open `index.html` to view a TalkJS chatbox with the imported data
30+
31+
To run the import script on your own exported Sendbird data:
32+
33+
1. Export your Sendbird user, channel and message data, following the instructions in the [tutorial](https://talkjs.com/resources/how-to-migrate-data-from-sendbird-to-talkjs/), and add the files to the `users`, `channels` and `messages` directories in `sendbird-data`.
34+
2. Run `npm start` to run the import.
35+
3. Test the import. You could check that the users, conversations and messages have been added with the [REST API](https://talkjs.com/docs/Reference/REST_API/Getting_Started/Introduction/), view them in the **Activity** tab of the TalkJS [dashboard](https://talkjs.com/dashboard), or edit `script.js` to view your own data in a TalkJS chatbox.
36+
37+
## About the import script
38+
39+
The import script `runImport.js` calls the scripts in the `importers` directory to import first users, then channels (conversations in TalkJS), then messages.
40+
41+
<div style="background-color: #F9E5D2; padding: 15px;">
42+
43+
<p><strong>Note:</strong> The script does not remove duplicate messages. If you run the script twice you will end up with two imported copies of the message, even if the messages have the same timestamp.</p>
44+
45+
</div>
46+
47+
### User import
48+
49+
The `userImporter.js` script calls the [create user](https://talkjs.com/docs/Reference/REST_API/Users/#create-or-update-a-user) endpoint of the TalkJS REST API.
50+
51+
It maps the following Sendbird user fields to TalkJS [user fields](https://talkjs.com/docs/Reference/Concepts/Users/#user-data):
52+
53+
| Sendbird field | TalkJS field | Required? |
54+
| ------------------ | ------------ | --------- |
55+
| `user_id` | `id` | Yes |
56+
| `nickname` | `name` | No |
57+
| `metadata.emailId` | `email` | No |
58+
| `profile_url` | `photoUrl` | No |
59+
60+
#### Conversation (channel) import
61+
62+
The `channelImporter` script calls the [create conversation](https://talkjs.com/docs/Reference/REST_API/Conversations/#setting-conversation-data) REST API endpoint.
63+
64+
It maps the following Sendbird channel fields to TalkJS [conversation fields](https://talkjs.com/docs/Reference/Concepts/Conversations/#conversation-data):
65+
66+
| TalkJS field | Sendbird field | Required? |
67+
| ------------ | -------------- | --------- |
68+
| `id` | `channel_url` | Yes |
69+
| `subject` | `name` | No |
70+
71+
It then adds users to the conversation as TalkJS [participants](https://talkjs.com/docs/Reference/Concepts/Participants/).
72+
73+
#### Message import
74+
75+
The `messageImporter` script calls the [import messages](https://talkjs.com/docs/Reference/REST_API/Importing_Messages/) REST API endpoint.
76+
77+
It uploads all Sendbird messages where `is_removed` is false, and where the [Sendbird message type](https://sendbird.com/docs/desk/sdk/v1/javascript/features/messages#2-message-types) is `MESG`. These correspond to TalkJS's [user messages](https://talkjs.com/docs/Reference/Concepts/Messages/). The import message endpoint does not support importing [system messages](https://talkjs.com/docs/Reference/Concepts/System_Messages/).
78+
79+
TalkJS autogenerates an `id` for each message. Other fields are mapped as follows:
80+
81+
| TalkJS field | Sendbird field | Required? |
82+
| ------------ | -------------- | --------- |
83+
| `sender` | `user.userId` | Yes |
84+
| `text` | `message` | Yes |
85+
| `timestamp` | `createdAt` | Yes |

0 commit comments

Comments
 (0)