-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
03aeda4
commit e67700e
Showing
12 changed files
with
343 additions
and
1,072 deletions.
There are no files selected for viewing
1,138 changes: 287 additions & 851 deletions
1,138
examples/flow-builder-typescript/package-lock.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { WebchatApp, WebchatArgs } from '@botonic/react' | ||
|
||
import { FORCED_PAYLOAD } from '../../server/constants' | ||
import { START_CONVERSATION_PAYLOAD } from '../../server/constants' | ||
|
||
export const webchat: WebchatArgs = { | ||
onOpen: (app: WebchatApp) => { | ||
if (app.getMessages()?.length === 0) { | ||
app.addUserPayload(FORCED_PAYLOAD) | ||
app.addUserPayload(START_CONVERSATION_PAYLOAD) | ||
} | ||
}, | ||
} |
45 changes: 0 additions & 45 deletions
45
examples/flow-builder-typescript/src/server/actions/extended-flow-builder.tsx
This file was deleted.
Oops, something went wrong.
13 changes: 6 additions & 7 deletions
13
examples/flow-builder-typescript/src/server/actions/start-conversation.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
import { FlowBuilderActionProps } from '@botonic/plugin-flow-builder' | ||
import { | ||
FlowBuilderActionProps, | ||
FlowBuilderMultichannelAction, | ||
} from '@botonic/plugin-flow-builder' | ||
import { RequestContext } from '@botonic/react' | ||
|
||
import { BotRequest } from '../types' | ||
import { getRequestData } from '../utils/actions' | ||
import { ExtendedFlowBuilderAction } from './extended-flow-builder' | ||
|
||
// Action intended to be used in first interaction, when there is inactivity or when the start over button is clicked | ||
export class StartConversationAction extends ExtendedFlowBuilderAction { | ||
export class StartConversationAction extends FlowBuilderMultichannelAction { | ||
static contextType = RequestContext | ||
static async botonicInit( | ||
request: BotRequest | ||
): Promise<FlowBuilderActionProps> { | ||
const { cmsPlugin, botContext } = getRequestData(request) | ||
const contents = await cmsPlugin.getStartContents(botContext.locale) | ||
return super.botonicInit(request, { contentId: contents[0].code }) | ||
return super.executeConversationStart(request) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1 @@ | ||
export const FORCED_PAYLOAD = '_forced_payload_' | ||
|
||
export const RESTART_CONVERSATION_PAYLOAD = 'restart-conversation' | ||
|
||
export const SUBMITED_WEBVIEW_PAYLOAD = 'ADD_SUBMITED_WEBVIEW_PAYLOAD' | ||
|
||
export const UPDATE_SESSION_PAYLOAD = 'update-session' | ||
|
||
export const REMOVE_SESSION_PAYLOAD = 'remove-session' | ||
|
||
export const MODIFY_SESSION_PAYLOAD_REGEX = new RegExp( | ||
`^${UPDATE_SESSION_PAYLOAD}.*|^${REMOVE_SESSION_PAYLOAD}.*` | ||
) | ||
|
||
export const REMOVE_SESSION_PAYLOAD_REGEX = new RegExp( | ||
`^${REMOVE_SESSION_PAYLOAD}.*` | ||
) | ||
|
||
export const CONTENT_ID_PAYLOAD = 'content-id' | ||
|
||
export const CONTENT_ID_PAYLOAD_REGEX = new RegExp(`^${CONTENT_ID_PAYLOAD}.*`) | ||
|
||
export const RATING_PAYLOAD = 'rating' | ||
|
||
export const RATING_PAYLOAD_REGEX = new RegExp(`^${RATING_PAYLOAD}.*`) | ||
|
||
export const START_CONVERSATION_PAYLOAD_REGEX = new RegExp( | ||
`^${FORCED_PAYLOAD}$|^${RESTART_CONVERSATION_PAYLOAD}$` | ||
) | ||
|
||
export const SET_WEBCHAT_SETTINGS_PAYLOAD = 'set-webchat-settings' | ||
|
||
export const SET_WEBCHAT_SETTINGS_PAYLOAD_REGEX = new RegExp( | ||
`^${SET_WEBCHAT_SETTINGS_PAYLOAD}.*` | ||
) | ||
|
||
export const DO_NOTHING_PAYLOAD = 'do-nothing' | ||
export const DO_NOTHING_PAYLOAD_REGEX = new RegExp(`^${DO_NOTHING_PAYLOAD}.*`) | ||
|
||
export const BACKDOOR_COMMANDS = { | ||
botInfo: '###bot_info', | ||
reset: '###reset', | ||
setPayload: '###payload=', | ||
} | ||
|
||
export const SET_PAYLOAD_BACKDOOR_REGEX = new RegExp( | ||
`^${BACKDOOR_COMMANDS.setPayload}.*` | ||
) | ||
export const START_CONVERSATION_PAYLOAD = 'start-conversation' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 0 additions & 37 deletions
37
examples/flow-builder-typescript/src/server/plugins/pre-handoff.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,44 @@ | ||
import BotonicPluginHubtypeAnalytics, { | ||
EventAction, | ||
EventCustom, | ||
EventFeedback, | ||
EventHandoff, | ||
EventHandoffOption, | ||
EventWebviewEnd, | ||
EventWebviewStep, | ||
HtEventProps, | ||
} from '@botonic/plugin-hubtype-analytics' | ||
import { ActionRequest } from '@botonic/react' | ||
import { EventAction, HtEventProps } from '@botonic/plugin-hubtype-analytics' | ||
|
||
import { BotRequest } from './types' | ||
import { isBrowser, isLocal } from './utils/env-utils' | ||
import { isLocal } from './utils/env-utils' | ||
|
||
export type EventPropsMap = { | ||
[EventAction.FeedbackCase]: Omit<EventFeedback, 'action'> | ||
[EventAction.FeedbackConversation]: Omit<EventFeedback, 'action'> | ||
[EventAction.FeedbackWebview]: Omit<EventFeedback, 'action'> | ||
[EventAction.HandoffOption]: Omit<EventHandoffOption, 'action'> | ||
[EventAction.HandoffFail]: Omit<EventHandoff, 'action'> | ||
[EventAction.WebviewStep]: Omit<EventWebviewStep, 'action'> | ||
[EventAction.WebviewEnd]: Omit<EventWebviewEnd, 'action'> | ||
[EventAction.Custom]: Omit<EventCustom, 'action'> | ||
} | ||
type EventArgs = { [key: string]: any } | ||
|
||
export async function trackEvent<T extends keyof EventPropsMap>( | ||
export async function trackEvent( | ||
request: BotRequest, | ||
eventName: T, | ||
eventProps?: EventPropsMap[T] | ||
eventName: string, | ||
args?: EventArgs | ||
): Promise<void> { | ||
if (isLocal()) { | ||
console.log('Tracking event...', eventName, eventProps) | ||
return | ||
if (Object.values(EventAction).includes(eventName as EventAction)) { | ||
const htEventProps = { | ||
action: eventName as EventAction, | ||
...args, | ||
} | ||
await trackHtEvent(request, htEventProps as HtEventProps) | ||
} | ||
|
||
const htEventProps = eventProps | ||
? { | ||
action: eventName as EventAction, | ||
...eventProps, | ||
} | ||
: { action: eventName as EventAction } | ||
|
||
await trackHtEvent(request, htEventProps as HtEventProps) | ||
return | ||
} | ||
|
||
export async function trackHtEvent( | ||
request: ActionRequest, | ||
request: BotRequest, | ||
htEventProps: HtEventProps | ||
) { | ||
const printLogs = !isBrowser() | ||
const hubtypeAnalyticsPlugin = isBrowser() | ||
? new BotonicPluginHubtypeAnalytics() | ||
: (request.plugins.hubtypeAnalytics as BotonicPluginHubtypeAnalytics) | ||
if (isLocal()) { | ||
console.log('TrackHtEvent', { htEventProps }) | ||
return | ||
} | ||
const hubtypeAnalytics = request.plugins.hubtypeAnalytics | ||
try { | ||
const response = await hubtypeAnalyticsPlugin.trackEvent( | ||
request, | ||
htEventProps | ||
) | ||
printLogs && console.log('TrackHtEvent Success', { data: response.data }) | ||
} catch (error: any) { | ||
printLogs && | ||
console.log( | ||
'TrackHtEvent Error', | ||
{ error }, | ||
JSON.stringify(error.response?.data), | ||
{ | ||
errorData: error.response?.data, | ||
} | ||
) | ||
await hubtypeAnalytics.trackEvent(request, htEventProps) | ||
console.log('TrackHtEvent Success', { | ||
action: htEventProps.action, | ||
}) | ||
} catch (error: unknown) { | ||
console.error('TrackHtEvent Error', { | ||
action: htEventProps.action, | ||
}) | ||
} | ||
|
||
return | ||
} |