Skip to content

Commit

Permalink
chore(core): split data models into User, Session and BotState
Browse files Browse the repository at this point in the history
  • Loading branch information
vanbasten17 committed Oct 19, 2021
1 parent 5151797 commit ae4f362
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 38 deletions.
12 changes: 12 additions & 0 deletions packages/botonic-core/src/models/bot-state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { RoutePath } from './legacy-types'

export interface BotState {
botId: string
isFirstInteraction: boolean
isHandoff: boolean
isShadowing: boolean
lastRoutePath: RoutePath
locale?: string
retries: number
botonicAction?: any
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ export interface BotonicMessageEvent extends BaseEvent {
type: MessageEventTypes
typing: number
delay: number
// idFromChannel?:string references to msgId
// also channel
}
2 changes: 2 additions & 0 deletions packages/botonic-core/src/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from './bot-state'
export * from './events'
export * from './legacy-types'
export * from './session'
export * from './user'
38 changes: 4 additions & 34 deletions packages/botonic-core/src/models/legacy-types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// 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.

import { DataProvider } from '../data-provider'
import { BotState } from './bot-state'
import { BotonicEvent } from './events'
import { Session } from './session'

export type CaseStatusType =
| typeof CASE_STATUS.ATTENDING
Expand Down Expand Up @@ -131,37 +132,6 @@ export type ProviderType =
| typeof PROVIDER.WECHAT
| typeof PROVIDER.WHATSAPP

export interface SessionUser {
id: string
// login
username?: string
// person name
name?: string
// whatsapp, telegram,...
provider: ProviderType
// The provider's user id
extra_data?: any
imp_id?: string
provider_id?: string
}

// eslint-disable @typescript-eslint/naming-convention
export interface Session {
bot: {
id: string
name?: string
}
__locale?: string
__retries: number
is_first_interaction: boolean
last_session?: any
organization?: string
user: SessionUser
// after handoff
_hubtype_case_status?: CaseStatusType
_hubtype_case_typification?: string
_shadowing?: boolean
}
// eslint-enable @typescript-eslint/naming-convention

export type InputMatcher = (input: Input) => boolean
Expand Down Expand Up @@ -204,8 +174,8 @@ export type Routes<R = Route> = R[] | ((_: BotRequest) => R[])

export interface BotRequest {
input: Input
lastRoutePath: RoutePath
session: Session
botState: BotState
dataProvider?: DataProvider
}

Expand Down Expand Up @@ -255,7 +225,7 @@ export interface ProcessInputResult {
action: Action
emptyAction: Action
fallbackAction: Action
lastRoutePath: RoutePath
botState: BotState
params: Params
}

Expand Down
3 changes: 3 additions & 0 deletions packages/botonic-core/src/models/session.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface Session {
[key: string]: any
}
15 changes: 11 additions & 4 deletions packages/botonic-core/src/models/user.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { Session } from './legacy-types'
import { BotState } from './bot-state'
import { Session } from './session'

export interface User {
id: string //TODO: UUID
providerId?: string
websocketId?: string
name?: string
userName?: string
channel: string
idFromChannel: string // providerId
session: Session
route: string
botState: BotState
// functioning
isOnline: boolean
websocketId?: string
// part of details?
// route: string inside botState
locationInfo: string
}

0 comments on commit ae4f362

Please sign in to comment.