|
1 |
| -<!DOCTYPE html> |
2 |
| -<html lang="en"> |
| 1 | +<html> |
3 | 2 | <head>
|
| 3 | + <title>VAPI</title> |
4 | 4 | <meta charset="UTF-8" />
|
5 |
| - <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
6 |
| - <title>Vapi Support Agent Demo</title> |
| 5 | + |
| 6 | + <style> |
| 7 | + .vapi-btn { |
| 8 | + position: "relative"; |
| 9 | + top: 0; |
| 10 | + left: 0; |
| 11 | + bottom: 0; |
| 12 | + right: 0; |
| 13 | + width: fit-content; |
| 14 | + margin: 100px; |
| 15 | + } |
| 16 | + </style> |
7 | 17 | </head>
|
8 | 18 | <body>
|
9 |
| - <div id="app">Hi there</div> |
| 19 | + <button id="log-action" onClick="logUserAction()">Log Action</button> |
10 | 20 |
|
11 | 21 | <script>
|
12 |
| - const assistant = { |
13 |
| - model: { |
14 |
| - provider: "openai", |
15 |
| - model: "gpt-3.5-turbo", |
16 |
| - systemPrompt: |
17 |
| - "You're a versatile AI assistant named Vapi who is fun to talk with.", |
18 |
| - }, |
19 |
| - voice: { |
20 |
| - provider: "11labs", |
21 |
| - voiceId: "paula", |
22 |
| - }, |
23 |
| - firstMessage: "Hi, I am Vapi how can I assist you today?", |
24 |
| - }; |
| 22 | + const assistant = "61250299-108c-490f-984c-c7c0ebdfd5ee"; // Replace with your assistant ID |
| 23 | + const apiKey = "%VITE_APP_VAPI_API_TOKEN%"; // Replace with your API key |
| 24 | + |
| 25 | + var vapiInstance = null; |
25 | 26 |
|
26 | 27 | const buttonConfig = {
|
27 |
| - position: "bottom-right", |
28 |
| - offset: "40px", |
29 |
| - width: "50px", |
30 |
| - height: "50px", |
| 28 | + position: "bottom-right", // "bottom" | "top" | "left" | "right" | "top-right" | "top-left" | "bottom-left" | "bottom-right" |
| 29 | + offset: "10px", // decide how far the button should be from the edge |
| 30 | + width: "200px", // min-width of the button |
| 31 | + height: "50px", // height of the button |
| 32 | + zIndex: 2147483647, |
31 | 33 | idle: {
|
32 |
| - color: `rgb(93, 254, 202)`, |
33 |
| - type: "round", |
| 34 | + // button state when the call is not active. |
| 35 | + color: `rgb(76, 173, 47)`, |
| 36 | + type: "pill", // or "round" |
| 37 | + // title: "¿Tienes una pregunta rápida?", // only required in case of Pill |
| 38 | + // subtitle: "Habla con nuestro asistente de IA", // only required in case of pill |
34 | 39 | icon: `https://unpkg.com/lucide-static@0.321.0/icons/phone.svg`,
|
35 | 40 | },
|
36 | 41 | loading: {
|
| 42 | + // button state when the call is connecting |
37 | 43 | color: `rgb(93, 124, 202)`,
|
38 |
| - type: "round", |
| 44 | + type: "pill", // or "round" |
| 45 | + // title: "Conectando...", // only required in case of Pill |
| 46 | + // subtitle: "Por favor, espera", // only required in case of pill |
39 | 47 | icon: `https://unpkg.com/lucide-static@0.321.0/icons/loader-2.svg`,
|
40 | 48 | },
|
41 | 49 | active: {
|
| 50 | + // button state when the call is in progress or active. |
42 | 51 | color: `rgb(255, 0, 0)`,
|
43 |
| - type: "round", |
| 52 | + type: "pill", // or "round" |
| 53 | + // title: "Llamada en curso...", // only required in case of Pill |
| 54 | + // subtitle: "Fin de la llamada", // only required in case of pill |
44 | 55 | icon: `https://unpkg.com/lucide-static@0.321.0/icons/phone-off.svg`,
|
45 | 56 | },
|
46 | 57 | };
|
47 | 58 |
|
48 | 59 | (function (d, t) {
|
49 | 60 | var g = document.createElement(t),
|
50 | 61 | s = d.getElementsByTagName(t)[0];
|
51 |
| - |
52 |
| - g.src = "dist/assets/index.js"; |
53 |
| - // g.src = |
54 |
| - // "https://cdn.jsdelivr.net/gh/VapiAI/vapi-support-sdk/dist/assets/index.js"; |
| 62 | + g.src = |
| 63 | + "https://cdn.jsdelivr.net/gh/VapiAI/html-script-tag@latest/dist/assets/index.js"; |
55 | 64 | g.defer = true;
|
56 | 65 | g.async = true;
|
57 | 66 | s.parentNode.insertBefore(g, s);
|
58 | 67 |
|
59 | 68 | g.onload = function () {
|
60 | 69 | const vapi = window.vapiSDK.run({
|
61 |
| - apiKey: "", |
62 |
| - assistant: assistant, |
63 |
| - // config: buttonConfig, |
| 70 | + apiKey: apiKey, // required |
| 71 | + assistant: assistant, // required |
| 72 | + config: buttonConfig, // optional |
64 | 73 | });
|
| 74 | + |
| 75 | + if (vapi) { |
| 76 | + // Extend more using vapi |
| 77 | + window.vapiSDK.vapi = vapi; |
| 78 | + vapiInstance = vapi; |
| 79 | + |
| 80 | + vapiInstance.on("speech-start", () => { |
| 81 | + console.log("Speech has started"); |
| 82 | + }); |
| 83 | + |
| 84 | + vapiInstance.on("speech-end", () => { |
| 85 | + console.log("Speech has ended"); |
| 86 | + }); |
| 87 | + |
| 88 | + vapiInstance.on("call-start", () => { |
| 89 | + console.log("Call has started"); |
| 90 | + }); |
| 91 | + |
| 92 | + vapiInstance.on("call-end", () => { |
| 93 | + console.log("Call has stopped"); |
| 94 | + }); |
| 95 | + |
| 96 | + vapiInstance.on("volume-level", (volume) => { |
| 97 | + console.log(`Assistant volume level: ${volume}`); |
| 98 | + }); |
| 99 | + |
| 100 | + // Function calls and transcripts will be sent via messages |
| 101 | + vapiInstance.on("message", (message) => { |
| 102 | + console.log(message); |
| 103 | + }); |
| 104 | + |
| 105 | + vapiInstance.on("error", (e) => { |
| 106 | + console.error(e); |
| 107 | + }); |
| 108 | + } |
65 | 109 | };
|
66 | 110 | })(document, "script");
|
| 111 | + |
| 112 | + function logUserAction() { |
| 113 | + // Function to log the user action |
| 114 | + |
| 115 | + if (window.vapiSDK.vapi) |
| 116 | + window.vapiSDK.vapi.send({ |
| 117 | + type: "add-message", |
| 118 | + message: { |
| 119 | + role: "system", |
| 120 | + content: "The user has pressed the button, say peanuts", |
| 121 | + }, |
| 122 | + }); |
| 123 | + else { |
| 124 | + console.log(window.vapiSDK, vapiInstance); |
| 125 | + } |
| 126 | + } |
67 | 127 | </script>
|
68 | 128 | </body>
|
69 | 129 | </html>
|
0 commit comments