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
ericmarcos marked this conversation as resolved.
Show resolved Hide resolved

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
ericmarcos marked this conversation as resolved.
Show resolved Hide resolved
): 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
}
5 changes: 3 additions & 2 deletions packages/botonic-core/src/handoff.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ export async function getAvailableAgents(session) {
}

export function cancelHandoff(session, typification = null) {
ericmarcos marked this conversation as resolved.
Show resolved Hide resolved
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) {
ericmarcos marked this conversation as resolved.
Show resolved Hide resolved
Expand Down