-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.js
More file actions
237 lines (150 loc) · 5.3 KB
/
app.js
File metadata and controls
237 lines (150 loc) · 5.3 KB
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
var Botkit = require('botkit');
var os = require('os');
var komponist = require('komponist');
var request = require('request');
var sys = require('sys')
var exec = require('child_process').exec;
var token = require('./token.js');
const playlistStore = []
// Connect to slack
var controller = Botkit.slackbot({
debug: false,
});
var bot = controller.spawn({
token: token.sparkplug
}).startRTM(function(err, bot, payload){
if(err) {
console.log(err);
throw new Error('Could not connect to slack');
}
});
var client = komponist.createConnection(6600, 'localhost', function() {
console.log('client created')
});
//a sample knowledgebaseObject that should persist on a DB come from DB per customer
var knowledgebaseObject = {
customerName: 'Comfort Chefs',
helpKeyword: 'help',
customerID: 12631616216321,
address: '16 Brookers Lane',
optionList:'\n 1. Give Feedback \n 2. Contact Information \n 3. Services \n 4. Talk to Someone',
welcomeMessage: function(name) {
return "Hi "+ name +", my name is Funke, I'm a bot, Welcome to "+ this.customerName +" You can say '"+ this.helpKeyword +"' anytime to get a list of things I can assist you with."
},
menuObject: {
hoursOfOperation: [ 'Weekdays: 10am - 7pm | Weekends: 11am - 8pm'],
faq: [
{
question: 'What time is faq',
answer: ' Sample answer'
},
{
question: 'Sample faq',
answer: ' Sample answer'
}
]
}
};
controller.hears('help', ['direct_message','direct_mention','mention'],function(bot,message) {
bot.startConversation(message, function(err, convo){
convo.addQuestion(knowledgebaseObject.optionList, function(response, convo){
convo.say('you picked ' + response.text)
})
})
});
controller.hears('hello',['direct_message','direct_mention','mention'],function(bot,message) {
// start a conversation to handle this response.
bot.startConversation(message,function(err,convo) {
convo.addQuestion('What is your name', function(response,convo) {
convo.say('Cool, you said: ' + response.text);
convo.say(knowledgebaseObject.welcomeMessage(response.text));
convo.say(knowledgebaseObject.menuObject)
convo.next();
},{},'default');
// convo.say(knowledgebaseObject.welcomeMessage);
// convo.say(knowledgebaseObject.welcomeMessage);
})
// client.currentsong(function(err, info) {
// console.log(info.Artist);
// console.log(info.Title);
// console.log(info.Album);
// var nowPlaying = info.file
// nowPlaying = nowPlaying.replace(/.mp3/g, '');
// var reply_with_attachments = {
// 'attachments': [
// {
// 'fallback': 'Now Playing attachments',
// 'title': 'Now Playing' + '\n' + 'Stream link - http://158.85.113.45:7500',
// "fields": [
// {
// "title": nowPlaying,
// "short": false
// }
// ],
// 'color': '#7CD197'
// }
// ],
// 'icon_url': 'http://southpawgroup.com/gidiloungeart/images/albums_thumbnail/Untitled.jpg'
// }
// });
// MPD playlist
// client.playlist(function(err, info) {
// console.log(info)
// })
});
// //search request
// controller.hears('search',['direct_message', 'direct_mention', 'mention'], function(bot, message) {
// var str = message.text;
// //remove search keyword
// var newStr = str.replace(/search/i, '');
// //remove whitespace
// newStr = newStr.replace(/ /i,'');
// console.log(newStr);
// var bashCommand = './runyoutube.sh ' + '\'' + newStr + '\'';
// dir = exec(bashCommand, function(err, stdout, stderr) {
// if (err) {
// // should have err.code here?
// }
// //bot.reply(message, stdout )
// console.log(stdout);
// });
// dir.on('exit', function (code) {
// // exit code is code
// bot.reply(message, 'Song Added to Queue' )
// });
// //bot.reply(message, newStr )
// var sendSearch = function(searchterm){
// var options = {
// url: 'http://gplayer.herokuapp.com/api/search?q='+searchterm,
// headers: {
// 'Accept': 'application/json',
// 'Content-Type': 'application/json',
// }
// }
// console.log('making network request')
// }
// })
controller.hears('list',['direct_message', 'direct_mention', 'mention'], function(bot, message) {
str = message.text;
client.playlist(function(err, info){
info = info.toString();
var reply_with_attachments = {
'attachments': [
{
'fallback': 'List of songs in Playlist',
'title': 'Playlist',
'text': info,
"fields": [
{
"Song 1": 'test',
"short": false
}
],
'color': '#7CD197'
}
],
'icon_url': 'http://southpawgroup.com/gidiloungeart/images/albums_thumbnail/Untitled.jpg'
}
bot.reply(message, reply_with_attachments);
})
})