|
| 1 | +<!DOCTYPE html> |
| 2 | + |
| 3 | +<html lang="en"> |
| 4 | + <head> |
| 5 | + <meta charset="utf-8" /> |
| 6 | + <meta name="viewport" content="width=device-width, initial-scale=1" /> |
| 7 | + |
| 8 | + <title>TalkJS tutorial</title> |
| 9 | + </head> |
| 10 | + |
| 11 | + <!-- minified snippet to load TalkJS without delaying your page --> |
| 12 | + <script> |
| 13 | + (function (t, a, l, k, j, s) { |
| 14 | + s = a.createElement("script"); |
| 15 | + s.async = 1; |
| 16 | + s.src = "https://cdn.talkjs.com/talk.js"; |
| 17 | + a.head.appendChild(s); |
| 18 | + k = t.Promise; |
| 19 | + t.Talk = { |
| 20 | + v: 3, |
| 21 | + ready: { |
| 22 | + then: function (f) { |
| 23 | + if (k) |
| 24 | + return new k(function (r, e) { |
| 25 | + l.push([f, r, e]); |
| 26 | + }); |
| 27 | + l.push([f]); |
| 28 | + }, |
| 29 | + catch: function () { |
| 30 | + return k && new k(); |
| 31 | + }, |
| 32 | + c: l, |
| 33 | + }, |
| 34 | + }; |
| 35 | + })(window, document, []); |
| 36 | + </script> |
| 37 | + |
| 38 | + <script> |
| 39 | + Talk.ready.then(function () { |
| 40 | + const me = new Talk.User({ |
| 41 | + id: "muteConversationExampleSupportAgent", |
| 42 | + name: "Alice", |
| 43 | + |
| 44 | + role: "default", |
| 45 | + photoUrl: "https://talkjs.com/images/avatar-1.jpg", |
| 46 | + welcomeMessage: "Hey there! How can I help?", |
| 47 | + }); |
| 48 | + const talkSession = new Talk.Session({ |
| 49 | + appId: "<APP_ID>", // replace with your app ID |
| 50 | + me: me, |
| 51 | + }); |
| 52 | + |
| 53 | + const other = new Talk.User({ |
| 54 | + id: "muteConversationExampleUser", |
| 55 | + name: "Sebastian", |
| 56 | + |
| 57 | + role: "default", |
| 58 | + photoUrl: "https://talkjs.com/images/avatar-5.jpg", |
| 59 | + welcomeMessage: "Hey, how can I help?", |
| 60 | + }); |
| 61 | + |
| 62 | + const bob = new Talk.User({ |
| 63 | + id: "muteConversationExampleUser2", |
| 64 | + name: "Bob", |
| 65 | + |
| 66 | + role: "default", |
| 67 | + photoUrl: "https://talkjs.com/images/avatar-4.jpg", |
| 68 | + welcomeMessage: "Hey, how can I help?", |
| 69 | + }); |
| 70 | + |
| 71 | + const conversation = talkSession.getOrCreateConversation( |
| 72 | + "muteConversationExample" |
| 73 | + ); |
| 74 | + conversation.setParticipant(me); |
| 75 | + conversation.setParticipant(other); |
| 76 | + |
| 77 | + const conversation2 = talkSession.getOrCreateConversation( |
| 78 | + "muteConversationExample2" |
| 79 | + ); |
| 80 | + conversation2.setParticipant(me); |
| 81 | + conversation2.setParticipant(bob); |
| 82 | + |
| 83 | + const inbox = talkSession.createInbox({ selected: conversation }); |
| 84 | + inbox.mount(document.getElementById("talkjs-container")); |
| 85 | + inbox.onCustomConversationAction("mute", (event) => { |
| 86 | + console.log("Muted conversation with id:", event.conversation.id); |
| 87 | + let conversation = talkSession.getOrCreateConversation( |
| 88 | + event.conversation.id |
| 89 | + ); |
| 90 | + conversation.setParticipant(me, { notify: false }); |
| 91 | + inbox.select(conversation); |
| 92 | + }); |
| 93 | + }); |
| 94 | + </script> |
| 95 | + |
| 96 | + <body> |
| 97 | + <!-- container element in which TalkJS will display a chat UI --> |
| 98 | + <div id="talkjs-container" style="width: 90%; margin: 30px; height: 500px"> |
| 99 | + <i>Loading chat...</i> |
| 100 | + </div> |
| 101 | + </body> |
| 102 | +</html> |
0 commit comments