@botonic/core 0.26.0-beta.0 → 0.26.1-alpha.0
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/lib/cjs/core-bot.d.ts +1 -3
- package/lib/cjs/core-bot.js +3 -33
- package/lib/cjs/core-bot.js.map +1 -1
- package/lib/cjs/handoff.d.ts +1 -1
- package/lib/cjs/index.d.ts +0 -1
- package/lib/cjs/index.js +0 -3
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/models/legacy-types.d.ts +44 -40
- package/lib/cjs/models/legacy-types.js +16 -32
- package/lib/cjs/models/legacy-types.js.map +1 -1
- package/lib/cjs/plugins.d.ts +2 -3
- package/lib/cjs/plugins.js +2 -4
- package/lib/cjs/plugins.js.map +1 -1
- package/lib/cjs/utils.d.ts +8 -0
- package/lib/cjs/utils.js +32 -1
- package/lib/cjs/utils.js.map +1 -1
- package/lib/esm/core-bot.d.ts +1 -3
- package/lib/esm/core-bot.js +4 -34
- package/lib/esm/core-bot.js.map +1 -1
- package/lib/esm/handoff.d.ts +1 -1
- package/lib/esm/index.d.ts +0 -1
- package/lib/esm/index.js +0 -3
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/models/legacy-types.d.ts +44 -40
- package/lib/esm/models/legacy-types.js +15 -31
- package/lib/esm/models/legacy-types.js.map +1 -1
- package/lib/esm/plugins.d.ts +2 -3
- package/lib/esm/plugins.js +2 -4
- package/lib/esm/plugins.js.map +1 -1
- package/lib/esm/utils.d.ts +8 -0
- package/lib/esm/utils.js +24 -0
- package/lib/esm/utils.js.map +1 -1
- package/package.json +1 -6
- package/src/core-bot.ts +2 -56
- package/src/handoff.ts +1 -1
- package/src/index.ts +0 -3
- package/src/models/legacy-types.ts +77 -75
- package/src/plugins.ts +2 -8
- package/src/utils.ts +32 -0
- package/lib/cjs/data-provider/dynamodb-data-provider.d.ts +0 -26
- package/lib/cjs/data-provider/dynamodb-data-provider.js +0 -107
- package/lib/cjs/data-provider/dynamodb-data-provider.js.map +0 -1
- package/lib/cjs/data-provider/dynamodb-utils.d.ts +0 -11
- package/lib/cjs/data-provider/dynamodb-utils.js +0 -121
- package/lib/cjs/data-provider/dynamodb-utils.js.map +0 -1
- package/lib/cjs/data-provider/factory.d.ts +0 -25
- package/lib/cjs/data-provider/factory.js +0 -31
- package/lib/cjs/data-provider/factory.js.map +0 -1
- package/lib/cjs/data-provider/index.d.ts +0 -4
- package/lib/cjs/data-provider/index.js +0 -8
- package/lib/cjs/data-provider/index.js.map +0 -1
- package/lib/cjs/data-provider/local-data-provider.d.ts +0 -26
- package/lib/cjs/data-provider/local-data-provider.js +0 -137
- package/lib/cjs/data-provider/local-data-provider.js.map +0 -1
- package/lib/cjs/output-parser/botonic-output-parser.d.ts +0 -16
- package/lib/cjs/output-parser/botonic-output-parser.js +0 -37
- package/lib/cjs/output-parser/botonic-output-parser.js.map +0 -1
- package/lib/cjs/output-parser/factory.d.ts +0 -4
- package/lib/cjs/output-parser/factory.js +0 -36
- package/lib/cjs/output-parser/factory.js.map +0 -1
- package/lib/cjs/output-parser/index.d.ts +0 -3
- package/lib/cjs/output-parser/index.js +0 -7
- package/lib/cjs/output-parser/index.js.map +0 -1
- package/lib/cjs/output-parser/parsers.d.ts +0 -26
- package/lib/cjs/output-parser/parsers.js +0 -171
- package/lib/cjs/output-parser/parsers.js.map +0 -1
- package/lib/esm/data-provider/dynamodb-data-provider.d.ts +0 -26
- package/lib/esm/data-provider/dynamodb-data-provider.js +0 -103
- package/lib/esm/data-provider/dynamodb-data-provider.js.map +0 -1
- package/lib/esm/data-provider/dynamodb-utils.d.ts +0 -11
- package/lib/esm/data-provider/dynamodb-utils.js +0 -113
- package/lib/esm/data-provider/dynamodb-utils.js.map +0 -1
- package/lib/esm/data-provider/factory.d.ts +0 -25
- package/lib/esm/data-provider/factory.js +0 -27
- package/lib/esm/data-provider/factory.js.map +0 -1
- package/lib/esm/data-provider/index.d.ts +0 -4
- package/lib/esm/data-provider/index.js +0 -5
- package/lib/esm/data-provider/index.js.map +0 -1
- package/lib/esm/data-provider/local-data-provider.d.ts +0 -26
- package/lib/esm/data-provider/local-data-provider.js +0 -133
- package/lib/esm/data-provider/local-data-provider.js.map +0 -1
- package/lib/esm/output-parser/botonic-output-parser.d.ts +0 -16
- package/lib/esm/output-parser/botonic-output-parser.js +0 -33
- package/lib/esm/output-parser/botonic-output-parser.js.map +0 -1
- package/lib/esm/output-parser/factory.d.ts +0 -4
- package/lib/esm/output-parser/factory.js +0 -32
- package/lib/esm/output-parser/factory.js.map +0 -1
- package/lib/esm/output-parser/index.d.ts +0 -3
- package/lib/esm/output-parser/index.js +0 -4
- package/lib/esm/output-parser/index.js.map +0 -1
- package/lib/esm/output-parser/parsers.d.ts +0 -26
- package/lib/esm/output-parser/parsers.js +0 -151
- package/lib/esm/output-parser/parsers.js.map +0 -1
- package/src/data-provider/dynamodb-data-provider.ts +0 -105
- package/src/data-provider/dynamodb-utils.ts +0 -149
- package/src/data-provider/factory.ts +0 -60
- package/src/data-provider/index.ts +0 -4
- package/src/data-provider/local-data-provider.ts +0 -154
- package/src/output-parser/botonic-output-parser.ts +0 -38
- package/src/output-parser/factory.ts +0 -45
- package/src/output-parser/index.ts +0 -3
- package/src/output-parser/parsers.ts +0 -237
package/lib/cjs/core-bot.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Inspector } from './debug';
|
|
2
2
|
import { BotRequest, BotResponse, Locales, ResolvedPlugins, Route, Routes, Session } from './models';
|
|
3
|
-
import { BotonicOutputParser } from './output-parser';
|
|
4
3
|
import { Router } from './routing';
|
|
5
4
|
export interface CoreBotConfig {
|
|
6
5
|
appId?: string;
|
|
@@ -27,9 +26,8 @@ export declare class CoreBot {
|
|
|
27
26
|
router: Router | null;
|
|
28
27
|
routes: Routes;
|
|
29
28
|
theme?: any;
|
|
30
|
-
botonicOutputParser: BotonicOutputParser;
|
|
31
29
|
constructor({ renderer, routes, locales, theme, plugins, appId, defaultTyping, defaultDelay, defaultRoutes, inspector, }: CoreBotConfig);
|
|
32
30
|
getString(id: string, session: Session): string;
|
|
33
31
|
setLocale(locale: string, session: Session): void;
|
|
34
|
-
input({ input, session, lastRoutePath,
|
|
32
|
+
input({ input, session, lastRoutePath, }: BotRequest): Promise<BotResponse>;
|
|
35
33
|
}
|
package/lib/cjs/core-bot.js
CHANGED
|
@@ -2,18 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CoreBot = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const ulid_1 = require("ulid");
|
|
6
5
|
const debug_1 = require("./debug");
|
|
7
6
|
const i18n_1 = require("./i18n");
|
|
8
7
|
const models_1 = require("./models");
|
|
9
|
-
const output_parser_1 = require("./output-parser");
|
|
10
8
|
const plugins_1 = require("./plugins");
|
|
11
9
|
const routing_1 = require("./routing");
|
|
12
10
|
class CoreBot {
|
|
13
11
|
constructor({
|
|
14
12
|
// TODO: Receives dataProvider
|
|
15
13
|
renderer, routes, locales, theme, plugins, appId, defaultTyping, defaultDelay, defaultRoutes, inspector, }) {
|
|
16
|
-
this.botonicOutputParser = new output_parser_1.BotonicOutputParser();
|
|
17
14
|
this.renderer = renderer;
|
|
18
15
|
this.plugins = (0, plugins_1.loadPlugins)(plugins);
|
|
19
16
|
this.theme = theme || {};
|
|
@@ -41,7 +38,7 @@ class CoreBot {
|
|
|
41
38
|
setLocale(locale, session) {
|
|
42
39
|
session.__locale = locale;
|
|
43
40
|
}
|
|
44
|
-
input({ input, session, lastRoutePath,
|
|
41
|
+
input({ input, session, lastRoutePath, }) {
|
|
45
42
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
46
43
|
session = session || {};
|
|
47
44
|
if (!session.__locale)
|
|
@@ -51,20 +48,11 @@ class CoreBot {
|
|
|
51
48
|
input,
|
|
52
49
|
session,
|
|
53
50
|
lastRoutePath,
|
|
54
|
-
dataProvider,
|
|
55
51
|
response: [],
|
|
56
|
-
messageEvents: null,
|
|
57
52
|
};
|
|
58
53
|
}
|
|
59
|
-
const parsedUserEvent = this.botonicOutputParser.parseFromUserInput(input);
|
|
60
|
-
const userId = session.user.id;
|
|
61
|
-
if (dataProvider) {
|
|
62
|
-
// TODO: Next iterations. Review cycle of commited events to DB when messages change their ACK
|
|
63
|
-
// @ts-ignore
|
|
64
|
-
const userEvent = yield dataProvider.saveEvent(Object.assign(Object.assign({}, parsedUserEvent), { userId, eventId: (0, ulid_1.ulid)(), createdAt: new Date().toISOString(), from: models_1.MessageEventFrom.USER, ack: models_1.MessageEventAck.RECEIVED }));
|
|
65
|
-
}
|
|
66
54
|
if (this.plugins) {
|
|
67
|
-
yield (0, plugins_1.runPlugins)(this.plugins, 'pre', input, session, lastRoutePath, undefined
|
|
55
|
+
yield (0, plugins_1.runPlugins)(this.plugins, 'pre', input, session, lastRoutePath, undefined);
|
|
68
56
|
}
|
|
69
57
|
if (this.routes instanceof Function) {
|
|
70
58
|
this.router = new routing_1.Router([
|
|
@@ -87,39 +75,21 @@ class CoreBot {
|
|
|
87
75
|
defaultTyping: this.defaultTyping,
|
|
88
76
|
defaultDelay: this.defaultDelay,
|
|
89
77
|
lastRoutePath,
|
|
90
|
-
dataProvider,
|
|
91
78
|
};
|
|
92
79
|
const response = yield this.renderer({
|
|
93
80
|
request,
|
|
94
81
|
actions: [output.fallbackAction, output.action, output.emptyAction],
|
|
95
82
|
});
|
|
96
|
-
let messageEvents = [];
|
|
97
|
-
try {
|
|
98
|
-
messageEvents = this.botonicOutputParser.xmlToMessageEvents(response);
|
|
99
|
-
}
|
|
100
|
-
catch (e) {
|
|
101
|
-
// Disabling Botonic 1.0 error log for LTS version:
|
|
102
|
-
// console.error(e)
|
|
103
|
-
}
|
|
104
83
|
lastRoutePath = output.lastRoutePath;
|
|
105
84
|
if (this.plugins) {
|
|
106
|
-
yield (0, plugins_1.runPlugins)(this.plugins, 'post', input, session, lastRoutePath, response
|
|
107
|
-
}
|
|
108
|
-
if (dataProvider) {
|
|
109
|
-
// TODO: save bot responses to db and update user with new session and new params
|
|
110
|
-
for (const messageEvent of messageEvents) {
|
|
111
|
-
// @ts-ignore
|
|
112
|
-
const botEvent = yield dataProvider.saveEvent(Object.assign(Object.assign({}, messageEvent), { userId, eventId: (0, ulid_1.ulid)(), createdAt: new Date().toISOString(), from: models_1.MessageEventFrom.BOT, ack: models_1.MessageEventAck.SENT }));
|
|
113
|
-
}
|
|
85
|
+
yield (0, plugins_1.runPlugins)(this.plugins, 'post', input, session, lastRoutePath, response);
|
|
114
86
|
}
|
|
115
87
|
session.is_first_interaction = false;
|
|
116
88
|
return {
|
|
117
89
|
input,
|
|
118
90
|
response,
|
|
119
|
-
messageEvents,
|
|
120
91
|
session,
|
|
121
92
|
lastRoutePath,
|
|
122
|
-
dataProvider,
|
|
123
93
|
};
|
|
124
94
|
});
|
|
125
95
|
}
|
package/lib/cjs/core-bot.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-bot.js","sourceRoot":"","sources":["../../src/core-bot.ts"],"names":[],"mappings":";;;;AAAA
|
|
1
|
+
{"version":3,"file":"core-bot.js","sourceRoot":"","sources":["../../src/core-bot.ts"],"names":[],"mappings":";;;;AAAA,mCAAmC;AACnC,iCAAkC;AAClC,qCASiB;AACjB,uCAAmD;AACnD,uCAAqD;AAcrD,MAAa,OAAO;IAclB,YAAY;IACV,8BAA8B;IAC9B,QAAQ,EACR,MAAM,EACN,OAAO,EACP,KAAK,EACL,OAAO,EACP,KAAK,EACL,aAAa,EACb,YAAY,EACZ,aAAa,EACb,SAAS,GACK;QACd,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,OAAO,GAAG,IAAA,qBAAW,EAAC,OAAO,CAAC,CAAA;QACnC,IAAI,CAAC,KAAK,GAAG,KAAK,IAAI,EAAE,CAAA;QACxB,IAAI,CAAC,aAAa;YAChB,OAAO,aAAa,KAAK,WAAW,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E,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC;aACpE,CAAC,CAAA;YAEF,aAAa,GAAG,MAAM,CAAC,aAAa,CAAA;YACpC,IAAI,IAAI,CAAC,OAAO,EAAE;gBAChB,MAAM,IAAA,oBAAU,EACd,IAAI,CAAC,OAAO,EACZ,MAAM,EACN,KAAK,EACL,OAAO,EACP,aAAa,EACb,QAAQ,CACT,CAAA;aACF;YAED,OAAO,CAAC,oBAAoB,GAAG,KAAK,CAAA;YACpC,OAAO;gBACL,KAAK;gBACL,QAAQ;gBACR,OAAO;gBACP,aAAa;aACd,CAAA;QACH,CAAC;KAAA;CACF;AAhJD,0BAgJC"}
|
package/lib/cjs/handoff.d.ts
CHANGED
package/lib/cjs/index.d.ts
CHANGED
package/lib/cjs/index.js
CHANGED
|
@@ -3,14 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./constants"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./core-bot"), exports);
|
|
6
|
-
// TODO: Review @botonic/react's tree-shaking to remove dataProvider from bundle
|
|
7
|
-
// export * from './data-provider'
|
|
8
6
|
tslib_1.__exportStar(require("./debug"), exports);
|
|
9
7
|
tslib_1.__exportStar(require("./handoff"), exports);
|
|
10
8
|
tslib_1.__exportStar(require("./hubtype-service"), exports);
|
|
11
9
|
tslib_1.__exportStar(require("./i18n"), exports);
|
|
12
10
|
tslib_1.__exportStar(require("./models"), exports);
|
|
13
|
-
tslib_1.__exportStar(require("./output-parser"), exports);
|
|
14
11
|
tslib_1.__exportStar(require("./plugins"), exports);
|
|
15
12
|
tslib_1.__exportStar(require("./routing"), exports);
|
|
16
13
|
tslib_1.__exportStar(require("./utils"), exports);
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,sDAA2B;AAC3B,qDAA0B;AAC1B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,sDAA2B;AAC3B,qDAA0B;AAC1B,kDAAuB;AACvB,oDAAyB;AACzB,4DAAiC;AACjC,iDAAsB;AACtB,mDAAwB;AACxB,oDAAyB;AACzB,oDAAyB;AACzB,kDAAuB"}
|
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export declare enum CASE_STATUS {
|
|
2
|
+
WAITING = "status_waiting",
|
|
3
|
+
ATTENDING = "status_attending",
|
|
4
|
+
IDLE = "status_idle",
|
|
5
|
+
RESOLVED = "status_resolved"
|
|
6
|
+
}
|
|
7
|
+
export type CaseStatusType = CASE_STATUS.ATTENDING | CASE_STATUS.IDLE | CASE_STATUS.RESOLVED | CASE_STATUS.WAITING;
|
|
8
|
+
export declare enum CASE_RESOLUTION {
|
|
9
|
+
OK = "result_ok",
|
|
10
|
+
NOK = "result_nok",
|
|
11
|
+
NOT_SOLVED = "result_not_solved",
|
|
12
|
+
BANNED = "result_banned"
|
|
13
|
+
}
|
|
14
|
+
export type CaseResolution = CASE_RESOLUTION.BANNED | CASE_RESOLUTION.NOK | CASE_RESOLUTION.NOT_SOLVED | CASE_RESOLUTION.OK;
|
|
5
15
|
export declare enum PROVIDER {
|
|
6
16
|
APPLE = "apple",
|
|
7
17
|
DEV = "dev",
|
|
@@ -16,6 +26,7 @@ export declare enum PROVIDER {
|
|
|
16
26
|
WECHAT = "wechat",
|
|
17
27
|
WHATSAPP = "whatsapp"
|
|
18
28
|
}
|
|
29
|
+
export type ProviderType = PROVIDER.DEV | PROVIDER.FACEBOOK | PROVIDER.GENERIC | PROVIDER.INSTAGRAM | PROVIDER.INTERCOM | PROVIDER.SMOOCH | PROVIDER.TELEGRAM | PROVIDER.TWITTER | PROVIDER.WEBCHAT | PROVIDER.WECHAT | PROVIDER.WHATSAPP;
|
|
19
30
|
export declare enum INPUT {
|
|
20
31
|
TEXT = "text",
|
|
21
32
|
POSTBACK = "postback",
|
|
@@ -32,19 +43,8 @@ export declare enum INPUT {
|
|
|
32
43
|
WHATSAPP_TEMPLATE = "whatsapptemplate",
|
|
33
44
|
RAW = "raw",
|
|
34
45
|
CHAT_EVENT = "chatevent",
|
|
35
|
-
WHATSAPP_BUTTON_LIST = "whatsapp-button-list"
|
|
36
|
-
|
|
37
|
-
export declare enum CASE_STATUS {
|
|
38
|
-
WAITING = "status_waiting",
|
|
39
|
-
ATTENDING = "status_attending",
|
|
40
|
-
IDLE = "status_idle",
|
|
41
|
-
RESOLVED = "status_resolved"
|
|
42
|
-
}
|
|
43
|
-
export declare enum CASE_RESOLUTION {
|
|
44
|
-
OK = "result_ok",
|
|
45
|
-
NOK = "result_nok",
|
|
46
|
-
NOT_SOLVED = "result_not_solved",
|
|
47
|
-
BANNED = "result_banned"
|
|
46
|
+
WHATSAPP_BUTTON_LIST = "whatsapp-button-list",
|
|
47
|
+
WHATSAPP_CTA_URL_BUTTON = "whatsapp-cta-url-button"
|
|
48
48
|
}
|
|
49
49
|
export interface Locales {
|
|
50
50
|
[id: string]: string | string[] | Locales;
|
|
@@ -65,7 +65,7 @@ export interface ResolvedPlugin extends Plugin {
|
|
|
65
65
|
config: any;
|
|
66
66
|
}
|
|
67
67
|
export type ResolvedPlugins = Record<string, ResolvedPlugin>;
|
|
68
|
-
export type InputType =
|
|
68
|
+
export type InputType = INPUT.AUDIO | INPUT.BUTTON_MESSAGE | INPUT.CAROUSEL | INPUT.CONTACT | INPUT.CUSTOM | INPUT.DOCUMENT | INPUT.IMAGE | INPUT.LOCATION | INPUT.POSTBACK | INPUT.TEXT | INPUT.VIDEO | INPUT.WEBCHAT_SETTINGS | INPUT.WHATSAPP_TEMPLATE | INPUT.CHAT_EVENT | INPUT.WHATSAPP_BUTTON_LIST | INPUT.WHATSAPP_CTA_URL_BUTTON;
|
|
69
69
|
export interface IntentResult {
|
|
70
70
|
intent: string;
|
|
71
71
|
confidence: number;
|
|
@@ -90,9 +90,21 @@ export interface Input extends Partial<NluResult> {
|
|
|
90
90
|
data?: string;
|
|
91
91
|
path?: string;
|
|
92
92
|
payload?: string;
|
|
93
|
+
referral?: string;
|
|
93
94
|
type: InputType;
|
|
95
|
+
context?: {
|
|
96
|
+
campaign?: Campaign;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
export interface Campaign {
|
|
100
|
+
id: string;
|
|
101
|
+
name: string;
|
|
102
|
+
status: string;
|
|
103
|
+
start_date: string;
|
|
104
|
+
end_date: string;
|
|
105
|
+
bot_path: string;
|
|
106
|
+
template_name: string;
|
|
94
107
|
}
|
|
95
|
-
export type ProviderType = typeof PROVIDER.DEV | typeof PROVIDER.FACEBOOK | typeof PROVIDER.GENERIC | typeof PROVIDER.INSTAGRAM | typeof PROVIDER.INTERCOM | typeof PROVIDER.SMOOCH | typeof PROVIDER.TELEGRAM | typeof PROVIDER.TWITTER | typeof PROVIDER.WEBCHAT | typeof PROVIDER.WECHAT | typeof PROVIDER.WHATSAPP;
|
|
96
108
|
export interface SessionUser {
|
|
97
109
|
id: string;
|
|
98
110
|
username?: string;
|
|
@@ -102,6 +114,11 @@ export interface SessionUser {
|
|
|
102
114
|
imp_id?: string;
|
|
103
115
|
provider_id?: string;
|
|
104
116
|
}
|
|
117
|
+
export interface HubtypeCaseContactReason {
|
|
118
|
+
id: string;
|
|
119
|
+
name: string;
|
|
120
|
+
project_id: string;
|
|
121
|
+
}
|
|
105
122
|
export interface Session {
|
|
106
123
|
bot: {
|
|
107
124
|
id: string;
|
|
@@ -109,15 +126,21 @@ export interface Session {
|
|
|
109
126
|
};
|
|
110
127
|
__locale?: string;
|
|
111
128
|
__retries: number;
|
|
129
|
+
_access_token: string;
|
|
130
|
+
_hubtype_api: string;
|
|
112
131
|
is_first_interaction: boolean;
|
|
113
132
|
last_session?: any;
|
|
114
|
-
organization: string;
|
|
115
133
|
organization_id: string;
|
|
134
|
+
organization: string;
|
|
116
135
|
user: SessionUser;
|
|
136
|
+
_botonic_action?: string;
|
|
117
137
|
_hubtype_case_status?: CaseStatusType;
|
|
138
|
+
_hubtype_case_id?: string;
|
|
118
139
|
_hubtype_case_typification?: string;
|
|
140
|
+
_hubtype_case_contact_reasons?: HubtypeCaseContactReason[];
|
|
119
141
|
_shadowing?: boolean;
|
|
120
|
-
|
|
142
|
+
external?: any;
|
|
143
|
+
zendesk_ticket_id?: string;
|
|
121
144
|
}
|
|
122
145
|
export type InputMatcher = (input: Input) => boolean;
|
|
123
146
|
export type ParamsMatcher = {
|
|
@@ -152,7 +175,6 @@ export interface BotRequest {
|
|
|
152
175
|
input: Input;
|
|
153
176
|
lastRoutePath: RoutePath;
|
|
154
177
|
session: Session;
|
|
155
|
-
dataProvider?: DataProvider;
|
|
156
178
|
}
|
|
157
179
|
/** The response of the bot for the triggered actions, which can be
|
|
158
180
|
* the one matched by the routes, the default action and the retry actions.
|
|
@@ -160,7 +182,6 @@ export interface BotRequest {
|
|
|
160
182
|
* */
|
|
161
183
|
export interface BotResponse extends BotRequest {
|
|
162
184
|
response: any;
|
|
163
|
-
messageEvents: Partial<BotonicEvent>[] | null;
|
|
164
185
|
}
|
|
165
186
|
export interface PluginPreRequest extends BotRequest {
|
|
166
187
|
plugins: ResolvedPlugins;
|
|
@@ -175,23 +196,6 @@ export interface Plugin {
|
|
|
175
196
|
export interface Params {
|
|
176
197
|
[key: string]: any;
|
|
177
198
|
}
|
|
178
|
-
export declare const Providers: Readonly<{
|
|
179
|
-
Messaging: {
|
|
180
|
-
APPLE: string;
|
|
181
|
-
FACEBOOK: string;
|
|
182
|
-
GENERIC: string;
|
|
183
|
-
IMBEE: string;
|
|
184
|
-
INSTAGRAM: string;
|
|
185
|
-
INTERCOM: string;
|
|
186
|
-
SMOOCH_WEB: string;
|
|
187
|
-
SMOOCH: string;
|
|
188
|
-
TELEGRAM: string;
|
|
189
|
-
TWITTER: string;
|
|
190
|
-
WEBCHAT: string;
|
|
191
|
-
WECHAT: string;
|
|
192
|
-
WHATSAPP: string;
|
|
193
|
-
};
|
|
194
|
-
}>;
|
|
195
199
|
export type Nullable<T> = T | null;
|
|
196
200
|
export type Action = Nullable<() => any>;
|
|
197
201
|
export type RoutePath = Nullable<string>;
|
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// TODO: This file contains all the legacy types we had in index.ts. After some refactors, we should be able to get rid of many of them.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
4
|
+
exports.INPUT = exports.PROVIDER = exports.CASE_RESOLUTION = exports.CASE_STATUS = void 0;
|
|
5
|
+
var CASE_STATUS;
|
|
6
|
+
(function (CASE_STATUS) {
|
|
7
|
+
CASE_STATUS["WAITING"] = "status_waiting";
|
|
8
|
+
CASE_STATUS["ATTENDING"] = "status_attending";
|
|
9
|
+
CASE_STATUS["IDLE"] = "status_idle";
|
|
10
|
+
CASE_STATUS["RESOLVED"] = "status_resolved";
|
|
11
|
+
})(CASE_STATUS = exports.CASE_STATUS || (exports.CASE_STATUS = {}));
|
|
12
|
+
var CASE_RESOLUTION;
|
|
13
|
+
(function (CASE_RESOLUTION) {
|
|
14
|
+
CASE_RESOLUTION["OK"] = "result_ok";
|
|
15
|
+
CASE_RESOLUTION["NOK"] = "result_nok";
|
|
16
|
+
CASE_RESOLUTION["NOT_SOLVED"] = "result_not_solved";
|
|
17
|
+
CASE_RESOLUTION["BANNED"] = "result_banned";
|
|
18
|
+
})(CASE_RESOLUTION = exports.CASE_RESOLUTION || (exports.CASE_RESOLUTION = {}));
|
|
5
19
|
var PROVIDER;
|
|
6
20
|
(function (PROVIDER) {
|
|
7
21
|
PROVIDER["APPLE"] = "apple";
|
|
@@ -35,36 +49,6 @@ var INPUT;
|
|
|
35
49
|
INPUT["RAW"] = "raw";
|
|
36
50
|
INPUT["CHAT_EVENT"] = "chatevent";
|
|
37
51
|
INPUT["WHATSAPP_BUTTON_LIST"] = "whatsapp-button-list";
|
|
52
|
+
INPUT["WHATSAPP_CTA_URL_BUTTON"] = "whatsapp-cta-url-button";
|
|
38
53
|
})(INPUT = exports.INPUT || (exports.INPUT = {}));
|
|
39
|
-
var CASE_STATUS;
|
|
40
|
-
(function (CASE_STATUS) {
|
|
41
|
-
CASE_STATUS["WAITING"] = "status_waiting";
|
|
42
|
-
CASE_STATUS["ATTENDING"] = "status_attending";
|
|
43
|
-
CASE_STATUS["IDLE"] = "status_idle";
|
|
44
|
-
CASE_STATUS["RESOLVED"] = "status_resolved";
|
|
45
|
-
})(CASE_STATUS = exports.CASE_STATUS || (exports.CASE_STATUS = {}));
|
|
46
|
-
var CASE_RESOLUTION;
|
|
47
|
-
(function (CASE_RESOLUTION) {
|
|
48
|
-
CASE_RESOLUTION["OK"] = "result_ok";
|
|
49
|
-
CASE_RESOLUTION["NOK"] = "result_nok";
|
|
50
|
-
CASE_RESOLUTION["NOT_SOLVED"] = "result_not_solved";
|
|
51
|
-
CASE_RESOLUTION["BANNED"] = "result_banned";
|
|
52
|
-
})(CASE_RESOLUTION = exports.CASE_RESOLUTION || (exports.CASE_RESOLUTION = {}));
|
|
53
|
-
exports.Providers = Object.freeze({
|
|
54
|
-
Messaging: {
|
|
55
|
-
APPLE: 'apple',
|
|
56
|
-
FACEBOOK: 'facebook',
|
|
57
|
-
GENERIC: 'generic',
|
|
58
|
-
IMBEE: 'imbee',
|
|
59
|
-
INSTAGRAM: 'instagram',
|
|
60
|
-
INTERCOM: 'intercom',
|
|
61
|
-
SMOOCH_WEB: 'smooch_web',
|
|
62
|
-
SMOOCH: 'smooch',
|
|
63
|
-
TELEGRAM: 'telegram',
|
|
64
|
-
TWITTER: 'twitter',
|
|
65
|
-
WEBCHAT: 'webchat',
|
|
66
|
-
WECHAT: 'wechat',
|
|
67
|
-
WHATSAPP: 'whatsapp',
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
54
|
//# sourceMappingURL=legacy-types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"legacy-types.js","sourceRoot":"","sources":["../../../src/models/legacy-types.ts"],"names":[],"mappings":";AAAA,wIAAwI;;;
|
|
1
|
+
{"version":3,"file":"legacy-types.js","sourceRoot":"","sources":["../../../src/models/legacy-types.ts"],"names":[],"mappings":";AAAA,wIAAwI;;;AAExI,IAAY,WAKX;AALD,WAAY,WAAW;IACrB,yCAA0B,CAAA;IAC1B,6CAA8B,CAAA;IAC9B,mCAAoB,CAAA;IACpB,2CAA4B,CAAA;AAC9B,CAAC,EALW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAKtB;AAQD,IAAY,eAKX;AALD,WAAY,eAAe;IACzB,mCAAgB,CAAA;IAChB,qCAAkB,CAAA;IAClB,mDAAgC,CAAA;IAChC,2CAAwB,CAAA;AAC1B,CAAC,EALW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAK1B;AAQD,IAAY,QAaX;AAbD,WAAY,QAAQ;IAClB,2BAAe,CAAA;IACf,uBAAW,CAAA;IACX,iCAAqB,CAAA;IACrB,+BAAmB,CAAA;IACnB,mCAAuB,CAAA;IACvB,iCAAqB,CAAA;IACrB,6BAAiB,CAAA;IACjB,iCAAqB,CAAA;IACrB,+BAAmB,CAAA;IACnB,+BAAmB,CAAA;IACnB,6BAAiB,CAAA;IACjB,iCAAqB,CAAA;AACvB,CAAC,EAbW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAanB;AAeD,IAAY,KAkBX;AAlBD,WAAY,KAAK;IACf,sBAAa,CAAA;IACb,8BAAqB,CAAA;IACrB,wBAAe,CAAA;IACf,wBAAe,CAAA;IACf,wBAAe,CAAA;IACf,8BAAqB,CAAA;IACrB,8BAAqB,CAAA;IACrB,4BAAmB,CAAA;IACnB,yCAAgC,CAAA;IAChC,8BAAqB,CAAA;IACrB,0BAAiB,CAAA;IACjB,6CAAoC,CAAA;IACpC,+CAAsC,CAAA;IACtC,oBAAW,CAAA;IACX,iCAAwB,CAAA;IACxB,sDAA6C,CAAA;IAC7C,4DAAmD,CAAA;AACrD,CAAC,EAlBW,KAAK,GAAL,aAAK,KAAL,aAAK,QAkBhB"}
|
package/lib/cjs/plugins.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BotonicEvent, Input, PluginConfig, ResolvedPlugins, RoutePath, Session } from './models';
|
|
1
|
+
import { Input, PluginConfig, ResolvedPlugins, RoutePath, Session } from './models';
|
|
3
2
|
type PluginMode = 'pre' | 'post';
|
|
4
3
|
export declare function loadPlugins(plugins: PluginConfig<any>[]): ResolvedPlugins;
|
|
5
|
-
export declare function runPlugins(plugins: ResolvedPlugins, mode: PluginMode, input: Input, session: Session, lastRoutePath: RoutePath, response?: string | null
|
|
4
|
+
export declare function runPlugins(plugins: ResolvedPlugins, mode: PluginMode, input: Input, session: Session, lastRoutePath: RoutePath, response?: string | null): Promise<void>;
|
|
6
5
|
export {};
|
package/lib/cjs/plugins.js
CHANGED
|
@@ -21,13 +21,13 @@ function loadPlugins(plugins) {
|
|
|
21
21
|
return _plugins;
|
|
22
22
|
}
|
|
23
23
|
exports.loadPlugins = loadPlugins;
|
|
24
|
-
function runPlugins(plugins, mode, input, session, lastRoutePath, response = null
|
|
24
|
+
function runPlugins(plugins, mode, input, session, lastRoutePath, response = null) {
|
|
25
25
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
26
26
|
for (const key in plugins) {
|
|
27
27
|
const p = yield plugins[key];
|
|
28
28
|
try {
|
|
29
29
|
if (mode === 'pre' && p.pre) {
|
|
30
|
-
yield p.pre({ input, session, lastRoutePath,
|
|
30
|
+
yield p.pre({ input, session, lastRoutePath, plugins });
|
|
31
31
|
}
|
|
32
32
|
if (mode === 'post' && p.post) {
|
|
33
33
|
yield p.post({
|
|
@@ -35,8 +35,6 @@ function runPlugins(plugins, mode, input, session, lastRoutePath, response = nul
|
|
|
35
35
|
session,
|
|
36
36
|
lastRoutePath,
|
|
37
37
|
response,
|
|
38
|
-
messageEvents,
|
|
39
|
-
dataProvider,
|
|
40
38
|
plugins,
|
|
41
39
|
});
|
|
42
40
|
}
|
package/lib/cjs/plugins.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.js","sourceRoot":"","sources":["../../src/plugins.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"plugins.js","sourceRoot":"","sources":["../../src/plugins.ts"],"names":[],"mappings":";;;;AAUA,SAAgB,WAAW,CAAC,OAA4B;IACtD,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAA;IACvB,MAAM,QAAQ,GAAG,EAAE,CAAA;IACnB,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,CAAA;IACpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,aAAa,EAAE,CAAC,EAAE,EAAE;QACtC,MAAM,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;QACzC,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;QAClC,MAAM,MAAM,GAAG,cAAc,CAAC,OAAO,CAAA;QACrC,MAAM,QAAQ,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,CAAA;QACpC,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,GAAG,QAAQ,CAAC,WAAW,CAAC,IAAI,EAAE,CAAA;QAC1D,QAAQ,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAA;QACvB,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,CAAA;QACpB,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,GAAG,OAAO,CAAA;QAC7B,QAAQ,CAAC,EAAE,CAAC,CAAC,IAAI,GAAG,GAAG,QAAQ,CAAC,WAAW,CAAC,IAAI,EAAE,CAAA;KACnD;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC;AAhBD,kCAgBC;AAED,SAAsB,UAAU,CAC9B,OAAwB,EACxB,IAAgB,EAChB,KAAY,EACZ,OAAgB,EAChB,aAAwB,EACxB,WAA0B,IAAI;;QAE9B,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE;YACzB,MAAM,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAA;YAC5B,IAAI;gBACF,IAAI,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,GAAG,EAAE;oBAC3B,MAAM,CAAC,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,CAAC,CAAA;iBACxD;gBACD,IAAI,IAAI,KAAK,MAAM,IAAI,CAAC,CAAC,IAAI,EAAE;oBAC7B,MAAM,CAAC,CAAC,IAAI,CAAC;wBACX,KAAK;wBACL,OAAO;wBACP,aAAa;wBACb,QAAQ;wBACR,OAAO;qBACR,CAAC,CAAA;iBACH;aACF;YAAC,OAAO,CAAC,EAAE;gBACV,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;aACf;SACF;IACH,CAAC;CAAA;AA3BD,gCA2BC"}
|
package/lib/cjs/utils.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Session } from './models/legacy-types';
|
|
1
2
|
export declare const isNode: () => boolean;
|
|
2
3
|
export declare const isBrowser: () => boolean;
|
|
3
4
|
export declare const isMobile: (mobileBreakpoint?: number) => boolean;
|
|
@@ -8,3 +9,10 @@ export declare const params2queryString: (params: {
|
|
|
8
9
|
}) => string;
|
|
9
10
|
export declare const join: (...segments: string[]) => string;
|
|
10
11
|
export declare const dirname: (path: string) => string;
|
|
12
|
+
export declare function isDev(session: Session): boolean;
|
|
13
|
+
export declare function isWebchat(session: Session): boolean;
|
|
14
|
+
export declare function isWhatsapp(session: Session): boolean;
|
|
15
|
+
export declare function isTelegram(session: Session): boolean;
|
|
16
|
+
export declare function isFacebook(session: Session): boolean;
|
|
17
|
+
export declare function isInstagram(session: Session): boolean;
|
|
18
|
+
export declare function isTwitter(session: Session): boolean;
|
package/lib/cjs/utils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dirname = exports.join = exports.params2queryString = exports.cloneObject = exports.isFunction = exports.isMobile = exports.isBrowser = exports.isNode = void 0;
|
|
3
|
+
exports.isTwitter = exports.isInstagram = exports.isFacebook = exports.isTelegram = exports.isWhatsapp = exports.isWebchat = exports.isDev = exports.dirname = exports.join = exports.params2queryString = exports.cloneObject = exports.isFunction = exports.isMobile = exports.isBrowser = exports.isNode = void 0;
|
|
4
|
+
const legacy_types_1 = require("./models/legacy-types");
|
|
4
5
|
const isNode = () => {
|
|
5
6
|
// @ts-ignore
|
|
6
7
|
return typeof IS_NODE !== 'undefined'
|
|
@@ -82,4 +83,34 @@ exports.join = join;
|
|
|
82
83
|
// Trailing slashes are ignored. Leading slash is preserved.
|
|
83
84
|
const dirname = (path) => (0, exports.join)(path, '..');
|
|
84
85
|
exports.dirname = dirname;
|
|
86
|
+
// To check Provider in session
|
|
87
|
+
function isDev(session) {
|
|
88
|
+
return session.user.provider === legacy_types_1.PROVIDER.DEV;
|
|
89
|
+
}
|
|
90
|
+
exports.isDev = isDev;
|
|
91
|
+
function isWebchat(session) {
|
|
92
|
+
// When the provider is DEV should we return true because it is a webchat?
|
|
93
|
+
return session.user.provider === legacy_types_1.PROVIDER.WEBCHAT;
|
|
94
|
+
}
|
|
95
|
+
exports.isWebchat = isWebchat;
|
|
96
|
+
function isWhatsapp(session) {
|
|
97
|
+
return session.user.provider === legacy_types_1.PROVIDER.WHATSAPP;
|
|
98
|
+
}
|
|
99
|
+
exports.isWhatsapp = isWhatsapp;
|
|
100
|
+
function isTelegram(session) {
|
|
101
|
+
return session.user.provider === legacy_types_1.PROVIDER.TELEGRAM;
|
|
102
|
+
}
|
|
103
|
+
exports.isTelegram = isTelegram;
|
|
104
|
+
function isFacebook(session) {
|
|
105
|
+
return session.user.provider === legacy_types_1.PROVIDER.FACEBOOK;
|
|
106
|
+
}
|
|
107
|
+
exports.isFacebook = isFacebook;
|
|
108
|
+
function isInstagram(session) {
|
|
109
|
+
return session.user.provider === legacy_types_1.PROVIDER.INSTAGRAM;
|
|
110
|
+
}
|
|
111
|
+
exports.isInstagram = isInstagram;
|
|
112
|
+
function isTwitter(session) {
|
|
113
|
+
return session.user.provider === legacy_types_1.PROVIDER.TWITTER;
|
|
114
|
+
}
|
|
115
|
+
exports.isTwitter = isTwitter;
|
|
85
116
|
//# sourceMappingURL=utils.js.map
|
package/lib/cjs/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAAA,wDAAyD;AAElD,MAAM,MAAM,GAAG,GAAY,EAAE;IAClC,aAAa;IACb,OAAO,OAAO,OAAO,KAAK,WAAW;QACnC,CAAC,CAAC,aAAa;YACb,OAAO;QACT,CAAC,CAAC,OAAO,OAAO,KAAK,WAAW;YAC5B,OAAO,CAAC,QAAQ,KAAK,IAAI;YACzB,OAAO,CAAC,QAAQ,CAAC,IAAI,KAAK,IAAI,CAAA;AACtC,CAAC,CAAA;AARY,QAAA,MAAM,UAQlB;AAEM,MAAM,SAAS,GAAG,GAAY,EAAE;;IACrC,aAAa;IACb,OAAO,OAAO,UAAU,KAAK,WAAW;QACtC,CAAC,CAAC,aAAa;YACb,UAAU;QACZ,CAAC,CAAC,OAAO,MAAM,KAAK,WAAW;YAC3B,OAAO,MAAM,CAAC,QAAQ,KAAK,WAAW;YACtC,CAAC,CAAA,MAAA,MAAA,MAAM,CAAC,OAAO,0CAAE,QAAQ,0CAAE,IAAI,CAAA,CAAA;AACvC,C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IACxC,0EAA0E;IAC1E,OAAO,OAAO,CAAC,IAAI,CAAC,QAAQ,KAAK,uBAAQ,CAAC,OAAO,CAAA;AACnD,CAAC;AAHD,8BAGC;AAED,SAAgB,UAAU,CAAC,OAAgB;IACzC,OAAO,OAAO,CAAC,IAAI,CAAC,QAAQ,KAAK,uBAAQ,CAAC,QAAQ,CAAA;AACpD,CAAC;AAFD,gCAEC;AAED,SAAgB,UAAU,CAAC,OAAgB;IACzC,OAAO,OAAO,CAAC,IAAI,CAAC,QAAQ,KAAK,uBAAQ,CAAC,QAAQ,CAAA;AACpD,CAAC;AAFD,gCAEC;AAED,SAAgB,UAAU,CAAC,OAAgB;IACzC,OAAO,OAAO,CAAC,IAAI,CAAC,QAAQ,KAAK,uBAAQ,CAAC,QAAQ,CAAA;AACpD,CAAC;AAFD,gCAEC;AAED,SAAgB,WAAW,CAAC,OAAgB;IAC1C,OAAO,OAAO,CAAC,IAAI,CAAC,QAAQ,KAAK,uBAAQ,CAAC,SAAS,CAAA;AACrD,CAAC;AAFD,kCAEC;AAED,SAAgB,SAAS,CAAC,OAAgB;IACxC,OAAO,OAAO,CAAC,IAAI,CAAC,QAAQ,KAAK,uBAAQ,CAAC,OAAO,CAAA;AACnD,CAAC;AAFD,8BAEC"}
|
package/lib/esm/core-bot.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Inspector } from './debug';
|
|
2
2
|
import { BotRequest, BotResponse, Locales, ResolvedPlugins, Route, Routes, Session } from './models';
|
|
3
|
-
import { BotonicOutputParser } from './output-parser';
|
|
4
3
|
import { Router } from './routing';
|
|
5
4
|
export interface CoreBotConfig {
|
|
6
5
|
appId?: string;
|
|
@@ -27,9 +26,8 @@ export declare class CoreBot {
|
|
|
27
26
|
router: Router | null;
|
|
28
27
|
routes: Routes;
|
|
29
28
|
theme?: any;
|
|
30
|
-
botonicOutputParser: BotonicOutputParser;
|
|
31
29
|
constructor({ renderer, routes, locales, theme, plugins, appId, defaultTyping, defaultDelay, defaultRoutes, inspector, }: CoreBotConfig);
|
|
32
30
|
getString(id: string, session: Session): string;
|
|
33
31
|
setLocale(locale: string, session: Session): void;
|
|
34
|
-
input({ input, session, lastRoutePath,
|
|
32
|
+
input({ input, session, lastRoutePath, }: BotRequest): Promise<BotResponse>;
|
|
35
33
|
}
|
package/lib/esm/core-bot.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
|
-
import { ulid } from 'ulid';
|
|
3
2
|
import { Inspector } from './debug';
|
|
4
3
|
import { getString } from './i18n';
|
|
5
|
-
import { INPUT,
|
|
6
|
-
import { BotonicOutputParser } from './output-parser';
|
|
4
|
+
import { INPUT, } from './models';
|
|
7
5
|
import { loadPlugins, runPlugins } from './plugins';
|
|
8
6
|
import { getComputedRoutes, Router } from './routing';
|
|
9
7
|
export class CoreBot {
|
|
10
8
|
constructor({
|
|
11
9
|
// TODO: Receives dataProvider
|
|
12
10
|
renderer, routes, locales, theme, plugins, appId, defaultTyping, defaultDelay, defaultRoutes, inspector, }) {
|
|
13
|
-
this.botonicOutputParser = new BotonicOutputParser();
|
|
14
11
|
this.renderer = renderer;
|
|
15
12
|
this.plugins = loadPlugins(plugins);
|
|
16
13
|
this.theme = theme || {};
|
|
@@ -38,7 +35,7 @@ export class CoreBot {
|
|
|
38
35
|
setLocale(locale, session) {
|
|
39
36
|
session.__locale = locale;
|
|
40
37
|
}
|
|
41
|
-
input({ input, session, lastRoutePath,
|
|
38
|
+
input({ input, session, lastRoutePath, }) {
|
|
42
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
40
|
session = session || {};
|
|
44
41
|
if (!session.__locale)
|
|
@@ -48,20 +45,11 @@ export class CoreBot {
|
|
|
48
45
|
input,
|
|
49
46
|
session,
|
|
50
47
|
lastRoutePath,
|
|
51
|
-
dataProvider,
|
|
52
48
|
response: [],
|
|
53
|
-
messageEvents: null,
|
|
54
49
|
};
|
|
55
50
|
}
|
|
56
|
-
const parsedUserEvent = this.botonicOutputParser.parseFromUserInput(input);
|
|
57
|
-
const userId = session.user.id;
|
|
58
|
-
if (dataProvider) {
|
|
59
|
-
// TODO: Next iterations. Review cycle of commited events to DB when messages change their ACK
|
|
60
|
-
// @ts-ignore
|
|
61
|
-
const userEvent = yield dataProvider.saveEvent(Object.assign(Object.assign({}, parsedUserEvent), { userId, eventId: ulid(), createdAt: new Date().toISOString(), from: MessageEventFrom.USER, ack: MessageEventAck.RECEIVED }));
|
|
62
|
-
}
|
|
63
51
|
if (this.plugins) {
|
|
64
|
-
yield runPlugins(this.plugins, 'pre', input, session, lastRoutePath, undefined
|
|
52
|
+
yield runPlugins(this.plugins, 'pre', input, session, lastRoutePath, undefined);
|
|
65
53
|
}
|
|
66
54
|
if (this.routes instanceof Function) {
|
|
67
55
|
this.router = new Router([
|
|
@@ -84,39 +72,21 @@ export class CoreBot {
|
|
|
84
72
|
defaultTyping: this.defaultTyping,
|
|
85
73
|
defaultDelay: this.defaultDelay,
|
|
86
74
|
lastRoutePath,
|
|
87
|
-
dataProvider,
|
|
88
75
|
};
|
|
89
76
|
const response = yield this.renderer({
|
|
90
77
|
request,
|
|
91
78
|
actions: [output.fallbackAction, output.action, output.emptyAction],
|
|
92
79
|
});
|
|
93
|
-
let messageEvents = [];
|
|
94
|
-
try {
|
|
95
|
-
messageEvents = this.botonicOutputParser.xmlToMessageEvents(response);
|
|
96
|
-
}
|
|
97
|
-
catch (e) {
|
|
98
|
-
// Disabling Botonic 1.0 error log for LTS version:
|
|
99
|
-
// console.error(e)
|
|
100
|
-
}
|
|
101
80
|
lastRoutePath = output.lastRoutePath;
|
|
102
81
|
if (this.plugins) {
|
|
103
|
-
yield runPlugins(this.plugins, 'post', input, session, lastRoutePath, response
|
|
104
|
-
}
|
|
105
|
-
if (dataProvider) {
|
|
106
|
-
// TODO: save bot responses to db and update user with new session and new params
|
|
107
|
-
for (const messageEvent of messageEvents) {
|
|
108
|
-
// @ts-ignore
|
|
109
|
-
const botEvent = yield dataProvider.saveEvent(Object.assign(Object.assign({}, messageEvent), { userId, eventId: ulid(), createdAt: new Date().toISOString(), from: MessageEventFrom.BOT, ack: MessageEventAck.SENT }));
|
|
110
|
-
}
|
|
82
|
+
yield runPlugins(this.plugins, 'post', input, session, lastRoutePath, response);
|
|
111
83
|
}
|
|
112
84
|
session.is_first_interaction = false;
|
|
113
85
|
return {
|
|
114
86
|
input,
|
|
115
87
|
response,
|
|
116
|
-
messageEvents,
|
|
117
88
|
session,
|
|
118
89
|
lastRoutePath,
|
|
119
|
-
dataProvider,
|
|
120
90
|
};
|
|
121
91
|
});
|
|
122
92
|
}
|
package/lib/esm/core-bot.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-bot.js","sourceRoot":"","sources":["../../src/core-bot.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"core-bot.js","sourceRoot":"","sources":["../../src/core-bot.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAClC,OAAO,EAGL,KAAK,GAMN,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAcrD,MAAM,OAAO,OAAO;IAclB,YAAY;IACV,8BAA8B;IAC9B,QAAQ,EACR,MAAM,EACN,OAAO,EACP,KAAK,EACL,OAAO,EACP,KAAK,EACL,aAAa,EACb,YAAY,EACZ,aAAa,EACb,SAAS,GACK;QACd,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,CAAA;QACnC,IAAI,CAAC,KAAK,GAAG,KAAK,IAAI,EAAE,CAAA;QACxB,IAAI,CA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