-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
97 lines (73 loc) · 2.69 KB
/
index.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
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
______ ______ ______ __ __ __ ______
/\ == \ /\ __ \ /\__ _\ /\ \/ / /\ \ /\__ _\
\ \ __< \ \ \/\ \ \/_/\ \/ \ \ _"-. \ \ \ \/_/\ \/
\ \_____\ \ \_____\ \ \_\ \ \_\ \_\ \ \_\ \ \_\
\/_____/ \/_____/ \/_/ \/_/\/_/ \/_/ \/_/
This is a sample Slack bot built with Botkit.
This bot demonstrates many of the core features of Botkit:
* Connect to Slack using the real time API
* 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.
# RUN THE BOT:
Get a Bot token from Slack:
-> http://my.slack.com/services/new/bot
Run your bot from the command line:
token=<MY TOKEN> node slack_bot.js
# USE THE BOT:
Find your bot inside Slack to send it a direct message.
Say: "Hello"
The bot will reply "Hello!"
Say: "who are you?"
The bot will tell you its name, where it is running, and for how long.
Say: "Call me <nickname>"
Tell the bot your nickname. Now you are friends.
Say: "who am I?"
The bot will tell you your nickname, if it knows one for you.
Say: "shutdown"
The bot will ask if you are sure, and then shut itself down.
Make sure to invite your bot into other channels using /invite @<my bot>!
# EXTEND THE BOT:
Botkit has many features for building cool and useful bots!
Read all about it here:
-> http://howdy.ai/botkit
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
const general = 'C77B7UY80'
if (!process.env.token) {
console.log('Error: Specify token in environment')
process.exit(1)
}
const Botkit = require('botkit')
const format = require('./format')
var controller = Botkit.slackbot({
debug: true,
json_file_store: './db',
retry: Infinity,
})
var bot = controller.spawn({
token: process.env.token
}).startRTM()
/**********
* Commands
**********/
const statsCommand = require('./commands/stats')
const earningsCommand = require('./commands/earnings')
const valueCommand = require('./commands/value')
const walletCommand = require('./commands/wallet')
/*********
* Chatter
*********/
const random = require('./commands/random')
const support = require('./commands/support')
const jokeCommand = require('./commands/joke')
support.init(controller)
jokeCommand.init(controller)
random.init(controller)
statsCommand.init(controller, general)
earningsCommand.init(controller, general)
valueCommand.init(controller, general)
walletCommand.init(controller, general)
jokeCommand.init(controller)