Switch between conversations
Once you've added a chatbox or popup to your site, and you have some conversations going, you might want your users to be able to switch between them.
Let's say you have a few buttons on a page, each corresponding to a conversation topic:
HTML1<button onclick="buttonClicked(this.innerHTML)">Conversation A</button>2<button onclick="buttonClicked(this.innerHTML)">Conversation B</button>3<button onclick="buttonClicked(this.innerHTML)">Conversation C</button>
Then we can define buttonClicked(conversationId)
as follows
JavaScript1let popup;23function buttonClicked(conversationId) {4 // assume `session` has been set elsewhere5 const conversation = session.getOrCreateConversation(conversationId);67 if (popup) {8 popup.show(); //in case popup is hidden9 popup.select(conversation); //select the conversation clicked on10 } else {11 //if there is no existing popup, create one12 popup = session.createPopup();13 popup.select(conversation);14 popup.mount({ show: true });15 }16}
When the user clicks on a button, the text within the button is used as a conversation id. The popup then makes this the active conversation. select
takes either a Conversation object or conversation id as its parameter - see select.
Assuming someChatbox
exists, we can simply do:
JavaScript1function buttonClicked(conversationId) {2 const conversation =3 window.talkSession.getOrCreateConversation(conversationId);4 someChatbox.select(conversation);5}