@botonic/plugin-hubtype-analytics 0.22.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # Botonic Plugin Hubtype Analytics
2
+
3
+ ## What Does This Plugin Do?
4
+
5
+ This plugin allows you to integrate Hubtype Analytics in your Botonic project.
6
+
7
+ ## Setup
8
+
9
+ 1. Install the plugin from npm (or yarn):
10
+
11
+ ```
12
+ npm i --save @botonic/plugin-hubtype-analytics
13
+ ```
14
+
15
+ 2. Add it to the `src/plugins.js` file defining the projectId of the Project you want to use:
16
+
17
+ ```
18
+ export const plugins = [
19
+ {
20
+ id: 'hubtype-analytics',
21
+ resolve: require('@botonic/plugin-hubtype-analytics'),
22
+ options: {
23
+ baseUrl: https://api.hubtype.com,
24
+ },
25
+ },
26
+ ]
27
+ ```
28
+
29
+ ## Use
30
+
31
+ You can use it in your actions for example an event to check that a faq has been displayed in the bot:
32
+
33
+ ```
34
+ const hubtypeAnalyticsPlugin = request.plugins.hubtypeAnalytics
35
+ const eventBotFaq = {
36
+ event_type: EventName.botFaq
37
+ event_data: { enduser_language: 'en', faq_name: 'orders_and_deliveries' }
38
+ }
39
+ try {
40
+ const response = await hubtypeAnalyticsPlugin.trackEvent(request, event)
41
+ console.log(response)
42
+ } catch(error) {
43
+ console.log(error)
44
+ }
45
+
46
+ ```
47
+
48
+ ## Plugin Options
49
+
50
+ - **`baseUrl`**: baseUrl to the envirment https://api.hubtype.com for production
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@botonic/plugin-hubtype-analytics",
3
+ "version": "0.22.0-alpha.2",
4
+ "description": "Plugin for tracking in the Hubtype backend to see the results in the Hubtype Dashbord",
5
+ "main": "./lib/cjs/index.js",
6
+ "module": "./lib/esm/index.js",
7
+ "scripts": {
8
+ "build": "rm -rf lib && ../../node_modules/.bin/tsc -p tsconfig.json && ../../node_modules/.bin/tsc -p tsconfig.esm.json",
9
+ "build:watch": "npm run build -- --watch",
10
+ "test": "echo \"Error: no test specified\" && exit 1",
11
+ "prepublishOnly": "rm -rf lib && npm run build",
12
+ "lint": "npm run lint_core -- --fix",
13
+ "lint_ci": "npm run lint_core -- -c ../.eslintrc_slow.js",
14
+ "lint_core": "../../node_modules/.bin/eslint_d --cache --quiet 'src/**/*.ts*'"
15
+ },
16
+ "keywords": [
17
+ "analytics",
18
+ "bot-framework",
19
+ "chatbot",
20
+ "conversational-app",
21
+ "conversational-ui",
22
+ "javascript",
23
+ "typescript"
24
+ ],
25
+ "author": "Hubtype",
26
+ "license": "MIT",
27
+ "dependencies": {
28
+ "@babel/runtime": "^7.21.0",
29
+ "@botonic/core": "^0.22.0",
30
+ "@types/axios": "^0.14.0",
31
+ "axios": "^1.4.0"
32
+ },
33
+ "eslintConfig": {
34
+ "extends": "../.eslintrc.js",
35
+ "root": true
36
+ },
37
+ "devDependencies": {
38
+ "@types/node": "^16.11.7",
39
+ "@types/react": "^16.14.0",
40
+ "typescript": "^4.8.4"
41
+ }
42
+ }
package/src/index.ts ADDED
@@ -0,0 +1,43 @@
1
+ import { BotRequest, Plugin } from '@botonic/core'
2
+ import axios from 'axios'
3
+
4
+ import { HtEvent } from './types'
5
+
6
+ export interface HubtypeAnalyticsOptions {
7
+ baseUrl: string
8
+ }
9
+
10
+ export default class BotonicPluginHubtypeAnalytics implements Plugin {
11
+ baseUrl: string
12
+ constructor(options: HubtypeAnalyticsOptions) {
13
+ this.baseUrl = options.baseUrl
14
+ }
15
+
16
+ pre(): void {
17
+ return
18
+ }
19
+
20
+ post(): void {
21
+ return
22
+ }
23
+
24
+ getUrl(request: BotRequest) {
25
+ return `${this.baseUrl}/external/v1/conversational_apps/${request.session.bot.id}/bot_event/`
26
+ }
27
+
28
+ async trackEvent(request: BotRequest, event: HtEvent) {
29
+ const url = this.getUrl(request)
30
+ const data = {
31
+ chat: request.session.user.id,
32
+ event_type: event.event_type,
33
+ event_data: {
34
+ ...event.event_data,
35
+ event_datetime: new Date().toISOString(),
36
+ channel: request.session.user.provider,
37
+ },
38
+ }
39
+ const headers = { Authorization: `Bearer ${request.session._access_token}` }
40
+ const config = { headers }
41
+ return axios.post(url, data, config)
42
+ }
43
+ }
package/src/types.ts ADDED
@@ -0,0 +1,123 @@
1
+ export enum EventName {
2
+ botAgentRating = 'bot_agent_rating',
3
+ botChannelRating = 'bot_channel_rating',
4
+ botFaqUseful = 'bot_faq_useful',
5
+ botRating = 'bot_rating',
6
+ botFaq = 'bot_faq',
7
+ botStart = 'bot_start',
8
+ botOpen = 'bot_open',
9
+ botAiModel = 'bot_ai_model',
10
+ botKeywordsModel = 'bot_keywords_model',
11
+ fallback = 'fallback',
12
+ handoffOption = 'handoff_option',
13
+ handoffSuccess = 'handoff_success',
14
+ handoffFail = 'handoff_fail',
15
+ }
16
+
17
+ interface EventData {
18
+ enduser_country?: string
19
+ enduser_language: string
20
+ format_version?: number
21
+ bot_version?: string
22
+ flow_version?: string
23
+ }
24
+
25
+ export interface EventAgentRating {
26
+ event_type: EventName.botAgentRating
27
+ event_data: EventData & { rating: number }
28
+ }
29
+
30
+ export interface EventChannelRating {
31
+ event_type: EventName.botChannelRating
32
+ event_data: EventData & { rating: number }
33
+ }
34
+
35
+ export interface EventFaqUseful {
36
+ event_type: EventName.botFaqUseful
37
+ event_data: EventData & { faq_name: string; useful: boolean }
38
+ }
39
+
40
+ export interface EventBotRating {
41
+ event_type: EventName.botRating
42
+ event_data: EventData & {
43
+ faq_name: string
44
+ useful: boolean
45
+ rating: number
46
+ free_comment: string
47
+ selected_options: string[]
48
+ }
49
+ }
50
+
51
+ export interface EventBotFaq {
52
+ event_type: EventName.botFaq
53
+ event_data: EventData & { faq_name: string }
54
+ }
55
+
56
+ export interface EventBotStart {
57
+ event_type: EventName.botStart
58
+ event_data: EventData
59
+ }
60
+
61
+ export interface EventBotOpen {
62
+ event_type: EventName.botOpen
63
+ event_data: EventData
64
+ }
65
+
66
+ export interface EventBotAiModel {
67
+ event_type: EventName.botAiModel
68
+ event_data: EventData & {
69
+ intent: string
70
+ confidence: number
71
+ confidence_successful: boolean
72
+ }
73
+ }
74
+
75
+ export interface EventBotKeywordModel {
76
+ event_type: EventName.botKeywordsModel
77
+ event_data: EventData & {
78
+ confidence_successful: boolean
79
+ }
80
+ }
81
+
82
+ export interface EventFallback {
83
+ event_type: EventName.fallback
84
+ event_data: EventData
85
+ }
86
+
87
+ export interface EventHandoffOption {
88
+ event_type: EventName.handoffOption
89
+ event_data: EventData
90
+ }
91
+
92
+ export interface EventHandoffSuccess {
93
+ event_type: EventName.handoffSuccess
94
+ event_data: EventData & {
95
+ queue_open: boolean
96
+ available_agents: boolean
97
+ threshold_reached: boolean
98
+ }
99
+ }
100
+
101
+ export interface EventHandoffFail {
102
+ event_type: EventName.handoffFail
103
+ event_data: EventData & {
104
+ queue_open: boolean
105
+ available_agents: boolean
106
+ threshold_reached: boolean
107
+ }
108
+ }
109
+
110
+ export type HtEvent =
111
+ | EventAgentRating
112
+ | EventChannelRating
113
+ | EventFaqUseful
114
+ | EventBotRating
115
+ | EventBotFaq
116
+ | EventBotStart
117
+ | EventBotOpen
118
+ | EventBotAiModel
119
+ | EventBotKeywordModel
120
+ | EventFallback
121
+ | EventHandoffOption
122
+ | EventHandoffSuccess
123
+ | EventHandoffFail
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "include": ["src/"],
4
+ "compilerOptions": {
5
+ "baseUrl": ".",
6
+ "outDir": "./lib/esm",
7
+ "target": "ES2017",
8
+ "module": "ES2020",
9
+ "moduleResolution": "node"
10
+ }
11
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "include": ["src/"],
4
+ "compilerOptions": {
5
+ "jsx": "react",
6
+ "experimentalDecorators": true,
7
+ "baseUrl": ".",
8
+ "outDir": "./lib/cjs",
9
+ "esModuleInterop": true,
10
+ "lib": ["es2015"],
11
+ "skipLibCheck": true
12
+ }
13
+ }