|
2 | 2 |
|
3 | 3 | <template>
|
4 | 4 | <div id="talkjs-container" style="width: 100%; height: 500px">
|
5 |
| - <i>Loading chat...</i> |
| 5 | + <i>Loading chat...</i> |
6 | 6 | </div>
|
7 | 7 | </template>
|
8 | 8 |
|
9 | 9 | <script setup>
|
10 |
| - import Talk from "talkjs"; |
11 |
| - import { onMounted } from 'vue'; |
| 10 | +import Talk from "talkjs"; |
| 11 | +import { onMounted } from "vue"; |
12 | 12 |
|
13 |
| - onMounted(() => { |
14 |
| - Talk.ready.then(() => { |
15 |
| - const me = new Talk.User({ |
16 |
| - id: 'nina', |
17 |
| - name: 'Nina', |
18 |
| - email: 'nina@example.com', |
19 |
| - photoUrl: 'https://talkjs.com/new-web/avatar-7.jpg', |
20 |
| - welcomeMessage: 'Hi!', |
21 |
| - }); |
22 |
| - const session = new Talk.Session({ |
23 |
| - appId: '<APP_ID>', |
24 |
| - me: me, |
25 |
| - }); |
| 13 | +onMounted(() => { |
| 14 | + Talk.ready.then(() => { |
| 15 | + const session = new Talk.Session({ |
| 16 | + appId: "<APP_ID>", |
| 17 | + userId: "nina", |
| 18 | + }); |
| 19 | + session.currentUser.createIfNotExists({ |
| 20 | + name: "Nina", |
| 21 | + email: "nina@example.com", |
| 22 | + photoUrl: "https://talkjs.com/new-web/avatar-7.jpg", |
| 23 | + welcomeMessage: "Hi!", |
| 24 | + }); |
26 | 25 |
|
27 |
| - const other = new Talk.User({ |
28 |
| - id: 'frank', |
29 |
| - name: 'Frank', |
30 |
| - email: 'frank@example.com', |
31 |
| - photoUrl: 'https://talkjs.com/new-web/avatar-8.jpg', |
32 |
| - welcomeMessage: 'Hey, how can I help?', |
33 |
| - }); |
| 26 | + const otherRef = session.user("frank"); |
| 27 | + otherRef.createIfNotExists({ |
| 28 | + name: "Frank", |
| 29 | + email: "frank@example.com", |
| 30 | + photoUrl: "https://talkjs.com/new-web/avatar-8.jpg", |
| 31 | + welcomeMessage: "Hey, how can I help?", |
| 32 | + }); |
34 | 33 |
|
35 |
| - const conversation = session.getOrCreateConversation('new_conversation'); |
36 |
| - conversation.setParticipant(me); |
37 |
| - conversation.setParticipant(other); |
| 34 | + const conversationRef = session.conversation("new_conversation"); |
| 35 | + conversationRef.createIfNotExists(); |
| 36 | + conversationRef.participant(otherRef).createIfNotExists(); |
38 | 37 |
|
39 |
| - const chatbox = session.createChatbox(); |
40 |
| - chatbox.select(conversation); |
41 |
| - chatbox.mount(document.getElementById('talkjs-container')); |
42 |
| - }); |
| 38 | + const chatbox = session.createChatbox(); |
| 39 | + chatbox.select(conversationRef); |
| 40 | + chatbox.mount(document.getElementById("talkjs-container")); |
43 | 41 | });
|
| 42 | +}); |
44 | 43 | </script>
|
0 commit comments