The Current User

Near the top of our TalkJS code, we created a Session, but we haven't given it much attention yet in this guide. This code has remained pretty much untouched:

1await Talk.ready;
2const me = new Talk.User({
3 id: '123456',
4 name: 'Alice',
5 email: '[email protected]',
6 photoUrl: 'https://talkjs.com/images/avatar-1.jpg',
7 welcomeMessage: 'Hey there! How are you? :-)',
8 role: 'default',
9});
10const session = new Talk.Session({
11 appId: 'YOUR_APP_ID',
12 me: me,
13});

This code should, ideally, appear on every page you serve, so that TalkJS can notify your users and your app of changes. Also include the <script> snippet, which loads TalkJS (without slowing down your page).

Note: you can also load TalkJS using our npm package if you prefer.

Starting a session

In the second <script> body, we use the Talk.Ready promise to wait for TalkJS to load. Then, we initialize this user's session. A session is the connection between a user's active browser tab and TalkJS. It also identifies your app to the TalkJS backend and it synchronizes your user's profile information. Read more about sessions.

As you might notice, we're still logged in as Alice. Use the same code that you used in the last section to remove Alice and replace it with information about the currently logged in user.

Next steps

That's it! You now have a basic 1-on-1 chat up and running. Check out the Features section for many ways to enrich and customize TalkJS. For instance: