forked from ObjectIsAdvantag/hackathon-resources
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tropo-IVR-hackathon.js
74 lines (62 loc) · 3.04 KB
/
tropo-IVR-hackathon.js
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
if (!currentCall) { // No tropo session yet => this is an outgoing call initiated via Tropo token url
var offset = 2; // CET+2
var now = new Date(Date.now() + (3600000 * offset));
call(phonenumber);
say("it is now " + now.getHours() + ":" + now.getMinutes() + " in Paris, Rome, Madrid, Berlin, Zurich and Amsterdam.");
wait(500);
offset = 1; // CET+1
now = new Date(Date.now() + (3600000 * offset));
say("note that it is now " + now.getHours() + ":" + now.getMinutes() + " in Lisbon, London and Dublin.");
}
else { // Session initiated => this is an incoming call
answer();
wait(1000); // On-boarding pause : do not speak too quickly the IVR
// Pick a voice depending on your language & preference (male/female)
// https://www.tropo.com/docs/scripting/international-features/speaking-multiple-languages
var currentVoice = "Ava"; // Allison, Ava, Samantha, Susan, Veronica, Vanessa (Default), Tom, Victor
log("speaking the welcome invite to: +" + currentCall.callerID);
say("Hello, Welcome to the Hackathon !", { voice: currentVoice });
wait(500);
say("What about learning Cisco Spark and Tropo API ?", { voice: currentVoice });
wait(1000);
// SSML: https://www.tropo.com/docs/scripting/advanced-speech-control/manipulating-say-ssml
event = ask("<speak>Dial 1 to receive instructions by SMS <break time='500ms'/> Dial 2 to get the name of the winner</speak>", {
voice: currentVoice,
choices: "1,2",
timeout: 5,
attempts: 3,
mode: "dtmf", // dial tone only as we are in an open conference room
onTimeout: function(event) {
say("Sorry, I didn't hear your choice.", { voice: currentVoice });
},
onBadChoice: function(event) {
say("Sorry, I didn't understand what you said.", { voice: currentVoice });
}
});
if (event.name == 'choice') {
var selected = parseInt(String(event.value));
switch (selected) {
case 1:
say("Got it, we are texting you the instructions.", { voice: currentVoice });
// Send a SMS from a new Tropo session
log("sending details via SMS to: +" + currentCall.callerID);
var forkedCall = call(currentCall.callerID, {
network: "SMS"
});
forkedCall.value.say("Welcome to the Cisco Spark and Tropo challenge.");
forkedCall.value.hangup();
break;
case 2:
default:
log("running the challenge via Tropo: +" + currentCall.callerID);
// [TODO] Implement takeChallenge()
say("Sorry, cheat mode is not implemented yet !", { voice: currentVoice });
break;
}
}
// Finish the conversation gently
wait(500);
say("Thanks and see you at the Cisco booth. Bye Bye.", { voice: currentVoice });
wait(1000);
hangup();
}