@botonic/react 0.22.0-alpha.2 → 0.22.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/botonic-tester.js +4 -4
- package/lib/cjs/botonic-tester.js.map +1 -1
- package/lib/cjs/components/index-types.d.ts +174 -0
- package/lib/cjs/components/index-types.js +17 -0
- package/lib/cjs/components/index-types.js.map +1 -0
- package/lib/cjs/components/index.d.ts +23 -20
- package/lib/cjs/components/index.js +6 -1
- package/lib/cjs/components/index.js.map +1 -1
- package/lib/cjs/components/message.js +2 -2
- package/lib/cjs/components/message.js.map +1 -1
- package/lib/cjs/components/multichannel/index-types.d.ts +45 -0
- package/lib/cjs/components/multichannel/index-types.js +3 -0
- package/lib/cjs/components/multichannel/index-types.js.map +1 -0
- package/lib/cjs/components/multichannel/index.d.ts +8 -3
- package/lib/cjs/components/multichannel/index.js +2 -0
- package/lib/cjs/components/multichannel/index.js.map +1 -1
- package/lib/cjs/components/multichannel/multichannel-text.js +1 -1
- package/lib/cjs/components/multichannel/multichannel-text.js.map +1 -1
- package/lib/cjs/components/whatsapp-button-list.d.ts +24 -0
- package/lib/cjs/components/whatsapp-button-list.js +26 -0
- package/lib/cjs/components/whatsapp-button-list.js.map +1 -0
- package/lib/cjs/contexts.d.ts +2 -3
- package/lib/cjs/contexts.js +3 -4
- package/lib/cjs/contexts.js.map +1 -1
- package/lib/cjs/index-types.d.ts +94 -0
- package/lib/cjs/index-types.js +12 -0
- package/lib/cjs/index-types.js.map +1 -0
- package/lib/cjs/index.d.ts +9 -10
- package/lib/cjs/index.js +5 -7
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/message-utils.d.ts +1 -1
- package/lib/cjs/message-utils.js +16 -16
- package/lib/cjs/message-utils.js.map +1 -1
- package/lib/cjs/node-app.d.ts +1 -1
- package/lib/cjs/react-bot.d.ts +1 -1
- package/lib/cjs/react-bot.js +2 -2
- package/lib/cjs/react-bot.js.map +1 -1
- package/lib/cjs/util/index.d.ts +8 -0
- package/lib/cjs/util/index.js +10 -0
- package/lib/cjs/util/index.js.map +1 -1
- package/lib/cjs/util/webchat.d.ts +1 -1
- package/lib/cjs/util/webchat.js.map +1 -1
- package/lib/cjs/webchat/index-types.d.ts +55 -0
- package/lib/cjs/webchat/index-types.js +3 -0
- package/lib/cjs/webchat/index-types.js.map +1 -0
- package/lib/cjs/webchat/index.d.ts +4 -6
- package/lib/cjs/webchat/index.js +3 -3
- package/lib/cjs/webchat/index.js.map +1 -1
- package/lib/cjs/webchat-app.js +4 -3
- package/lib/cjs/webchat-app.js.map +1 -1
- package/lib/esm/botonic-tester.js +1 -1
- package/lib/esm/botonic-tester.js.map +1 -1
- package/lib/esm/components/carousel.d.ts +2 -1
- package/lib/esm/components/index-types.d.ts +174 -0
- package/lib/esm/components/index-types.js +16 -0
- package/lib/esm/components/index-types.js.map +1 -0
- package/lib/esm/components/index.d.ts +23 -19
- package/lib/esm/components/index.js +3 -0
- package/lib/esm/components/index.js.map +1 -1
- package/lib/esm/components/message.js +2 -2
- package/lib/esm/components/message.js.map +1 -1
- package/lib/esm/components/multichannel/index-types.d.ts +45 -0
- package/lib/esm/components/multichannel/index-types.js +2 -0
- package/lib/esm/components/multichannel/index-types.js.map +1 -0
- package/lib/esm/components/multichannel/index.d.ts +8 -3
- package/lib/esm/components/multichannel/index.js +1 -0
- package/lib/esm/components/multichannel/index.js.map +1 -1
- package/lib/esm/components/multichannel/multichannel-text.js +1 -1
- package/lib/esm/components/multichannel/multichannel-text.js.map +1 -1
- package/lib/esm/components/whatsapp-button-list.d.ts +24 -0
- package/lib/esm/components/whatsapp-button-list.js +22 -0
- package/lib/esm/components/whatsapp-button-list.js.map +1 -0
- package/lib/esm/contexts.d.ts +2 -3
- package/lib/esm/contexts.js +3 -3
- package/lib/esm/contexts.js.map +1 -1
- package/lib/esm/index-types.d.ts +94 -0
- package/lib/esm/index-types.js +9 -0
- package/lib/esm/index-types.js.map +1 -0
- package/lib/esm/index.d.ts +9 -9
- package/lib/esm/index.js +4 -3
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/message-utils.d.ts +2 -1
- package/lib/esm/message-utils.js +1 -1
- package/lib/esm/message-utils.js.map +1 -1
- package/lib/esm/node-app.d.ts +3 -3
- package/lib/esm/react-bot.d.ts +2 -1
- package/lib/esm/react-bot.js +1 -1
- package/lib/esm/react-bot.js.map +1 -1
- package/lib/esm/util/index.d.ts +8 -0
- package/lib/esm/util/index.js +8 -1
- package/lib/esm/util/index.js.map +1 -1
- package/lib/esm/util/webchat.d.ts +1 -1
- package/lib/esm/util/webchat.js.map +1 -1
- package/lib/esm/webchat/index-types.d.ts +55 -0
- package/lib/esm/webchat/index-types.js +2 -0
- package/lib/esm/webchat/index-types.js.map +1 -0
- package/lib/esm/webchat/index.d.ts +4 -6
- package/lib/esm/webchat/index.js +2 -3
- package/lib/esm/webchat/index.js.map +1 -1
- package/lib/esm/webchat-app.d.ts +4 -3
- package/lib/esm/webchat-app.js +2 -1
- package/lib/esm/webchat-app.js.map +1 -1
- package/package.json +3 -3
- package/src/botonic-tester.jsx +1 -1
- package/src/components/{index.d.ts → index-types.ts} +22 -43
- package/src/components/{index.js → index.ts} +6 -0
- package/src/components/message.jsx +11 -4
- package/src/components/multichannel/{index.d.ts → index-types.ts} +1 -10
- package/src/components/multichannel/{index.js → index.ts} +2 -0
- package/src/components/multichannel/multichannel-text.jsx +5 -2
- package/src/components/whatsapp-button-list.tsx +64 -0
- package/src/contexts.jsx +3 -3
- package/src/index-types.ts +195 -0
- package/src/{index.js → index.ts} +4 -3
- package/src/message-utils.js +1 -1
- package/src/react-bot.jsx +1 -1
- package/src/util/index.ts +8 -0
- package/src/util/webchat.js +13 -12
- package/src/webchat/{index.d.ts → index-types.ts} +11 -13
- package/src/webchat/{index.js → index.ts} +3 -3
- package/src/webchat-app.jsx +2 -1
- package/src/index.d.ts +0 -238
- package/src/util/index.d.ts +0 -9
- package/src/util/index.js +0 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { INPUT } from '@botonic/core'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
import { renderComponent } from '../util/react'
|
|
5
|
+
import { Message } from './message'
|
|
6
|
+
|
|
7
|
+
// TODO: Add validation in component
|
|
8
|
+
|
|
9
|
+
interface Action {
|
|
10
|
+
button: string
|
|
11
|
+
sections: Section[]
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface Section {
|
|
15
|
+
title?: string
|
|
16
|
+
rows: Row[]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface Row {
|
|
20
|
+
id: string
|
|
21
|
+
title: string
|
|
22
|
+
description: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface TextMessage {
|
|
26
|
+
text: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface WhatsappButtonListProps {
|
|
30
|
+
header?: string
|
|
31
|
+
body: TextMessage
|
|
32
|
+
footer?: TextMessage
|
|
33
|
+
action: Action
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const serialize = _whatsappTemplateProps => {
|
|
37
|
+
// TODO: Implement to have data persistance in localStorage, not needed for this WhatsApp development
|
|
38
|
+
return {}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const WhatsappButtonList = (props: WhatsappButtonListProps) => {
|
|
42
|
+
const renderBrowser = () => {
|
|
43
|
+
// Return a dummy message for browser
|
|
44
|
+
const message = `${JSON.stringify(props)}`
|
|
45
|
+
return (
|
|
46
|
+
<Message
|
|
47
|
+
json={serialize(message)}
|
|
48
|
+
{...props}
|
|
49
|
+
type={INPUT.WHATSAPP_BUTTON_LIST}
|
|
50
|
+
>
|
|
51
|
+
{message}
|
|
52
|
+
</Message>
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const renderNode = () => {
|
|
57
|
+
return (
|
|
58
|
+
// @ts-ignore Property 'message' does not exist on type 'JSX.IntrinsicElements'.
|
|
59
|
+
<message {...props} type={INPUT.WHATSAPP_BUTTON_LIST} />
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return renderComponent({ renderBrowser, renderNode })
|
|
64
|
+
}
|
package/src/contexts.jsx
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createContext } from 'react'
|
|
2
2
|
|
|
3
3
|
import { webchatInitialState } from './webchat/hooks'
|
|
4
4
|
|
|
5
|
-
export const RequestContext =
|
|
5
|
+
export const RequestContext = createContext({
|
|
6
6
|
getString: () => '',
|
|
7
7
|
setLocale: () => '',
|
|
8
8
|
session: {},
|
|
@@ -12,7 +12,7 @@ export const RequestContext = React.createContext({
|
|
|
12
12
|
defaultTyping: 0,
|
|
13
13
|
})
|
|
14
14
|
|
|
15
|
-
export const WebchatContext =
|
|
15
|
+
export const WebchatContext = createContext({
|
|
16
16
|
sendText: text => {},
|
|
17
17
|
sendAttachment: attachment => {},
|
|
18
18
|
sendPayload: payload => {},
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BotRequest as CoreBotRequest,
|
|
3
|
+
Input as CoreInput,
|
|
4
|
+
InputType as CoreInputType,
|
|
5
|
+
Plugin as CorePlugin,
|
|
6
|
+
Route as CoreRoute,
|
|
7
|
+
Routes as CoreRoutes,
|
|
8
|
+
Session as CoreSession,
|
|
9
|
+
SessionUser as CoreSessionUser,
|
|
10
|
+
} from '@botonic/core/lib/esm/models/legacy-types'
|
|
11
|
+
import React from 'react'
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
ButtonProps,
|
|
15
|
+
ReplyProps,
|
|
16
|
+
ThemeProps,
|
|
17
|
+
WebchatSettingsProps,
|
|
18
|
+
Webview,
|
|
19
|
+
} from './components/index-types'
|
|
20
|
+
import { WebchatState } from './webchat'
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* See @botonic/core's Response for the description of the Response's semantics*/
|
|
24
|
+
export interface BotResponse extends CoreBotRequest {
|
|
25
|
+
response: [React.ReactNode]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface Route extends CoreRoute {
|
|
29
|
+
action?: React.ComponentType<any>
|
|
30
|
+
retryAction?: React.ComponentType<any>
|
|
31
|
+
}
|
|
32
|
+
export type Routes = CoreRoutes<Route>
|
|
33
|
+
|
|
34
|
+
// Parameters of the actions' botonicInit method
|
|
35
|
+
export interface ActionRequest {
|
|
36
|
+
defaultDelay: number
|
|
37
|
+
defaultTyping: number
|
|
38
|
+
input: CoreInput
|
|
39
|
+
lastRoutePath: string
|
|
40
|
+
params: { [key: string]: string }
|
|
41
|
+
plugins: { [id: string]: CorePlugin }
|
|
42
|
+
session: CoreSession
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface RequestContextInterface extends ActionRequest {
|
|
46
|
+
getString: (stringId: string) => string
|
|
47
|
+
setLocale: (locale: string) => string
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface CustomMessageType {
|
|
51
|
+
customTypeName: string
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// TODO: Reuse types to be reused in respective components
|
|
55
|
+
// export class WebchatApp {
|
|
56
|
+
// constructor(options: WebchatAppArgs)
|
|
57
|
+
// addBotMessage(message: WebchatMessage): void
|
|
58
|
+
// addBotText(text: string): void
|
|
59
|
+
// addUserMessage(message: WebchatMessage): void
|
|
60
|
+
// addUserPayload(payload: string): void
|
|
61
|
+
// addUserText(text: string): void
|
|
62
|
+
// clearMessages(): void
|
|
63
|
+
// close(): void
|
|
64
|
+
// closeCoverComponent(): void
|
|
65
|
+
// destroy(): void
|
|
66
|
+
// getComponent(
|
|
67
|
+
// host: HTMLElement,
|
|
68
|
+
// optionsAtRuntime?: WebchatAppArgs
|
|
69
|
+
// ): React.ForwardRefExoticComponent<any>
|
|
70
|
+
// getLastMessageUpdate(): string
|
|
71
|
+
// getMessages(): WebchatMessage[]
|
|
72
|
+
// getVisibility(): Promise<boolean>
|
|
73
|
+
// isWebchatVisible({ appId: string }): Promise<boolean>
|
|
74
|
+
// onCloseWebchat(args: any): void
|
|
75
|
+
// onInitWebchat(args: any): void
|
|
76
|
+
// onOpenWebchat(args: any): void
|
|
77
|
+
// onServiceEvent(event: Event): void
|
|
78
|
+
// onStateChange(args: OnStateChangeArgs): void
|
|
79
|
+
// onUserInput(args: OnUserInputArgs): Promise<void>
|
|
80
|
+
// open(): void
|
|
81
|
+
// openCoverComponent(): void
|
|
82
|
+
// render(dest?: HTMLElement, optionsAtRuntime?: WebchatAppArgs): void
|
|
83
|
+
// resendUnsentInputs(): Promise<void>
|
|
84
|
+
// resolveWebchatVisibility(optionsAtRuntime: {
|
|
85
|
+
// appId: string
|
|
86
|
+
// visibility: () => boolean
|
|
87
|
+
// }): Promise<boolean>
|
|
88
|
+
// setTyping(enable: boolean): void
|
|
89
|
+
// toggle(): void
|
|
90
|
+
// toggleCoverComponent(): void
|
|
91
|
+
// updateMessageInfo(msgId: string, messageInfo: MessageInfo): void
|
|
92
|
+
// updateLastMessageDate(date: string): void
|
|
93
|
+
// updateUser(user: Partial<CoreSessionUser>): void
|
|
94
|
+
// updateWebchatSettings(settings: WebchatSettingsProps): void
|
|
95
|
+
// renderCustomComponent(customComponent: React.ReactNode): void
|
|
96
|
+
// unmountCustomComponent(): void
|
|
97
|
+
// }
|
|
98
|
+
|
|
99
|
+
// export interface WebchatArgs {
|
|
100
|
+
// blockInputs?: BlockInputOption[]
|
|
101
|
+
// coverComponent?: CoverComponentOptions
|
|
102
|
+
// defaultDelay?: number
|
|
103
|
+
// defaultTyping?: number
|
|
104
|
+
// enableAnimations?: boolean
|
|
105
|
+
// enableAttachments?: boolean
|
|
106
|
+
// enableEmojiPicker?: boolean
|
|
107
|
+
// enableUserInput?: boolean
|
|
108
|
+
// shadowDOM?: boolean | (() => boolean)
|
|
109
|
+
// hostId?: string
|
|
110
|
+
// getString?: (stringId: string, session: CoreSession) => string
|
|
111
|
+
// onClose?: (app: WebchatApp, args: any) => void
|
|
112
|
+
// onInit?: (app: WebchatApp, args: any) => void
|
|
113
|
+
// onMessage?: (app: WebchatApp, message: WebchatMessage) => void
|
|
114
|
+
// onOpen?: (app: WebchatApp, args: any) => void
|
|
115
|
+
// onConnectionChange?: (app: WebchatApp, isOnline: boolean) => void
|
|
116
|
+
// persistentMenu?: PersistentMenuTheme
|
|
117
|
+
// storage?: Storage | null
|
|
118
|
+
// storageKey?: any
|
|
119
|
+
// theme?: ThemeProps
|
|
120
|
+
// }
|
|
121
|
+
|
|
122
|
+
// export interface WebchatAppArgs extends WebchatArgs {
|
|
123
|
+
export interface WebchatAppArgs {
|
|
124
|
+
appId?: string
|
|
125
|
+
visibility?: () => boolean
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export interface WebchatMessage {
|
|
129
|
+
ack: 0 | 1
|
|
130
|
+
buttons: ButtonProps[]
|
|
131
|
+
data: any
|
|
132
|
+
delay: number
|
|
133
|
+
display: boolean
|
|
134
|
+
from: 'user' | 'bot'
|
|
135
|
+
id: string
|
|
136
|
+
markdown: boolean
|
|
137
|
+
replies: ReplyProps[]
|
|
138
|
+
timestamp: string
|
|
139
|
+
type: CoreInputType
|
|
140
|
+
typing: number
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export interface OnUserInputArgs {
|
|
144
|
+
input: CoreInput
|
|
145
|
+
lastRoutePath?: string
|
|
146
|
+
session?: CoreSession
|
|
147
|
+
user: CoreSessionUser
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export interface OnStateChangeArgs {
|
|
151
|
+
messagesJSON: WebchatMessage[]
|
|
152
|
+
user: CoreSessionUser
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export interface MessageInfo {
|
|
156
|
+
data: any | 'typing_on'
|
|
157
|
+
id: string
|
|
158
|
+
type: 'update_webchat_settings' | 'sender_action'
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export interface Event {
|
|
162
|
+
action?: 'update_message_info'
|
|
163
|
+
isError?: boolean
|
|
164
|
+
message?: MessageInfo
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export interface WebchatContextProps {
|
|
168
|
+
sendText: (text: string, payload?: string) => void
|
|
169
|
+
sendAttachment: (attachment: File) => void
|
|
170
|
+
sendPayload: (payload: string) => void
|
|
171
|
+
sendInput: (input: CoreInput) => void
|
|
172
|
+
openWebview: (webviewComponent: Webview) => void
|
|
173
|
+
addMessage: (message: WebchatMessage) => void
|
|
174
|
+
updateMessage: (message: WebchatMessage) => void
|
|
175
|
+
updateReplies: (replies: boolean) => void
|
|
176
|
+
updateLatestInput: (input: CoreInput) => void
|
|
177
|
+
closeWebview: () => void
|
|
178
|
+
toggleWebchat: () => void
|
|
179
|
+
getThemeProperty: (property: string, defaultValue?: string) => any
|
|
180
|
+
resolveCase: () => void
|
|
181
|
+
theme: ThemeProps
|
|
182
|
+
webchatState: WebchatState
|
|
183
|
+
updateWebchatDevSettings: (settings: WebchatSettingsProps) => void
|
|
184
|
+
updateUser: (user: Partial<CoreSessionUser>) => void
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// export class DevApp extends WebchatApp {
|
|
188
|
+
// constructor(args: WebchatAppArgs)
|
|
189
|
+
// onUserInput(args: OnUserInputArgs): Promise<void>
|
|
190
|
+
// render(dest: HTMLElement, optionsAtRuntime: WebchatAppArgs): void
|
|
191
|
+
// }
|
|
192
|
+
|
|
193
|
+
export * from './components'
|
|
194
|
+
export * from './util'
|
|
195
|
+
export * from './webchat'
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export { BotonicInputTester, BotonicOutputTester } from './botonic-tester'
|
|
2
|
-
export * from './components'
|
|
2
|
+
// export * from './components'
|
|
3
3
|
export { RequestContext, WebchatContext } from './contexts'
|
|
4
4
|
export { DevApp } from './dev-app'
|
|
5
|
+
export * from './index-types'
|
|
5
6
|
export { msgsToBotonic, msgToBotonic } from './msg-to-botonic'
|
|
6
7
|
export { NodeApp } from './node-app'
|
|
7
|
-
export
|
|
8
|
-
export { getBotonicApp, Webchat } from './webchat/index
|
|
8
|
+
export * from './util'
|
|
9
|
+
// export { getBotonicApp, Webchat } from './webchat/index'
|
|
9
10
|
export { WebchatApp } from './webchat-app'
|
|
10
11
|
export { WebviewApp } from './webview-app'
|
package/src/message-utils.js
CHANGED
package/src/react-bot.jsx
CHANGED
package/src/util/webchat.js
CHANGED
|
@@ -10,20 +10,21 @@ import { getProperty } from './objects'
|
|
|
10
10
|
* It gives preference to nested defined properties (e.g.: header.style) over plain properties (e.g.: headerStyle).
|
|
11
11
|
* If property doesn't exist, returns the defaultValue.
|
|
12
12
|
*/
|
|
13
|
-
export const _getThemeProperty =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
export const _getThemeProperty = theme => (
|
|
14
|
+
property,
|
|
15
|
+
defaultValue = undefined
|
|
16
|
+
) => {
|
|
17
|
+
for (const [k, v] of Object.entries(WEBCHAT.CUSTOM_PROPERTIES)) {
|
|
18
|
+
if (v == property) {
|
|
19
|
+
const nestedProperty = getProperty(theme, v)
|
|
20
|
+
if (nestedProperty !== undefined) return nestedProperty
|
|
21
|
+
const plainProperty = getProperty(theme, k)
|
|
22
|
+
if (plainProperty !== undefined) return plainProperty
|
|
23
|
+
return defaultValue
|
|
24
24
|
}
|
|
25
|
-
return undefined
|
|
26
25
|
}
|
|
26
|
+
return undefined
|
|
27
|
+
}
|
|
27
28
|
|
|
28
29
|
export const createUser = () => {
|
|
29
30
|
const parser = new UAParser()
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import type {
|
|
2
|
+
Input as CoreInput,
|
|
3
|
+
Session as CoreSession,
|
|
4
|
+
} from '@botonic/core/lib/esm/models/legacy-types'
|
|
3
5
|
import { RefObject } from 'react'
|
|
4
6
|
|
|
5
|
-
import {
|
|
6
|
-
import { Message, WebchatApp, WebchatArgs } from '../index'
|
|
7
|
+
import { Webview } from '../components/index-types'
|
|
7
8
|
|
|
8
9
|
export interface WebchatStateTheme {
|
|
9
10
|
headerTitle: string
|
|
@@ -20,13 +21,13 @@ export interface WebchatState {
|
|
|
20
21
|
width: number
|
|
21
22
|
height: number
|
|
22
23
|
messagesJSON: any[]
|
|
23
|
-
messagesComponents:
|
|
24
|
-
replies:
|
|
25
|
-
latestInput: Partial<
|
|
24
|
+
messagesComponents: any[]
|
|
25
|
+
replies: any[]
|
|
26
|
+
latestInput: Partial<CoreInput>
|
|
26
27
|
typing: boolean
|
|
27
28
|
webview: Webview | null
|
|
28
29
|
webviewParams: null
|
|
29
|
-
session: Partial<
|
|
30
|
+
session: Partial<CoreSession>
|
|
30
31
|
lastRoutePath: string | null
|
|
31
32
|
handoff: boolean
|
|
32
33
|
theme: WebchatStateTheme
|
|
@@ -41,11 +42,11 @@ export interface WebchatState {
|
|
|
41
42
|
currentAttachment: File | undefined
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
export interface WebchatProps extends WebchatArgs {
|
|
45
|
+
// export interface WebchatProps extends WebchatArgs {
|
|
46
|
+
export interface WebchatProps {
|
|
45
47
|
ref: RefObject<any>
|
|
46
48
|
onConnectionRegained?: () => Promise<void>
|
|
47
49
|
}
|
|
48
|
-
export const WebChat: React.ForwardRefExoticComponent<WebchatProps>
|
|
49
50
|
|
|
50
51
|
export interface WebchatDevProps extends WebchatProps {
|
|
51
52
|
initialDevSettings?: {
|
|
@@ -53,9 +54,6 @@ export interface WebchatDevProps extends WebchatProps {
|
|
|
53
54
|
showSessionView?: boolean
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
|
-
export const WebChatDev: React.ForwardRefExoticComponent<WebchatDevProps>
|
|
57
|
-
|
|
58
|
-
export function getBotonicApp(): WebchatApp
|
|
59
57
|
|
|
60
58
|
export interface CoverComponentProps {
|
|
61
59
|
closeComponent: () => void
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
1
2
|
export { Webchat } from './webchat'
|
|
2
3
|
export { WebchatDev } from './webchat-dev'
|
|
3
4
|
|
|
4
|
-
/**
|
|
5
|
-
* @returns {WebChatApp}
|
|
6
|
-
*/
|
|
7
5
|
export function getBotonicApp() {
|
|
8
6
|
// Botonic is exported from your bot
|
|
9
7
|
// eslint-disable-next-line no-undef
|
|
10
8
|
return Botonic
|
|
11
9
|
}
|
|
10
|
+
|
|
11
|
+
export * from './index-types'
|
package/src/webchat-app.jsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { HubtypeService
|
|
1
|
+
import { HubtypeService } from '@botonic/core'
|
|
2
|
+
import { INPUT } from '@botonic/core/lib/esm/models/legacy-types'
|
|
2
3
|
import merge from 'lodash.merge'
|
|
3
4
|
import React, { createRef } from 'react'
|
|
4
5
|
import { render, unmountComponentAtNode } from 'react-dom'
|
package/src/index.d.ts
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
import * as core from '@botonic/core'
|
|
2
|
-
import * as React from 'react'
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
BlockInputOption,
|
|
6
|
-
ButtonProps,
|
|
7
|
-
CoverComponentOptions,
|
|
8
|
-
PersistentMenuTheme,
|
|
9
|
-
ReplyProps,
|
|
10
|
-
ThemeProps,
|
|
11
|
-
WebchatSettingsProps,
|
|
12
|
-
Webview,
|
|
13
|
-
} from './components'
|
|
14
|
-
import { WebchatState } from './webchat'
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* See @botonic/core's Response for the description of the Response's semantics*/
|
|
18
|
-
export interface BotResponse extends core.BotRequest {
|
|
19
|
-
response: [React.ReactNode]
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface Route extends core.Route {
|
|
23
|
-
action?: React.ComponentType<any>
|
|
24
|
-
retryAction?: React.ComponentType<any>
|
|
25
|
-
}
|
|
26
|
-
type Routes = core.Routes<Route>
|
|
27
|
-
|
|
28
|
-
export class ReactBot extends core.CoreBot {
|
|
29
|
-
renderReactActions({
|
|
30
|
-
actions,
|
|
31
|
-
request: ActionRequest,
|
|
32
|
-
}): Promise<React.ReactNode>
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export class NodeApp {
|
|
36
|
-
constructor(options: Omit<core.CoreBotConfig, 'renderer'>)
|
|
37
|
-
bot: ReactBot
|
|
38
|
-
input(request: core.BotRequest): Promise<BotResponse>
|
|
39
|
-
renderNode(args): string
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Parameters of the actions' botonicInit method
|
|
43
|
-
export interface ActionRequest {
|
|
44
|
-
defaultDelay: number
|
|
45
|
-
defaultTyping: number
|
|
46
|
-
input: core.Input
|
|
47
|
-
lastRoutePath: string
|
|
48
|
-
params: { [key: string]: string }
|
|
49
|
-
plugins: { [id: string]: core.Plugin }
|
|
50
|
-
session: core.Session
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export class BotonicInputTester {
|
|
54
|
-
constructor(app: NodeApp)
|
|
55
|
-
|
|
56
|
-
text(
|
|
57
|
-
inp: string,
|
|
58
|
-
session?: core.Session,
|
|
59
|
-
lastRoutePath?: string
|
|
60
|
-
): Promise<string>
|
|
61
|
-
|
|
62
|
-
payload(
|
|
63
|
-
inp: string,
|
|
64
|
-
session?: core.Session,
|
|
65
|
-
lastRoutePath?: string
|
|
66
|
-
): Promise<string>
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export class BotonicOutputTester {
|
|
70
|
-
constructor(app: NodeApp)
|
|
71
|
-
|
|
72
|
-
text(out: string, replies?: any): Promise<string>
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export interface RequestContextInterface extends ActionRequest {
|
|
76
|
-
getString: (stringId: string) => string
|
|
77
|
-
setLocale: (locale: string) => string
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export const RequestContext: React.Context<RequestContextInterface>
|
|
81
|
-
export type RequestContext = React.Context<RequestContextInterface>
|
|
82
|
-
|
|
83
|
-
export interface CustomMessageType {
|
|
84
|
-
customTypeName: string
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function msgToBotonic(
|
|
88
|
-
msg: any,
|
|
89
|
-
customMessageTypes?: CustomMessageType[]
|
|
90
|
-
): React.ReactNode
|
|
91
|
-
|
|
92
|
-
export function msgsToBotonic(
|
|
93
|
-
msgs: any | any[],
|
|
94
|
-
customMessageTypes?: CustomMessageType[]
|
|
95
|
-
): React.ReactNode
|
|
96
|
-
|
|
97
|
-
export interface WebchatArgs {
|
|
98
|
-
blockInputs?: BlockInputOption[]
|
|
99
|
-
coverComponent?: CoverComponentOptions
|
|
100
|
-
defaultDelay?: number
|
|
101
|
-
defaultTyping?: number
|
|
102
|
-
enableAnimations?: boolean
|
|
103
|
-
enableAttachments?: boolean
|
|
104
|
-
enableEmojiPicker?: boolean
|
|
105
|
-
enableUserInput?: boolean
|
|
106
|
-
shadowDOM?: boolean | (() => boolean)
|
|
107
|
-
hostId?: string
|
|
108
|
-
getString?: (stringId: string, session: core.Session) => string
|
|
109
|
-
onClose?: (app: WebchatApp, args: any) => void
|
|
110
|
-
onInit?: (app: WebchatApp, args: any) => void
|
|
111
|
-
onMessage?: (app: WebchatApp, message: WebchatMessage) => void
|
|
112
|
-
onOpen?: (app: WebchatApp, args: any) => void
|
|
113
|
-
onConnectionChange?: (app: WebchatApp, isOnline: boolean) => void
|
|
114
|
-
persistentMenu?: PersistentMenuTheme
|
|
115
|
-
storage?: Storage | null
|
|
116
|
-
storageKey?: any
|
|
117
|
-
theme?: ThemeProps
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export interface WebchatAppArgs extends WebchatArgs {
|
|
121
|
-
appId?: string
|
|
122
|
-
visibility?: () => boolean
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export interface WebchatMessage {
|
|
126
|
-
ack: 0 | 1
|
|
127
|
-
buttons: ButtonProps[]
|
|
128
|
-
data: any
|
|
129
|
-
delay: number
|
|
130
|
-
display: boolean
|
|
131
|
-
from: 'user' | 'bot'
|
|
132
|
-
id: string
|
|
133
|
-
markdown: boolean
|
|
134
|
-
replies: ReplyProps[]
|
|
135
|
-
timestamp: string
|
|
136
|
-
type: core.InputType
|
|
137
|
-
typing: number
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export interface OnUserInputArgs {
|
|
141
|
-
input: core.Input
|
|
142
|
-
lastRoutePath?: string
|
|
143
|
-
session?: core.Session
|
|
144
|
-
user: core.SessionUser
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export interface OnStateChangeArgs {
|
|
148
|
-
messagesJSON: WebchatMessage[]
|
|
149
|
-
user: core.SessionUser
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export interface MessageInfo {
|
|
153
|
-
data: any | 'typing_on'
|
|
154
|
-
id: string
|
|
155
|
-
type: 'update_webchat_settings' | 'sender_action'
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export interface Event {
|
|
159
|
-
action?: 'update_message_info'
|
|
160
|
-
isError?: boolean
|
|
161
|
-
message?: MessageInfo
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export class WebchatApp {
|
|
165
|
-
constructor(options: WebchatAppArgs)
|
|
166
|
-
addBotMessage(message: WebchatMessage): void
|
|
167
|
-
addBotText(text: string): void
|
|
168
|
-
addUserMessage(message: WebchatMessage): void
|
|
169
|
-
addUserPayload(payload: string): void
|
|
170
|
-
addUserText(text: string): void
|
|
171
|
-
clearMessages(): void
|
|
172
|
-
close(): void
|
|
173
|
-
closeCoverComponent(): void
|
|
174
|
-
destroy(): void
|
|
175
|
-
getComponent(
|
|
176
|
-
host: HTMLElement,
|
|
177
|
-
optionsAtRuntime?: WebchatAppArgs
|
|
178
|
-
): React.ForwardRefExoticComponent<any>
|
|
179
|
-
getLastMessageUpdate(): string
|
|
180
|
-
getMessages(): WebchatMessage[]
|
|
181
|
-
getVisibility(): Promise<boolean>
|
|
182
|
-
isWebchatVisible({ appId: string }): Promise<boolean>
|
|
183
|
-
onCloseWebchat(args: any): void
|
|
184
|
-
onInitWebchat(args: any): void
|
|
185
|
-
onOpenWebchat(args: any): void
|
|
186
|
-
onServiceEvent(event: Event): void
|
|
187
|
-
onStateChange(args: OnStateChangeArgs): void
|
|
188
|
-
onUserInput(args: OnUserInputArgs): Promise<void>
|
|
189
|
-
open(): void
|
|
190
|
-
openCoverComponent(): void
|
|
191
|
-
render(dest?: HTMLElement, optionsAtRuntime?: WebchatAppArgs): void
|
|
192
|
-
resendUnsentInputs(): Promise<void>
|
|
193
|
-
resolveWebchatVisibility(optionsAtRuntime: {
|
|
194
|
-
appId: string
|
|
195
|
-
visibility: () => boolean
|
|
196
|
-
}): Promise<boolean>
|
|
197
|
-
setTyping(enable: boolean): void
|
|
198
|
-
toggle(): void
|
|
199
|
-
toggleCoverComponent(): void
|
|
200
|
-
updateMessageInfo(msgId: string, messageInfo: MessageInfo): void
|
|
201
|
-
updateLastMessageDate(date: string): void
|
|
202
|
-
updateUser(user: Partial<core.SessionUser>): void
|
|
203
|
-
updateWebchatSettings(settings: WebchatSettingsProps): void
|
|
204
|
-
renderCustomComponent(customComponent: React.ReactNode): void
|
|
205
|
-
unmountCustomComponent(): void
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
export interface WebchatContextProps {
|
|
209
|
-
sendText: (text: string, payload?: string) => void
|
|
210
|
-
sendAttachment: (attachment: File) => void
|
|
211
|
-
sendPayload: (payload: string) => void
|
|
212
|
-
sendInput: (input: core.Input) => void
|
|
213
|
-
openWebview: (webviewComponent: Webview) => void
|
|
214
|
-
addMessage: (message: WebchatMessage) => void
|
|
215
|
-
updateMessage: (message: WebchatMessage) => void
|
|
216
|
-
updateReplies: (replies: boolean) => void
|
|
217
|
-
updateLatestInput: (input: core.Input) => void
|
|
218
|
-
closeWebview: () => void
|
|
219
|
-
toggleWebchat: () => void
|
|
220
|
-
getThemeProperty: (property: string, defaultValue?: string) => any
|
|
221
|
-
resolveCase: () => void
|
|
222
|
-
theme: ThemeProps
|
|
223
|
-
webchatState: WebchatState
|
|
224
|
-
updateWebchatDevSettings: (settings: WebchatSettingsProps) => void
|
|
225
|
-
updateUser: (user: Partial<core.SessionUser>) => void
|
|
226
|
-
}
|
|
227
|
-
export const WebchatContext: React.Context<WebchatContextProps>
|
|
228
|
-
export type WebchatContext = React.Context<WebchatContextProps>
|
|
229
|
-
|
|
230
|
-
export class DevApp extends WebchatApp {
|
|
231
|
-
constructor(args: WebchatAppArgs)
|
|
232
|
-
onUserInput(args: OnUserInputArgs): Promise<void>
|
|
233
|
-
render(dest: HTMLElement, optionsAtRuntime: WebchatAppArgs): void
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
export * from './components'
|
|
237
|
-
export * from './util'
|
|
238
|
-
export * from './webchat'
|
package/src/util/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ReactElement, ReactNode } from 'react'
|
|
2
|
-
|
|
3
|
-
export function staticAsset(path: string): string
|
|
4
|
-
export function hasComplexChildren(
|
|
5
|
-
element: ReactNode
|
|
6
|
-
): ReactElement<{ children: ReactNode[] }>
|
|
7
|
-
|
|
8
|
-
export const isDev: boolean
|
|
9
|
-
export const isProd: boolean
|
package/src/util/index.js
DELETED
|
File without changes
|