forked from BeepBoopHQ/in-or-out
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
59 lines (49 loc) · 1.47 KB
/
server.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
'use strict'
const express = require('express')
const Slapp = require('slapp')
const BeepBoopConvoStore = require('slapp-convo-beepboop')
const BeepBoopContext = require('slapp-context-beepboop')
const BeepBoopPersist = require('beepboop-persist')
const Chronos = require('./src/chronos')
const config = require('./src/config').validate()
const connectApi = require('./src/api')();
var slapp = Slapp({
verify_token: config.slack_verify_token,
log: config.slapp_log,
colors: config.slapp_colors,
record: 'out.jsonl',
convo_store: BeepBoopConvoStore(),
context: BeepBoopContext()
})
var server = slapp.attachToExpress(express())
var app = {
slapp,
server,
kv: BeepBoopPersist({ provider: config.persist_provider }),
chronos: Chronos({
beepboop_token: config.beepboop_token,
beepboop_project_id: config.beepboop_project_id
})
}
//connect to api and set authentication
connectApi((err, api, token)=>{
//if err occurs then set api to false so that we can return the error to slack when the bot tries to access the api;
if(err){
app.api = false;
app.apiError = err;
console.log(err);
}
else{
app.api = api;
app.token = token;
}
require('./src/flows')(app)
server.get('/', function (req, res) {
res.send('Hello')
})
server.get('/healthz', function (req, res) {
res.send({ version: process.env.VERSION, id: process.env.BEEPBOOP_ID })
})
console.log('Listening on :' + config.port)
server.listen(config.port)
})