This repository has been archived by the owner on Nov 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.js
63 lines (50 loc) · 2.25 KB
/
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
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
______ ______ ______ __ __ __ ______
/\ == \ /\ __ \ /\__ _\ /\ \/ / /\ \ /\__ _\
\ \ __< \ \ \/\ \ \/_/\ \/ \ \ _"-. \ \ \ \/_/\ \/
\ \_____\ \ \_____\ \ \_\ \ \_\ \_\ \ \_\ \ \_\
\/_____/ \/_____/ \/_/ \/_/\/_/ \/_/ \/_/
This is a sample Google Hangouts Chat bot built with Botkit.
# RUN THE BOT :
Follow the instructions here to set up your Facebook app and page:
-> https://developers.google.com/hangouts/chat/how-tos/bots-publish
Run your bot from the command line:
DEBUG=botkit:* \
PORT=YOUR_APP_PORT \
GOOGLE_APPLICATION_CREDENTIALS=YOUR_GOOGLE_CREDENTIALS_FILE \
GOOGLE_VERIFICATION_TOKEN=YOUR_GOOGLE_VERIFICATION_TOKEN \
node bot.js
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
const env = require('node-env-file');
env(__dirname + '/.env');
let google_auth_params = {}
if(process.env.GOOGLE_APPLICATION_CREDENTIALS_DATA) {
// Handle json file as a environement variable for Heroku like systems
google_auth_params = {
credentials: JSON.parse(process.env.GOOGLE_APPLICATION_CREDENTIALS_DATA)
}
}
else if (!process.env.GOOGLE_APPLICATION_CREDENTIALS && !process.env.GOOGLE_APPLICATION_CREDENTIALS_DATA) {
console.log('Error: Specify a GOOGLE_APPLICATION_CREDENTIALS or GOOGLE_APPLICATION_CREDENTIALS_DATA in environment.');
process.exit(1);
}
const Botkit = require('botkit')
const mongoStorage = require('botkit-storage-mongo')({mongoUri: process.env.MONGO_URL || 'mongodb://localhost/bb'})
const endpoint = "receive";
const token = process.env.GOOGLE_VERIFICATION_TOKEN;
const port = process.env.PORT || 3000;
const debug = true;
const controller = Botkit.googlehangoutsbot({
endpoint,
token,
port,
debug,
storage: mongoStorage,
google_auth_params: google_auth_params
});
const bot = controller.spawn({});
const webserver = require(__dirname + '/components/express_webserver.js')(controller, bot);
const normalizedPath = require("path").join(__dirname, "skills");
require("fs").readdirSync(normalizedPath).forEach(function(file) {
require("./skills/" + file)(controller);
});