Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add handoff options for shadowing, cancelHandoff and deleteUser #603

Merged
merged 7 commits into from
Mar 17, 2020
40 changes: 31 additions & 9 deletions packages/botonic-core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export interface Input {
entities?: any
}


export interface SessionUser {
id: string
// login
Expand All @@ -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
Expand Down Expand Up @@ -80,6 +85,7 @@ export class HandOffBuilder {
withAgentEmail(email: string): HandOffBuilder
withNoteURL(note: string): HandOffBuilder
withCaseInfoURL(caseInfo: string): HandOffBuilder
withShadowing(shadowing?: boolean): HandOffBuilder

handOff(): Promise<void>
}
Expand Down Expand Up @@ -118,6 +124,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
Expand Down Expand Up @@ -176,20 +189,29 @@ 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 {
focusOnlyOnRoutes(focusRoutePaths: string[]): FocusRouteInspector
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
}
2 changes: 1 addition & 1 deletion packages/botonic-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
24 changes: 22 additions & 2 deletions packages/botonic-core/src/handoff.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,20 @@ export class HandOffBuilder {
return this
}

withShadowing(shadowing = true) {
ericmarcos marked this conversation as resolved.
Show resolved Hide resolved
this._shadowing = shadowing
return this
}

async handOff() {
return _humanHandOff(
this._session,
this._queue,
this._onFinish,
this._email,
this._caseInfo,
this._note
this._note,
this._shadowing
)
}
}
Expand Down Expand Up @@ -87,7 +93,8 @@ async function _humanHandOff(
onFinish,
agentEmail = '',
caseInfo = '',
note = ''
note = '',
shadowing = false
) {
const params = {}
if (!queueNameOrId && agentEmail) {
Expand All @@ -105,6 +112,9 @@ async function _humanHandOff(
if (note) {
params.note = note
}
if (shadowing) {
params.shadowing = shadowing
}

if (onFinish) {
params.on_finish = onFinish
Expand Down Expand Up @@ -151,3 +161,13 @@ export async function getAvailableAgents(session) {
})
return resp.data
}

export function cancelHandoff(session, typification = null) {
ericmarcos marked this conversation as resolved.
Show resolved Hide resolved
let action = 'discard_case'
if (typification) action = `${action}:${JSON.stringify({ typification })}`
session._botonic_action = action
}

export function deleteUser(session) {
ericmarcos marked this conversation as resolved.
Show resolved Hide resolved
session._botonic_action = `delete_user`
}
2 changes: 2 additions & 0 deletions packages/botonic-core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export {
HandOffBuilder,
storeCaseRating,
getAvailableAgents,
cancelHandoff,
deleteUser,
} from './handoff'
export { getNLU } from './nlu'
export { isBrowser, isNode, isMobile, params2queryString } from './utils'
Expand Down
2 changes: 1 addition & 1 deletion packages/botonic-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down