/
index.ts
executable file
·47 lines (38 loc) · 1.08 KB
/
index.ts
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
import 'bluebird-global'
import { SDK } from 'botpress'
import _ from 'lodash'
import Analytics from './analytics'
import api from './api'
import setup from './setup'
import { AnalyticsByBot } from './typings'
const analyticsByBot: AnalyticsByBot = {}
const interactionsToTrack = ['message', 'text', 'button', 'template', 'quick_reply', 'postback']
const onServerStarted = async (bp: SDK) => {
await setup(bp, interactionsToTrack)
}
const onServerReady = async (bp: SDK) => {
await api(bp, analyticsByBot)
}
const onBotMount = async (bp: SDK, botId: string) => {
const analytics = new Analytics(bp, botId)
analyticsByBot[botId] = analytics
await analytics.start()
}
const onBotUnmount = async (bp: SDK, botId: string) => {
await analyticsByBot[botId].stop()
delete analyticsByBot[botId]
}
const entryPoint: SDK.ModuleEntryPoint = {
onServerStarted,
onServerReady,
onBotMount,
onBotUnmount,
definition: {
name: 'analytics',
fullName: 'Analytics',
homepage: 'https://botpress.io',
menuIcon: 'timeline',
menuText: 'Analytics'
}
}
export default entryPoint