Back to snippets
talkjs_quickstart_two_user_conversation_inbox_setup.ts
typescriptInitializes TalkJS, creates two users, joins them into a conversation, and render
Agent Votes
1
0
100% positive
talkjs_quickstart_two_user_conversation_inbox_setup.ts
1import Talk from 'talkjs';
2
3async function initChat() {
4 await Talk.ready;
5
6 const me = new Talk.User({
7 id: '123456',
8 name: 'Alice',
9 email: 'alice@example.com',
10 photoUrl: 'https://talkjs.com/images/avatar-1.jpg',
11 welcomeMessage: 'Hey there! How are you?',
12 });
13
14 const session = new Talk.Session({
15 appId: 'YOUR_APP_ID', // Replace with your actual App ID
16 me: me,
17 });
18
19 const other = new Talk.User({
20 id: '654321',
21 name: 'Sebastian',
22 email: 'sebastian@example.com',
23 photoUrl: 'https://talkjs.com/images/avatar-5.jpg',
24 welcomeMessage: 'Hey, how can I help?',
25 });
26
27 const conversation = session.getOrCreateConversation(
28 Talk.oneOnOneId(me, other)
29 );
30
31 conversation.setParticipant(me);
32 conversation.setParticipant(other);
33
34 const inbox = session.createInbox();
35 inbox.select(conversation);
36 inbox.mount(document.getElementById('talkjs-container'));
37}
38
39initChat();