-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscan_event.html
143 lines (131 loc) · 4.28 KB
/
scan_event.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>QR Code Scan Success</title>
<style>
body {
font-family: "Arial", sans-serif;
background-color: #f0f8ff; /* Subtle blue */
color: #333;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.message-container {
text-align: center;
border: 2px solid #007bff;
border-radius: 10px;
padding: 20px;
max-width: 300px;
background-color: #e6f2ff;
}
.message-container h1 {
font-size: 24px;
color: #007bff;
}
.message-container p {
font-size: 18px;
margin: 10px 0;
}
.special-value {
font-weight: bold;
color: #ff6600;
margin-top: 15px;
}
</style>
</head>
<body>
<div class="message-container">
<h1>✅ QR Code Scanned Successfully!</h1>
<p>
Your Voiceflow diagram will now have knowledge of this scan event. 🌟
</p>
<p class="special-value" id="special-value">Special Value: Loading...</p>
</div>
<script type="module">
import { checkProjectID, QRCodeExtension } from "./index.js";
import { projectID } from "./config.js";
// Function to get session ID from URL parameters
function getSessionFromURL() {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get("session");
}
// Function to collect user device information
function getUserDeviceDetails() {
const userAgent = navigator.userAgent;
const platform = navigator.platform;
const language = navigator.language;
const screenResolution = `${window.screen.width}x${window.screen.height}`;
const colorDepth = window.screen.colorDepth;
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
return {
userAgent,
platform,
language,
screenResolution,
colorDepth,
timezone,
};
}
// Send user device details to Voiceflow
function sendUserDetailsToVoiceflow(chat) {
const userDeets = getUserDeviceDetails();
console.log("#", { userDeets });
chat.interact({
type: "complete",
payload: {
details: userDeets,
scanFinished: true,
},
});
}
export const loadVoiceflowScript = async () => {
return new Promise((resolve, reject) => {
if (!projectID) {
console.error("Project ID is required.");
return reject("Project ID is required.");
}
const script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://cdn.voiceflow.com/widget/bundle.mjs";
script.onload = () => {
try {
checkProjectID(projectID, window.document);
const session = getSessionFromURL();
document.getElementById(
"special-value"
).textContent = `Special Value: ${session || "No session found"}`;
window.voiceflow.chat
.load({
verify: { projectID },
url: "https://general-runtime.voiceflow.com",
userID: session,
versionID: "production",
render: {
mode: "overlay",
},
autostart: true,
allowDangerousHTML: true,
})
.then((_) => resolve({ chat: window.voiceflow.chat, session }));
} catch (error) {
console.error("Error during script load:", error);
reject(error);
}
};
script.onerror = () => reject("Failed to load Voiceflow script.");
document.getElementsByTagName("head")[0].appendChild(script);
});
};
window.onload = () => {
loadVoiceflowScript()
.then(({ chat }) => sendUserDetailsToVoiceflow(chat))
.catch((error) => console.error(error));
};
</script>
</body>
</html>