-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
145 lines (136 loc) · 3.79 KB
/
script.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
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
144
145
// Use this sample to create your own voice commands
intent("hello world", (p) => {
p.play("(hello|hi there)");
});
intent("Type me a message", (p) => {
// p.play("ok sure");
p.play({ command: "type_message" });
});
intent("Open $(username* (.*)) (chat| chat box|)", (p) => {
let username = p.username.value;
let users = p.visual.data;
username = username.toLowerCase();
let valid;
if (users) {
if (!users.find((u) => u.username === username)) {
p.play(`No user found of username ${username}`);
} else {
p.play(`Opening ${username}'s chat`);
p.play({ command: "openUser", username: username, data: users });
}
}
});
intent("Read me (all|) the messages", async (p) => {
let users = p.visual.data;
if (users) {
let selectedUser = users.find((u) => u.selected === true);
if (selectedUser) {
if (selectedUser.messages) {
for (let i = selectedUser.messages.length - 1; i >= 0; i--) {
await p.play(`${selectedUser.messages[i].content}`);
}
p.play({ command: "readUserMessage", data: selectedUser });
}
}
}
});
intent("Read me the last message", async (p) => {
let users = p.visual.data;
if (users) {
let selectedUser = users.find((u) => u.selected === true);
if (selectedUser) {
if (selectedUser.messages) {
let msg = selectedUser.messages[0];
if (selectedUser.username === msg.from) {
p.play(`${msg.from} sent you message ${msg.content}`);
} else {
p.play(`You send ${msg.content} to ${msg.to}`);
}
p.play({ command: "readLastMessage", data: selectedUser });
p.play(`Would you like to send message to ${selectedUser.username}?`);
}
}
}
});
intent("Type me a message", async (p) => {
let users = p.visual.data;
if (users) {
let selectedUser = users.find((u) => u.selected === true);
if (selectedUser) {
if (selectedUser.messages) {
p.play("ok, just say Add");
p.play("AND your message after it");
}
}
}
});
intent("add $(message* (.*))", async (p) => {
let users = p.visual.data;
if (users) {
let selectedUser = users.find((u) => u.selected === true);
if (selectedUser) {
if (selectedUser.messages) {
p.play("alright");
p.play({ command: "typeMessage", msg: p.message.value });
p.play("Do you want to send it");
p.then(setMessage);
}
}
}
});
intent("log me out", "log out", (p) => {
p.play("as you wish");
p.play({ command: "logoutUser" });
});
const setMessage = context(() => {
intent("yes", async (p) => {
let users = p.visual.data;
if (users) {
let selectedUser = users.find((u) => u.selected === true);
if (selectedUser) {
if (selectedUser.messages) {
p.play("ok");
p.play({ command: "sendMessage" });
p.play("sent");
}
}
}
});
intent("No", async (p) => {
let users = p.visual.data;
if (users) {
let selectedUser = users.find((u) => u.selected === true);
if (selectedUser) {
if (selectedUser.messages) {
p.play("sure");
p.play({ command: "resetMessage" });
}
}
}
});
});
const confirmation = context(() => {
intent("yes", async (p) => {
let users = p.visual.data;
if (users) {
let selectedUser = users.find((u) => u.selected === true);
if (selectedUser) {
if (selectedUser.messages) {
p.play("ok, say add");
p.play("and your message");
}
}
}
});
intent("no", async (p) => {
let users = p.visual.data;
if (users) {
let selectedUser = users.find((u) => u.selected === true);
if (selectedUser) {
if (selectedUser.messages) {
p.play("Ok, no problem.");
}
}
}
});
});