-
Notifications
You must be signed in to change notification settings - Fork 0
/
luis_bot.js
117 lines (79 loc) · 3.33 KB
/
luis_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
105
106
107
108
109
110
111
112
113
114
115
116
117
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
______ ______ ______ __ __ __ ______
/\ == \ /\ __ \ /\__ _\ /\ \/ / /\ \ /\__ _\
\ \ __< \ \ \/\ \ \/_/\ \/ \ \ _"-. \ \ \ \/_/\ \/
\ \_____\ \ \_____\ \ \_\ \ \_\ \_\ \ \_\ \ \_\
\/_____/ \/_____/ \/_/ \/_/\/_/ \/_/ \/_/
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
* Send a message with attachments
* Send a message via direct message (instead of in a public channel)
# 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> serviceUri=<LUIS_SERVICE_URI>node demo_bot.js
# USE THE BOT:
Find your bot inside Slack to send it a direct message.
Say: "Hello"
The bot will reply "Hello!"
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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
var env = require('node-env-file');
if (process.env.NODE_ENV === 'production') {
env(__dirname + '/.env_production');
} else {
env(__dirname + '/.env');
}
//Log Helper
const logUtil = require("./util/logUtil");
var Botkit = require('botkit');
var debug = require('debug')('botkit:main');
var botkitStoragePostgres = require('./node_modules/botkit-storage-postgres');
var bot_options = {
replyWithTyping: true,
storage: botkitStoragePostgres({
host: process.env.BOTKIT_STORAGE_POSTGRES_HOST,
port: process.env.BOTKIT_STORAGE_POSTGRES_PORT,
user: process.env.BOTKIT_STORAGE_POSTGRES_USER,
password: process.env.BOTKIT_STORAGE_POSTGRES_PASSWORD,
database: process.env.BOTKIT_STORAGE_POSTGRES_DATABASE
})
};
//Localization
// Source: https://github.com/noveogroup-amorgunov/localizify
const localizify = require('./node_modules/localizify');
const de = require('./localization/de');
localizify
.add('de', de)
.setLocale('de');
var luis = require('./node_modules/botkit-middleware-luis/src/luis-middleware');
if (!process.env.SERVICEURI) {
logUtil.error('Error: Specify Luis service uri');
process.exit(1);
}
var luisOptions = {serviceUri: process.env.SERVICEURI};
// Create the Botkit controller, which controls all instances of the bot.
var controller = Botkit.socketbot(bot_options);
// Set up an Express-powered webserver to expose oauth and webhook endpoints
var webserver = require(__dirname + '/components/express_webserver.js')(controller);
// Open the web socket server
controller.openSocketServer(controller.httpserver);
//Add Luis Middleware to controller
controller.middleware.receive.use(luis.middleware.receive(luisOptions));
// Start the bot brain in motion!!
controller.startTicking();
var fs = require("fs")
var normalizedPath = require("path").join(__dirname, "skills")
fs.readdirSync(normalizedPath).forEach(function(file) {
if (!fs.lstatSync("./skills/" + file).isDirectory()) {
require("./skills/" + file)(controller)
}
})
logUtil.info('I AM ONLINE! COME TALK TO ME: http://localhost:' + (process.env.PORT || 3000));