forked from howdyai/botkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spark_bot.js
104 lines (75 loc) · 3.46 KB
/
spark_bot.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
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
______ ______ ______ __ __ __ ______
/\ == \ /\ __ \ /\__ _\ /\ \/ / /\ \ /\__ _\
\ \ __< \ \ \/\ \ \/_/\ \/ \ \ _"-. \ \ \ \/_/\ \/
\ \_____\ \ \_____\ \ \_\ \ \_\ \_\ \ \_\ \ \_\
\/_____/ \/_____/ \/_/ \/_/\/_/ \/_/ \/_/
This is a sample Cisco Spark bot built with Botkit.
This bot demonstrates many of the core features of Botkit:
* Connect to Cisco Spark's APIs
* Receive messages based on "spoken" patterns
* Reply to messages
* Use the conversation system to ask questions
* Use the built in storage system to store and retrieve information
for a user.
# EXTEND THE BOT:
Botkit has many features for building cool and useful bots!
Read all about it here:
-> http://botkit.ai
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
var Botkit = require('./lib/Botkit.js');
var controller = Botkit.sparkbot({
debug: false,
log: false,
public_address: process.env.public_address,
ciscospark_access_token: process.env.access_token,
studio_token: process.env.studio_token, // get one from studio.botkit.ai to enable content management, stats, message console and more
secret: process.env.secret, // this is an RECOMMENDED but optional setting that enables validation of incoming webhooks
webhook_name: 'Cisco Spark bot created with Botkit, override me before going to production',
// limit_to_domain: ['mycompany.com'],
// limit_to_org: 'my_cisco_org_id',
});
var bot = controller.spawn({});
controller.setupWebserver(process.env.PORT || 3000, function(err, webserver) {
controller.createWebhookEndpoints(webserver, bot, function() {
console.log("Cisco Spark: Webhooks set up!");
});
});
controller.middleware.receive.use(function(bot, message, next) {
console.log(message);
next();
});
controller.hears(['^markdown'], 'direct_message,direct_mention', function(bot, message) {
bot.reply(message, {text: '*this is cool*', markdown: '*this is super cool*'});
});
controller.on('user_space_join', function(bot, message) {
bot.reply(message, 'Welcome, ' + message.original_message.data.personDisplayName);
});
controller.on('user_space_leave', function(bot, message) {
bot.reply(message, 'Bye, ' + message.original_message.data.personDisplayName);
});
controller.on('bot_space_join', function(bot, message) {
bot.reply(message, 'This trusty bot is here to help.');
});
controller.on('direct_mention', function(bot, message) {
bot.reply(message, 'You mentioned me and said, "' + message.text + '"');
});
controller.on('direct_message', function(bot, message) {
bot.reply(message, 'I got your private message. You said, "' + message.text + '"');
if (message.original_message.files) {
bot.retrieveFileInfo(message.original_message.files[0], function(err, file) {
bot.reply(message,'I also got an attached file called ' + file.filename);
});
}
});
if (process.env.studio_token) {
controller.on('direct_message,direct_mention', function(bot, message) {
controller.studio.runTrigger(bot, message.text, message.user, message.channel).then(function(convo) {
if (!convo) {
// console.log('NO STUDIO MATCH');
}
}).catch(function(err) {
console.error('Error with Botkit Studio: ', err);
});
});
}