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:

<!-- minified snippet to load TalkJS without delaying your page -->
<script>
(function(t,a,l,k,j,s){
s=a.createElement('script');s.async=1;s.src="https://cdn.talkjs.com/talk.js";a.head.appendChild(s)
;k=t.Promise;t.Talk={v:1,ready:{then:function(f){if(k)return new k(function(r,e){l.push([f,r,e])});l
.push([f])},catch:function(){return k&&new k()},c:l}};})(window,document,[]);
</script>

<!-- Session initialization code -->
<script>
Talk.ready.then(function() {
    var me = new Talk.User({
        id: "123456",
        name: "Alice",
        email: "[email protected]",
        photoUrl: "https://demo.talkjs.com/img/alice.jpg",
        welcomeMessage: "Hey there! How are you? :-)"
    });
    window.talkSession = new Talk.Session({
        appId: "YOUR_APP_ID",
        me: me
    });
});
</script>

This code should, ideally, appear on every page you serve, so that TalkJS can notify your users and your app of changes. The top <script> tag in here 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: