Skip to content

Commit c05e9ef

Browse files
committed
Merge branch 'master-lts' into BLT-1591-remove-get-string-function-from-request-bot-context
2 parents 13f49f4 + d2aaa87 commit c05e9ef

File tree

3 files changed

+45
-29
lines changed

3 files changed

+45
-29
lines changed

packages/botonic-core/src/models/legacy-types.ts

+23-15
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ export interface Campaign {
225225
template_name: string
226226
}
227227

228-
export interface SessionUser {
228+
export interface SessionUser<TExtraData = any> {
229229
id: string
230230
// login
231231
username?: string
@@ -234,7 +234,7 @@ export interface SessionUser {
234234
// whatsapp, telegram,...
235235
provider: ProviderType
236236
// The provider's user id
237-
extra_data?: any
237+
extra_data?: TExtraData
238238
imp_id?: string
239239
provider_id?: string
240240
locale: string
@@ -253,7 +253,7 @@ export interface SessionBot {
253253
name?: string
254254
}
255255

256-
export interface Session {
256+
export interface Session<TExtraData = any> {
257257
bot: SessionBot
258258
__retries: number
259259
_access_token: string
@@ -263,7 +263,7 @@ export interface Session {
263263
last_session?: any
264264
organization_id: string
265265
organization: string
266-
user: SessionUser
266+
user: SessionUser<TExtraData>
267267
// after handoff
268268
_botonic_action?: BotonicActionType
269269
_hubtype_case_status?: CaseStatusType
@@ -314,14 +314,18 @@ export interface Route {
314314

315315
export type Routes<R = Route> = R[] | ((_: BotRequest) => R[])
316316

317-
export interface BotRequest {
317+
export interface BotRequest<TExtraData = any> {
318318
input: Input
319319
lastRoutePath: RoutePath
320-
session: Session
320+
session: Session<TExtraData>
321321
}
322322

323-
export interface BotContext<T extends ResolvedPlugins = ResolvedPlugins>
324-
extends BotRequest {
323+
export interface BotContext<
324+
TPlugins extends ResolvedPlugins = ResolvedPlugins,
325+
TExtraData = any,
326+
> extends BotRequest<TExtraData> {
327+
// TODO: remove getString function?
328+
getString: (stringId: string) => string
325329
getUserCountry: () => string
326330
getUserLocale: () => string
327331
getSystemLocale: () => string
@@ -331,7 +335,7 @@ export interface BotContext<T extends ResolvedPlugins = ResolvedPlugins>
331335
defaultDelay: number
332336
defaultTyping: number
333337
params: Record<string, string>
334-
plugins: T
338+
plugins: TPlugins
335339
}
336340

337341
/** The response of the bot for the triggered actions, which can be
@@ -342,13 +346,17 @@ export interface BotResponse extends BotRequest {
342346
response: any
343347
}
344348

345-
export type PluginPreRequest<T extends ResolvedPlugins = ResolvedPlugins> =
346-
BotContext<T>
349+
export type PluginPreRequest<
350+
TPlugins extends ResolvedPlugins = ResolvedPlugins,
351+
TExtraData = any,
352+
> = BotContext<TPlugins, TExtraData>
347353

348-
export type PluginPostRequest<T extends ResolvedPlugins = ResolvedPlugins> =
349-
BotContext<T> & {
350-
response: string | null
351-
}
354+
export type PluginPostRequest<
355+
TPlugins extends ResolvedPlugins = ResolvedPlugins,
356+
TExtraData = any,
357+
> = BotContext<TPlugins, TExtraData> & {
358+
response: string | null
359+
}
352360

353361
export interface Plugin {
354362
post?(request: PluginPostRequest): void | Promise<void>

packages/botonic-plugin-flow-builder/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default class BotonicPluginFlowBuilder implements Plugin {
6666
public jsonVersion: FlowBuilderJSONVersion
6767
public apiUrl: string
6868

69-
constructor(options: BotonicPluginFlowBuilderOptions<ResolvedPlugins>) {
69+
constructor(options: BotonicPluginFlowBuilderOptions<ResolvedPlugins, any>) {
7070
this.apiUrl = options.apiUrl || FLOW_BUILDER_API_URL_PROD
7171
this.jsonVersion = options.jsonVersion || FlowBuilderJSONVersion.LATEST
7272
this.flow = options.flow

packages/botonic-plugin-flow-builder/src/types.ts

+21-13
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,41 @@ export interface InShadowingConfig {
1313
allowKnowledgeBases: boolean
1414
}
1515

16-
export interface BotonicPluginFlowBuilderOptions<T extends ResolvedPlugins> {
16+
export interface BotonicPluginFlowBuilderOptions<
17+
TPlugins extends ResolvedPlugins = ResolvedPlugins,
18+
TExtraData = any,
19+
> {
1720
apiUrl?: string
1821
jsonVersion?: FlowBuilderJSONVersion
1922
flow?: HtFlowBuilderData
2023
customFunctions?: Record<any, any>
2124
getLocale: (session: Session) => string
2225
getAccessToken: () => string
23-
trackEvent?: TrackEventFunction<T>
24-
getKnowledgeBaseResponse?: KnowledgeBaseFunction<T>
26+
trackEvent?: TrackEventFunction<TPlugins, TExtraData>
27+
getKnowledgeBaseResponse?: KnowledgeBaseFunction<TPlugins, TExtraData>
2528
smartIntentsConfig?: { numSmartIntentsToUse: number }
2629
inShadowing?: Partial<InShadowingConfig>
2730
}
2831

29-
export type TrackEventFunction<T extends ResolvedPlugins = ResolvedPlugins> = (
30-
request: BotContext<T>,
32+
export type TrackEventFunction<
33+
TPlugins extends ResolvedPlugins = ResolvedPlugins,
34+
TExtraData = any,
35+
> = (
36+
request: BotContext<TPlugins, TExtraData>,
3137
eventAction: string,
3238
args?: Record<string, any>
3339
) => Promise<void>
3440

35-
export type KnowledgeBaseFunction<T extends ResolvedPlugins = ResolvedPlugins> =
36-
(
37-
request: BotContext<T>,
38-
sources: string[],
39-
instructions: string,
40-
messageId: string,
41-
memoryLength: number
42-
) => Promise<KnowledgeBaseResponse>
41+
export type KnowledgeBaseFunction<
42+
TPlugins extends ResolvedPlugins = ResolvedPlugins,
43+
TExtraData = any,
44+
> = (
45+
request: BotContext<TPlugins, TExtraData>,
46+
sources: string[],
47+
instructions: string,
48+
messageId: string,
49+
memoryLength: number
50+
) => Promise<KnowledgeBaseResponse>
4351

4452
export interface FlowBuilderApiOptions {
4553
url: string

0 commit comments

Comments
 (0)