-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path06.routing.html
48 lines (42 loc) · 1.16 KB
/
06.routing.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
<script>
var departments = ["sales", "tech"]
var greetings = {
sales : "Thank your for contacting our Sales Department. An agent will reply soon.",
tech : "Thank your for contacting our Tech Department. An agent will reply soon."
}
if (!localStorage.getItem("crisp-routing")) {
$crisp.push(["do", "message:show", ["picker", {
"id": "routing",
"text": "What is your question about?",
"choices": [{
"value": "sales",
"label": "Sales",
"selected": false
}, {
"value": "tech",
"label": "Tech",
"selected": false
}]
}]])
}
$crisp.push(["on", "message:received", function(data) {
if (data.origin !== "update") {
return;
}
if (!data.content.choices) {
return;
}
if (localStorage.getItem("crisp-routing")) {
return;
}
for (var index in data.content.choices) {
var current = data.content.choices[index];
if (current.selected && departments[current.value] !== -1) {
$crisp.push(["set", "session:segments", [[current.value]]]);
$crisp.push(["do", "message:show", ["text", greetings[current.value]]]);
localStorage.setItem("crisp-routing", "true");
return;
}
}
}])
</script>