-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
206 lines (194 loc) · 6.05 KB
/
app.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
"use strict";
const express = require("express");
const bodyParser = require("body-parser");
const hostname = '127.0.0.1';
const port = 3000;
const restService = express();
restService.use(
bodyParser.urlencoded({
extended: true
})
);
restService.use(bodyParser.json());
restService.post("/echo", function(req, res) {
var speech =
req.body.result &&
req.body.result.parameters &&
req.body.result.parameters.echoText
? req.body.result.parameters.echoText
: "Seems like some problem. Speak again.";
return res.json({
speech: speech,
displayText: speech,
source: "webhook-echo-sample"
});
});
restService.post("/audio", function(req, res) {
var speech = "";
switch (req.body.result.parameters.AudioSample.toLowerCase()) {
//Speech Synthesis Markup Language
case "music one":
speech =
'<speak><audio src="https://actions.google.com/sounds/v1/cartoon/slide_whistle.ogg">did not get your audio file</audio></speak>';
break;
case "music two":
speech =
'<speak><audio clipBegin="1s" clipEnd="3s" src="https://actions.google.com/sounds/v1/cartoon/slide_whistle.ogg">did not get your audio file</audio></speak>';
break;
case "music three":
speech =
'<speak><audio repeatCount="2" soundLevel="-15db" src="https://actions.google.com/sounds/v1/cartoon/slide_whistle.ogg">did not get your audio file</audio></speak>';
break;
case "music four":
speech =
'<speak><audio speed="200%" src="https://actions.google.com/sounds/v1/cartoon/slide_whistle.ogg">did not get your audio file</audio></speak>';
break;
case "music five":
speech =
'<audio src="https://actions.google.com/sounds/v1/cartoon/slide_whistle.ogg">did not get your audio file</audio>';
break;
case "delay":
speech =
'<speak>Let me take a break for 3 seconds. <break time="3s"/> I am back again.</speak>';
break;
//https://www.w3.org/TR/speech-synthesis/#S3.2.3
case "cardinal":
speech = '<speak><say-as interpret-as="cardinal">12345</say-as></speak>';
break;
case "ordinal":
speech =
'<speak>I stood <say-as interpret-as="ordinal">10</say-as> in the class exams.</speak>';
break;
case "characters":
speech =
'<speak>Hello is spelled as <say-as interpret-as="characters">Hello</say-as></speak>';
break;
case "fraction":
speech =
'<speak>Rather than saying 24+3/4, I should say <say-as interpret-as="fraction">24+3/4</say-as></speak>';
break;
case "bleep":
speech =
'<speak>I do not want to say <say-as interpret-as="bleep">F&%$#</say-as> word</speak>';
break;
case "unit":
speech =
'<speak>This road is <say-as interpret-as="unit">50 foot</say-as> wide</speak>';
break;
case "verbatim":
speech =
'<speak>You spell HELLO as <say-as interpret-as="verbatim">hello</say-as></speak>';
break;
case "date one":
speech =
'<speak>Today is <say-as interpret-as="date" format="yyyymmdd" detail="1">2017-12-16</say-as></speak>';
break;
case "date two":
speech =
'<speak>Today is <say-as interpret-as="date" format="dm" detail="1">16-12</say-as></speak>';
break;
case "date three":
speech =
'<speak>Today is <say-as interpret-as="date" format="dmy" detail="1">16-12-2017</say-as></speak>';
break;
case "time":
speech =
'<speak>It is <say-as interpret-as="time" format="hms12">2:30pm</say-as> now</speak>';
break;
case "telephone one":
speech =
'<speak><say-as interpret-as="telephone" format="91">09012345678</say-as> </speak>';
break;
case "telephone two":
speech =
'<speak><say-as interpret-as="telephone" format="1">(781) 771-7777</say-as> </speak>';
break;
// https://www.w3.org/TR/2005/NOTE-ssml-sayas-20050526/#S3.3
case "alternate":
speech =
'<speak>IPL stands for <sub alias="indian premier league">IPL</sub></speak>';
break;
}
return res.json({
speech: speech,
displayText: speech,
source: "webhook-echo-sample"
});
});
restService.post("/video", function(req, res) {
return res.json({
speech:
'<speak> <audio src="https://www.youtube.com/watch?v=VX7SSnvpj-8">did not get your MP3 audio file</audio></speak>',
displayText:
'<speak> <audio src="https://www.youtube.com/watch?v=VX7SSnvpj-8">did not get your MP3 audio file</audio></speak>',
source: "webhook-echo-sample"
});
});
restService.post("/slack-test", function(req, res) {
var slack_message = {
text: "Details of JIRA board for Browse and Commerce",
attachments: [
{
title: "JIRA Board",
title_link: "http://www.google.com",
color: "#36a64f",
fields: [
{
title: "Epic Count",
value: "50",
short: "false"
},
{
title: "Story Count",
value: "40",
short: "false"
}
],
thumb_url:
"https://stiltsoft.com/blog/wp-content/uploads/2016/01/5.jira_.png"
},
{
title: "Story status count",
title_link: "http://www.google.com",
color: "#f49e42",
fields: [
{
title: "Not started",
value: "50",
short: "false"
},
{
title: "Development",
value: "40",
short: "false"
},
{
title: "Development",
value: "40",
short: "false"
},
{
title: "Development",
value: "40",
short: "false"
}
]
}
]
};
return res.json({
speech: "speech",
displayText: "speech",
source: "webhook-echo-sample",
data: {
slack: slack_message
}
});
});
restService.get('/', function (req, res) {
res.send('Hello World');
})
var port = process.env.PORT || 8000
restService.listen(port, function() {
console.log("Server up and listening");
});