forked from howdyai/botkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslackbutton_slashcommand.js
executable file
·77 lines (51 loc) · 2.26 KB
/
slackbutton_slashcommand.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
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
______ ______ ______ __ __ __ ______
/\ == \ /\ __ \ /\__ _\ /\ \/ / /\ \ /\__ _\
\ \ __< \ \ \/\ \ \/_/\ \/ \ \ _"-. \ \ \ \/_/\ \/
\ \_____\ \ \_____\ \ \_\ \ \_\ \_\ \ \_\ \ \_\
\/_____/ \/_____/ \/_/ \/_/\/_/ \/_/ \/_/
This is a sample Slack Button application that provides a custom
Slash command.
This bot demonstrates many of the core features of Botkit:
*
* Authenticate users with Slack using OAuth
* Receive messages using the slash_command event
* Reply to Slash command both publicly and privately
# RUN THE BOT:
Create a Slack app. Make sure to configure at least one Slash command!
-> https://api.slack.com/applications/new
Run your bot from the command line:
clientId=<my client id> clientSecret=<my client secret> port=3000 node bot.js
Note: you can test your oauth authentication locally, but to use Slash commands
in Slack, the app must be hosted at a publicly reachable IP or host.
# EXTEND THE BOT:
Botkit has many features for building cool and useful bots!
Read all about it here:
-> http://howdy.ai/botkit
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
var Botkit = require('../lib/Botkit.js');
if (!process.env.clientId || !process.env.clientSecret || !process.env.port) {
console.log('Error: Specify clientId clientSecret and port in environment');
process.exit(1);
}
var controller = Botkit.slackbot({
json_file_store: './db_slackbutton_slashcommand/',
}).configureSlackApp({
clientId: process.env.clientId,
clientSecret: process.env.clientSecret,
scopes: ['commands'],
});
controller.setupWebserver(process.env.port,function(err,webserver) {
controller.createWebhookEndpoints(controller.webserver);
controller.createOauthEndpoints(controller.webserver,function(err,req,res) {
if (err) {
res.status(500).send('ERROR: ' + err);
} else {
res.send('Success!');
}
});
});
controller.on('slash_command',function(bot,message) {
bot.replyPublic(message,'<@' + message.user + '> is cool!');
bot.replyPrivate(message,'*nudge nudge wink wink*');
});