From e6c2cf2a3c1cb0290002354bb81167ba4ccd2b24 Mon Sep 17 00:00:00 2001 From: Eric Marcos Date: Fri, 28 Feb 2020 16:51:45 +0100 Subject: [PATCH 1/6] feat(core): add handoff options for shadowing, cancelHandoff and deleteUser --- packages/botonic-core/src/handoff.js | 23 +++++++++++++++++++++-- packages/botonic-core/src/index.js | 2 ++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/botonic-core/src/handoff.js b/packages/botonic-core/src/handoff.js index fd1130e228..548a532de2 100644 --- a/packages/botonic-core/src/handoff.js +++ b/packages/botonic-core/src/handoff.js @@ -49,6 +49,11 @@ export class HandOffBuilder { return this } + withShadowing(shadowing = true) { + this._shadowing = shadowing + return this + } + async handOff() { return _humanHandOff( this._session, @@ -56,7 +61,8 @@ export class HandOffBuilder { this._onFinish, this._email, this._caseInfo, - this._note + this._note, + this._shadowing ) } } @@ -87,7 +93,8 @@ async function _humanHandOff( onFinish, agentEmail = '', caseInfo = '', - note = '' + note = '', + shadowing = false ) { const params = {} if (!queueNameOrId && agentEmail) { @@ -105,6 +112,9 @@ async function _humanHandOff( if (note) { params.note = note } + if (shadowing) { + params.shadowing = shadowing + } if (onFinish) { params.on_finish = onFinish @@ -151,3 +161,12 @@ export async function getAvailableAgents(session) { }) return resp.data } + +export function cancelHandoff(session, typification = null) { + let params = { typification } + session._botonic_action = `discard_case:${JSON.stringify(params)}` +} + +export function deleteUser(session) { + session._botonic_action = `delete_user` +} diff --git a/packages/botonic-core/src/index.js b/packages/botonic-core/src/index.js index ef63e897a5..97edd9314a 100644 --- a/packages/botonic-core/src/index.js +++ b/packages/botonic-core/src/index.js @@ -6,6 +6,8 @@ export { HandOffBuilder, storeCaseRating, getAvailableAgents, + cancelHandoff, + deleteUser, } from './handoff' export { getNLU } from './nlu' export { isBrowser, isNode, isMobile, params2queryString } from './utils' From 4d4b3fe8a66df3f7e361412485dd9e4abfb4a135 Mon Sep 17 00:00:00 2001 From: Eric Marcos Date: Mon, 2 Mar 2020 15:16:32 +0100 Subject: [PATCH 2/6] chore(core): add types for cancelHandoff, deleteUser, and shadowing options --- packages/botonic-core/index.d.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/botonic-core/index.d.ts b/packages/botonic-core/index.d.ts index f4fad009e3..670ac7303d 100644 --- a/packages/botonic-core/index.d.ts +++ b/packages/botonic-core/index.d.ts @@ -80,6 +80,7 @@ export class HandOffBuilder { withAgentEmail(email: string): HandOffBuilder withNoteURL(note: string): HandOffBuilder withCaseInfoURL(caseInfo: string): HandOffBuilder + withShadowing(shadowing: boolean): HandOffBuilder handOff(): Promise } @@ -118,6 +119,13 @@ export declare function getAvailableAgents( session: Session ): Promise<{ agents: HubtypeAgentsInfo[] }> +export declare function cancelHandoff( + session: Session, + typification: string +): void + +export declare function deleteUser(session: Session): void + export interface BotRequest { input: Input session: Session From ad83a82d416dbf14dcd7f117634fbb929a35e0b0 Mon Sep 17 00:00:00 2001 From: Eric Marcos Date: Mon, 2 Mar 2020 15:17:23 +0100 Subject: [PATCH 3/6] fix(core): cancelHandoff to return a 'typification' param only if it's defined --- packages/botonic-core/src/handoff.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/botonic-core/src/handoff.js b/packages/botonic-core/src/handoff.js index 548a532de2..d8a57e0caf 100644 --- a/packages/botonic-core/src/handoff.js +++ b/packages/botonic-core/src/handoff.js @@ -163,8 +163,9 @@ export async function getAvailableAgents(session) { } export function cancelHandoff(session, typification = null) { - let params = { typification } - session._botonic_action = `discard_case:${JSON.stringify(params)}` + let action = 'discard_case' + if (typification) action = `${action}:${JSON.stringify({ typification })}` + session._botonic_action = action } export function deleteUser(session) { From 899f82c2392e514a415d0a08445f8e4d1694d030 Mon Sep 17 00:00:00 2001 From: Eric Marcos Date: Mon, 2 Mar 2020 15:17:57 +0100 Subject: [PATCH 4/6] style(core): code formatting of index.d.ts --- packages/botonic-core/index.d.ts | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/packages/botonic-core/index.d.ts b/packages/botonic-core/index.d.ts index 670ac7303d..a389244bad 100644 --- a/packages/botonic-core/index.d.ts +++ b/packages/botonic-core/index.d.ts @@ -18,7 +18,6 @@ export interface Input { entities?: any } - export interface SessionUser { id: string // login @@ -45,10 +44,16 @@ export interface Session { } type StringMatcher = RegExp | string | ((data: string) => boolean) -type ParamsMatcher = { [key: string]: string } | ((params: { [key: string]: string }) => boolean) +type ParamsMatcher = + | { [key: string]: string } + | ((params: { [key: string]: string }) => boolean) type SessionMatcher = (session: Session) => boolean type InputMatcher = (input: Input) => boolean -type RouteMatcher = StringMatcher | ParamsMatcher| SessionMatcher | InputMatcher +type RouteMatcher = + | StringMatcher + | ParamsMatcher + | SessionMatcher + | InputMatcher export interface Route { path?: StringMatcher @@ -184,8 +189,18 @@ export class CoreBot { // Debug export class RouteInspector { - routeMatched(route: Route, routeKey: string, routeValue: RouteMatcher, input: Input): void; - routeNotMatched(route: Route, routeKey: string, routeValue: RouteMatcher, input: Input): void; + routeMatched( + route: Route, + routeKey: string, + routeValue: RouteMatcher, + input: Input + ): void + routeNotMatched( + route: Route, + routeKey: string, + routeValue: RouteMatcher, + input: Input + ): void } export class FocusRouteInspector extends RouteInspector { @@ -193,11 +208,10 @@ export class FocusRouteInspector extends RouteInspector { focusOnlyOnMatches(): FocusRouteInspector } -export class LogRouteInspector extends FocusRouteInspector { -} +export class LogRouteInspector extends FocusRouteInspector {} export class Inspector { - constructor(routeInspector: RouteInspector | undefined); + constructor(routeInspector: RouteInspector | undefined) - getRouteInspector(): RouteInspector; + getRouteInspector(): RouteInspector } From 26b5fe3a048c25638a68ef511f06121748f06f4e Mon Sep 17 00:00:00 2001 From: Dani Pinyol Date: Mon, 2 Mar 2020 17:19:02 +0100 Subject: [PATCH 5/6] chore(core/react): d.ts was not being eslinted --- packages/botonic-core/package.json | 2 +- packages/botonic-react/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/botonic-core/package.json b/packages/botonic-core/package.json index aab03565b8..7b295aee05 100644 --- a/packages/botonic-core/package.json +++ b/packages/botonic-core/package.json @@ -7,7 +7,7 @@ "test": "../../node_modules/.bin/jest --coverage", "prepare": "node ../../preinstall.js", "lint": "npm run lint_ci -- --fix", - "lint_ci": "../../node_modules/.bin/eslint_d --cache --quiet 'src/**/*.js*'", + "lint_ci": "../../node_modules/.bin/eslint_d --cache --quiet 'src/**/*.js*' '**/*.d.ts'", "build": "rm -rf lib && babel src --out-dir lib --source-maps --copy-files" }, "repository": { diff --git a/packages/botonic-react/package.json b/packages/botonic-react/package.json index 6d7a78bdcb..9ca629e3db 100644 --- a/packages/botonic-react/package.json +++ b/packages/botonic-react/package.json @@ -9,7 +9,7 @@ "build": "rm -rf lib && babel src --out-dir lib --source-maps --copy-files", "lint": "npm run lint_core -- --fix", "lint_ci": "npm run lint_core", - "lint_core": "../../node_modules/.bin/eslint_d --cache --quiet 'src/**/*.js*' 'src/**/*.d.ts' 'tests/**/*.js' 'tests/**/*.jsx'" + "lint_core": "../../node_modules/.bin/eslint_d --cache --quiet 'src/**/*.js*' '**/*.d.ts' 'tests/**/*.js' 'tests/**/*.jsx'" }, "sideEffects": [ "*.(scss|css)" From 40040e7ebeb3168e9d629f1aeccc70218f0804fd Mon Sep 17 00:00:00 2001 From: Eric Marcos Date: Mon, 2 Mar 2020 18:34:43 +0100 Subject: [PATCH 6/6] fix(core): define typification param as optional in cancelHandoff types --- packages/botonic-core/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/botonic-core/index.d.ts b/packages/botonic-core/index.d.ts index a389244bad..6ca3181381 100644 --- a/packages/botonic-core/index.d.ts +++ b/packages/botonic-core/index.d.ts @@ -85,7 +85,7 @@ export class HandOffBuilder { withAgentEmail(email: string): HandOffBuilder withNoteURL(note: string): HandOffBuilder withCaseInfoURL(caseInfo: string): HandOffBuilder - withShadowing(shadowing: boolean): HandOffBuilder + withShadowing(shadowing?: boolean): HandOffBuilder handOff(): Promise } @@ -126,7 +126,7 @@ export declare function getAvailableAgents( export declare function cancelHandoff( session: Session, - typification: string + typification?: string ): void export declare function deleteUser(session: Session): void