Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/botonic-react/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,7 @@ export const ROLES = {
RAW_MESSAGE: 'raw-message',
SYSTEM_DEBUG_TRACE_MESSAGE: 'system-debug-trace-message',
}

export const WEBCHAT_DEFAULT_CONTENTS = {
INPUT_PLACEHOLDER: 'Ask me something...',
}
5 changes: 5 additions & 0 deletions packages/botonic-react/src/dev-app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class DevApp extends WebchatApp {
onClose,
onMessage,
onTrackEvent,
contentsByLocale,
webviews,
...botOptions
}) {
Expand All @@ -48,6 +49,7 @@ export class DevApp extends WebchatApp {
onClose,
onMessage,
onTrackEvent,
contentsByLocale,
})
this.webviews = webviews
this.bot = new ReactBot({
Expand All @@ -65,6 +67,7 @@ export class DevApp extends WebchatApp {
onClose,
onMessage,
onTrackEvent,
contentsByLocale,
hostId,
...webchatOptions
} = optionsAtRuntime
Expand All @@ -76,6 +79,7 @@ export class DevApp extends WebchatApp {
this.onClose = onClose || this.onClose
this.onMessage = onMessage || this.onMessage
this.onTrackEvent = onTrackEvent || this.onTrackEvent
this.contentsByLocale = contentsByLocale || this.contentsByLocale
this.hostId = hostId || this.hostId
this.createRootElement(host)
return (
Expand All @@ -87,6 +91,7 @@ export class DevApp extends WebchatApp {
theme={theme}
storage={storage}
storageKey={storageKey}
contentsByLocale={this.contentsByLocale}
onInit={(...args) => this.onInitWebchat(...args)}
onOpen={(...args) => this.onOpenWebchat(...args)}
onClose={(...args) => this.onCloseWebchat(...args)}
Expand Down
6 changes: 6 additions & 0 deletions packages/botonic-react/src/index-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ export interface MinimalHubtypeMessage {
text: string
}

export interface WebchatLocaleContents {
inputPlaceholder: string
}

export interface PreviewUtils {
getChunkIdsGroupedBySource: (
chunkIds: string[]
Expand Down Expand Up @@ -122,6 +126,7 @@ export interface WebchatArgs {
onMessage?: (app: WebchatApp, message: WebchatMessage) => void
onTrackEvent?: TrackEventFunction
onConnectionChange?: (app: WebchatApp, isOnline: boolean) => void
contentsByLocale?: Record<string, WebchatLocaleContents>
appId?: string
visibility?: boolean | (() => boolean) | 'dynamic'
server?: ServerConfig
Expand Down Expand Up @@ -149,6 +154,7 @@ export interface WebchatProps {
server?: ServerConfig
localWebviews?: React.ComponentType[]
previewUtils?: PreviewUtils
contentsByLocale?: Record<string, WebchatLocaleContents>
}

export type EventArgs = { [key: string]: any }
Expand Down
7 changes: 7 additions & 0 deletions packages/botonic-react/src/webchat-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
SENDERS,
Typing,
type WebchatArgs,
type WebchatLocaleContents,
type WebchatMessage,
type WebchatRef,
} from './index-types'
Expand Down Expand Up @@ -55,6 +56,7 @@ export class WebchatApp {
args?: EventArgs
) => Promise<void>
public onConnectionChange?: (app: WebchatApp, isOnline: boolean) => void
public contentsByLocale?: Record<string, WebchatLocaleContents>
public appId?: string
public visibility?: boolean | (() => boolean) | 'dynamic'
public server?: ServerConfig
Expand Down Expand Up @@ -86,6 +88,7 @@ export class WebchatApp {
onMessage,
onTrackEvent,
onConnectionChange,
contentsByLocale,
appId,
visibility,
server,
Expand Down Expand Up @@ -119,6 +122,7 @@ export class WebchatApp {
this.onMessage = onMessage
this.onTrackEvent = onTrackEvent
this.onConnectionChange = onConnectionChange
this.contentsByLocale = contentsByLocale
this.visibility = visibility
this.server = server
this.previewUtils = previewUtils
Expand Down Expand Up @@ -482,6 +486,7 @@ export class WebchatApp {
onClose,
onMessage,
onConnectionChange,
contentsByLocale,
onTrackEvent,
appId,
visibility,
Expand All @@ -502,6 +507,7 @@ export class WebchatApp {
this.onMessage = onMessage || this.onMessage
this.onTrackEvent = onTrackEvent || this.onTrackEvent
this.onConnectionChange = onConnectionChange || this.onConnectionChange
this.contentsByLocale = contentsByLocale || this.contentsByLocale
this.visibility = visibility || this.visibility
this.appId = appId || this.appId
this.hostId = hostId || this.hostId
Expand Down Expand Up @@ -533,6 +539,7 @@ export class WebchatApp {
args?: EventArgs
) => this.onTrackEventWebchat(request, eventName, args)}
server={server}
contentsByLocale={this.contentsByLocale}
/>
)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/botonic-react/src/webchat/theme/default-theme.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { COLORS, WEBCHAT } from '../../constants'
import { COLORS, WEBCHAT, WEBCHAT_DEFAULT_CONTENTS } from '../../constants'
import type { WebchatTheme } from './types'

export const defaultTheme: WebchatTheme = {
Expand Down Expand Up @@ -81,7 +81,7 @@ export const defaultTheme: WebchatTheme = {
userInput: {
attachments: { enable: undefined },
box: {
placeholder: 'Ask me something...',
placeholder: WEBCHAT_DEFAULT_CONTENTS.INPUT_PLACEHOLDER,
},
emojiPicker: { enable: undefined },
sendButton: { enable: true },
Expand Down
19 changes: 18 additions & 1 deletion packages/botonic-react/src/webchat/webchat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ import {
Video,
type WebchatSettingsProps,
} from '../components'
import { COLORS, MAX_ALLOWED_SIZE_MB, ROLES, WEBCHAT } from '../constants'
import {
COLORS,
MAX_ALLOWED_SIZE_MB,
ROLES,
WEBCHAT,
WEBCHAT_DEFAULT_CONTENTS,
} from '../constants'
import type { CloseWebviewOptions } from '../contexts'
import { SENDERS, type WebchatProps, type WebchatRef } from '../index-types'
import {
Expand Down Expand Up @@ -109,6 +115,7 @@ const Webchat = forwardRef<WebchatRef | null, WebchatProps>((props, ref) => {
scrollableMessagesListRef,
} = props.webchatHooks || useWebchat(props.theme)

const contentsByLocale = props.contentsByLocale
const firstUpdate = useRef(true)
const isOnline = () => webchatState.online
const currentDateString = () => new Date().toISOString()
Expand Down Expand Up @@ -485,6 +492,16 @@ const Webchat = forwardRef<WebchatRef | null, WebchatProps>((props, ref) => {
*/

const updateSessionWithUser = (userToUpdate: any) => {
if (contentsByLocale && userToUpdate.system_locale) {
const placeholder =
contentsByLocale[userToUpdate.system_locale]?.inputPlaceholder ??
WEBCHAT_DEFAULT_CONTENTS.INPUT_PLACEHOLDER
const themeUpdates = { userInput: { box: { placeholder } } }
updateTheme(
merge(props.theme, themeUpdates),
themeUpdates as WebchatTheme
)
}
updateSession(merge(webchatState.session, { user: userToUpdate }))
}

Expand Down
Loading