@botonic/react 0.20.1-alpha.1 → 0.20.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.
Files changed (128) hide show
  1. package/lib/app.js +4 -3
  2. package/lib/app.js.map +1 -1
  3. package/lib/components/button.js +22 -2
  4. package/lib/components/button.js.map +1 -1
  5. package/lib/components/buttons-disabler.js +2 -2
  6. package/lib/components/carousel.js +2 -2
  7. package/lib/components/custom-message.js +2 -2
  8. package/lib/components/document.js +2 -2
  9. package/lib/components/image.js +28 -32
  10. package/lib/components/image.js.map +1 -1
  11. package/lib/components/message.js +2 -2
  12. package/lib/components/multichannel/facebook/facebook.js +2 -2
  13. package/lib/components/reply.js +2 -2
  14. package/lib/components/subtitle.js +2 -2
  15. package/lib/components/text.js +2 -2
  16. package/lib/components/timestamps.js +2 -2
  17. package/lib/components/title.js +2 -2
  18. package/lib/constants.js +201 -0
  19. package/lib/constants.js.map +1 -0
  20. package/lib/contexts.js +57 -0
  21. package/lib/contexts.js.map +1 -0
  22. package/lib/dev-app.js +241 -0
  23. package/lib/dev-app.js.map +1 -0
  24. package/lib/index.d.ts +241 -0
  25. package/lib/index.js +131 -0
  26. package/lib/index.js.map +1 -0
  27. package/lib/message-utils.js +149 -0
  28. package/lib/message-utils.js.map +1 -0
  29. package/lib/msg-to-botonic.js +199 -0
  30. package/lib/msg-to-botonic.js.map +1 -0
  31. package/lib/node-app.js +97 -0
  32. package/lib/node-app.js.map +1 -0
  33. package/lib/react-bot.js +167 -0
  34. package/lib/react-bot.js.map +1 -0
  35. package/lib/util/dom.js +84 -0
  36. package/lib/util/dom.js.map +1 -0
  37. package/lib/util/environment.js +42 -0
  38. package/lib/util/environment.js.map +1 -0
  39. package/lib/util/error-boundary.js +105 -0
  40. package/lib/util/error-boundary.js.map +1 -0
  41. package/lib/util/index.d.ts +9 -0
  42. package/lib/util/index.js +2 -0
  43. package/lib/util/index.js.map +1 -0
  44. package/lib/util/logs.js +28 -0
  45. package/lib/util/logs.js.map +1 -0
  46. package/lib/util/objects.js +60 -0
  47. package/lib/util/objects.js.map +1 -0
  48. package/lib/util/react.js +75 -0
  49. package/lib/util/react.js.map +1 -0
  50. package/lib/util/regexs.js +31 -0
  51. package/lib/util/regexs.js.map +1 -0
  52. package/lib/util/webchat.js +92 -0
  53. package/lib/util/webchat.js.map +1 -0
  54. package/lib/webchat/actions.js +53 -0
  55. package/lib/webchat/actions.js.map +1 -0
  56. package/lib/webchat/components/attachment.js +43 -0
  57. package/lib/webchat/components/attachment.js.map +1 -0
  58. package/lib/webchat/components/common.js +33 -0
  59. package/lib/webchat/components/common.js.map +1 -0
  60. package/lib/webchat/components/emoji-picker.js +58 -0
  61. package/lib/webchat/components/emoji-picker.js.map +1 -0
  62. package/lib/webchat/components/persistent-menu.js +96 -0
  63. package/lib/webchat/components/persistent-menu.js.map +1 -0
  64. package/lib/webchat/components/send-button.js +27 -0
  65. package/lib/webchat/components/send-button.js.map +1 -0
  66. package/lib/webchat/components/styled-scrollbar.js +55 -0
  67. package/lib/webchat/components/styled-scrollbar.js.map +1 -0
  68. package/lib/webchat/components/styled-scrollbar.scss +12 -0
  69. package/lib/webchat/components/typing-indicator.js +27 -0
  70. package/lib/webchat/components/typing-indicator.js.map +1 -0
  71. package/lib/webchat/components/typing-indicator.scss +38 -0
  72. package/lib/webchat/devices/device-adapter.js +82 -0
  73. package/lib/webchat/devices/device-adapter.js.map +1 -0
  74. package/lib/webchat/devices/index.js +32 -0
  75. package/lib/webchat/devices/index.js.map +1 -0
  76. package/lib/webchat/devices/scrollbar-controller.js +152 -0
  77. package/lib/webchat/devices/scrollbar-controller.js.map +1 -0
  78. package/lib/webchat/devices/webchat-resizer.js +76 -0
  79. package/lib/webchat/devices/webchat-resizer.js.map +1 -0
  80. package/lib/webchat/header.js +116 -0
  81. package/lib/webchat/header.js.map +1 -0
  82. package/lib/webchat/hooks.js +359 -0
  83. package/lib/webchat/hooks.js.map +1 -0
  84. package/lib/webchat/index.d.ts +62 -0
  85. package/lib/webchat/index.js +32 -0
  86. package/lib/webchat/index.js.map +1 -0
  87. package/lib/webchat/message-list.js +88 -0
  88. package/lib/webchat/message-list.js.map +1 -0
  89. package/lib/webchat/messages-reducer.js +93 -0
  90. package/lib/webchat/messages-reducer.js.map +1 -0
  91. package/lib/webchat/replies.js +78 -0
  92. package/lib/webchat/replies.js.map +1 -0
  93. package/lib/webchat/session-view.js +106 -0
  94. package/lib/webchat/session-view.js.map +1 -0
  95. package/lib/webchat/use-storage-state-hook.js +29 -0
  96. package/lib/webchat/use-storage-state-hook.js.map +1 -0
  97. package/lib/webchat/webchat-dev.js +109 -0
  98. package/lib/webchat/webchat-dev.js.map +1 -0
  99. package/lib/webchat/webchat-reducer.js +108 -0
  100. package/lib/webchat/webchat-reducer.js.map +1 -0
  101. package/lib/webchat/webchat.js +1059 -0
  102. package/lib/webchat/webchat.js.map +1 -0
  103. package/lib/webchat/webview.js +122 -0
  104. package/lib/webchat/webview.js.map +1 -0
  105. package/lib/webchat-app.js +653 -0
  106. package/lib/webchat-app.js.map +1 -0
  107. package/lib/webchat.template.html +37 -0
  108. package/lib/webview.js +214 -0
  109. package/lib/webview.js.map +1 -0
  110. package/lib/webview.template.html +39 -0
  111. package/package.json +2 -2
  112. package/src/components/button.jsx +21 -1
  113. package/src/components/image.jsx +22 -27
  114. package/src/components/index.d.ts +5 -1
  115. package/src/constants.js +1 -0
  116. package/src/index.d.ts +3 -7
  117. package/src/index.js +0 -1
  118. package/src/webchat/actions.jsx +1 -1
  119. package/src/webchat/hooks.js +5 -5
  120. package/src/webchat/webchat-reducer.js +3 -3
  121. package/src/webchat/webchat.jsx +20 -17
  122. package/src/webchat-app.jsx +4 -4
  123. package/src/webchat/components/portal-modal/backdrop.jsx +0 -38
  124. package/src/webchat/components/portal-modal/constants.js +0 -7
  125. package/src/webchat/components/portal-modal/content.jsx +0 -10
  126. package/src/webchat/components/portal-modal/index.js +0 -5
  127. package/src/webchat/components/portal-modal/portal-modal-component.jsx +0 -72
  128. package/src/webchat/components/portal-modal/portal.jsx +0 -21
package/lib/index.d.ts ADDED
@@ -0,0 +1,241 @@
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 interface BotOptions extends core.BotOptions {
29
+ routes: Routes
30
+ }
31
+
32
+ export class ReactBot extends core.CoreBot {
33
+ renderReactActions({
34
+ actions,
35
+ request: ActionRequest,
36
+ }): Promise<React.ReactNode>
37
+ }
38
+
39
+ export class NodeApp {
40
+ constructor(options: Omit<BotOptions, 'renderer'>)
41
+ bot: ReactBot
42
+ input(request: core.BotRequest): Promise<BotResponse>
43
+ renderNode(args): string
44
+ }
45
+
46
+ // Parameters of the actions' botonicInit method
47
+ export interface ActionRequest {
48
+ defaultDelay: number
49
+ defaultTyping: number
50
+ input: core.Input
51
+ lastRoutePath: string
52
+ params: { [key: string]: string }
53
+ plugins: { [id: string]: core.Plugin }
54
+ session: core.Session
55
+ }
56
+
57
+ export class BotonicInputTester {
58
+ constructor(app: NodeApp)
59
+
60
+ text(
61
+ inp: string,
62
+ session?: core.Session,
63
+ lastRoutePath?: string
64
+ ): Promise<string>
65
+
66
+ payload(
67
+ inp: string,
68
+ session?: core.Session,
69
+ lastRoutePath?: string
70
+ ): Promise<string>
71
+ }
72
+
73
+ export class BotonicOutputTester {
74
+ constructor(app: NodeApp)
75
+
76
+ text(out: string, replies?: any): Promise<string>
77
+ }
78
+
79
+ export interface RequestContextInterface extends ActionRequest {
80
+ getString: (stringId: string) => string
81
+ setLocale: (locale: string) => string
82
+ }
83
+
84
+ export const RequestContext: React.Context<RequestContextInterface>
85
+ export type RequestContext = React.Context<RequestContextInterface>
86
+
87
+ export interface CustomMessageType {
88
+ customTypeName: string
89
+ }
90
+
91
+ export function msgToBotonic(
92
+ msg: any,
93
+ customMessageTypes?: CustomMessageType[]
94
+ ): React.ReactNode
95
+
96
+ export function msgsToBotonic(
97
+ msgs: any | any[],
98
+ customMessageTypes?: CustomMessageType[]
99
+ ): React.ReactNode
100
+
101
+ export interface WebchatArgs {
102
+ blockInputs?: BlockInputOption[]
103
+ coverComponent?: CoverComponentOptions
104
+ defaultDelay?: number
105
+ defaultTyping?: number
106
+ enableAnimations?: boolean
107
+ enableAttachments?: boolean
108
+ enableEmojiPicker?: boolean
109
+ enableUserInput?: boolean
110
+ shadowDOM?: boolean | (() => boolean)
111
+ hostId?: string
112
+ getString?: (stringId: string, session: core.Session) => string
113
+ onClose?: (app: WebchatApp, args: any) => void
114
+ onInit?: (app: WebchatApp, args: any) => void
115
+ onMessage?: (app: WebchatApp, message: WebchatMessage) => void
116
+ onOpen?: (app: WebchatApp, args: any) => void
117
+ onConnectionChange?: (app: WebchatApp, isOnline: boolean) => void
118
+ persistentMenu?: PersistentMenuTheme
119
+ storage?: Storage
120
+ storageKey?: any
121
+ theme?: ThemeProps
122
+ }
123
+
124
+ export interface WebchatAppArgs extends WebchatArgs {
125
+ appId?: string
126
+ visibility?: () => boolean
127
+ }
128
+
129
+ export interface WebchatMessage {
130
+ ack: 0 | 1
131
+ buttons: ButtonProps[]
132
+ data: any
133
+ delay: number
134
+ display: boolean
135
+ from: 'user' | 'bot'
136
+ id: string
137
+ markdown: boolean
138
+ replies: ReplyProps[]
139
+ timestamp: string
140
+ type: core.InputType
141
+ typing: number
142
+ }
143
+
144
+ export interface OnUserInputArgs {
145
+ input: core.Input
146
+ lastRoutePath?: string
147
+ session?: core.Session
148
+ user: core.SessionUser
149
+ }
150
+
151
+ export interface OnStateChangeArgs {
152
+ messagesJSON: WebchatMessage[]
153
+ user: core.SessionUser
154
+ }
155
+
156
+ export interface MessageInfo {
157
+ data: any | 'typing_on'
158
+ id: string
159
+ type: 'update_webchat_settings' | 'sender_action'
160
+ }
161
+
162
+ export interface Event {
163
+ action?: 'update_message_info'
164
+ isError?: boolean
165
+ message?: MessageInfo
166
+ }
167
+
168
+ export class WebchatApp {
169
+ constructor(options: WebchatAppArgs)
170
+ addBotMessage(message: WebchatMessage): void
171
+ addBotText(text: string): void
172
+ addUserMessage(message: WebchatMessage): void
173
+ addUserPayload(payload: string): void
174
+ addUserText(text: string): void
175
+ clearMessages(): void
176
+ close(): void
177
+ closeCoverComponent(): void
178
+ getComponent(
179
+ host: HTMLElement,
180
+ optionsAtRuntime?: WebchatAppArgs
181
+ ): React.ForwardRefExoticComponent<any>
182
+ getLastMessageUpdate(): string
183
+ getMessages(): WebchatMessage[]
184
+ getVisibility(): Promise<boolean>
185
+ isWebchatVisible({ appId: string }): Promise<boolean>
186
+ onCloseWebchat(args: any): void
187
+ onInitWebchat(args: any): void
188
+ onOpenWebchat(args: any): void
189
+ onServiceEvent(event: Event): void
190
+ onStateChange(args: OnStateChangeArgs): void
191
+ onUserInput(args: OnUserInputArgs): Promise<void>
192
+ open(): void
193
+ openCoverComponent(): void
194
+ render(dest: HTMLElement, optionsAtRuntime: WebchatAppArgs): void
195
+ resendUnsentInputs(): Promise<void>
196
+ resolveWebchatVisibility(optionsAtRuntime: {
197
+ appId: string
198
+ visibility: () => boolean
199
+ }): Promise<boolean>
200
+ setTyping(enable: boolean): void
201
+ toggle(): void
202
+ toggleCoverComponent(): void
203
+ updateMessageInfo(msgId: string, messageInfo: MessageInfo): void
204
+ updateLastMessageDate(date: string): void
205
+ updateUser(user: core.SessionUser): void
206
+ updateWebchatSettings(settings: WebchatSettingsProps): void
207
+ renderCustomComponent(customComponent: React.ReactNode): void
208
+ unmountCustomComponent(): void
209
+ }
210
+
211
+ export interface WebchatContextProps {
212
+ sendText: (text: string) => void
213
+ sendAttachment: (attachment: File) => void
214
+ sendPayload: (payload: string) => void
215
+ sendInput: (input: core.Input) => void
216
+ openWebview: (webviewComponent: Webview) => void
217
+ addMessage: (message: WebchatMessage) => void
218
+ updateMessage: (message: WebchatMessage) => void
219
+ updateReplies: (replies: boolean) => void
220
+ updateLatestInput: (input: core.Input) => void
221
+ closeWebview: () => void
222
+ toggleWebchat: () => void
223
+ getThemeProperty: (property: string, defaultValue?: string) => any
224
+ resolveCase: () => void
225
+ theme: ThemeProps
226
+ webchatState: WebchatState
227
+ updateWebchatDevSettings: (settings: WebchatSettingsProps) => void
228
+ updateUser: (user: core.SessionUser) => void
229
+ }
230
+ export const WebchatContext: React.Context<WebchatContextProps>
231
+ export type WebchatContext = React.Context<WebchatContextProps>
232
+
233
+ export class DevApp extends WebchatApp {
234
+ constructor(args: WebchatAppArgs)
235
+ onUserInput(args: OnUserInputArgs): Promise<void>
236
+ render(dest: HTMLElement, optionsAtRuntime: WebchatAppArgs): void
237
+ }
238
+
239
+ export * from './components'
240
+ export * from './util'
241
+ export * from './webchat'
package/lib/index.js ADDED
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ BotonicInputTester: true,
8
+ BotonicOutputTester: true,
9
+ RequestContext: true,
10
+ WebchatContext: true,
11
+ DevApp: true,
12
+ msgsToBotonic: true,
13
+ msgToBotonic: true,
14
+ NodeApp: true,
15
+ staticAsset: true,
16
+ getBotonicApp: true,
17
+ Webchat: true,
18
+ WebchatApp: true,
19
+ WebviewApp: true
20
+ };
21
+ Object.defineProperty(exports, "BotonicInputTester", {
22
+ enumerable: true,
23
+ get: function get() {
24
+ return _botonicTester.BotonicInputTester;
25
+ }
26
+ });
27
+ Object.defineProperty(exports, "BotonicOutputTester", {
28
+ enumerable: true,
29
+ get: function get() {
30
+ return _botonicTester.BotonicOutputTester;
31
+ }
32
+ });
33
+ Object.defineProperty(exports, "DevApp", {
34
+ enumerable: true,
35
+ get: function get() {
36
+ return _devApp.DevApp;
37
+ }
38
+ });
39
+ Object.defineProperty(exports, "NodeApp", {
40
+ enumerable: true,
41
+ get: function get() {
42
+ return _nodeApp.NodeApp;
43
+ }
44
+ });
45
+ Object.defineProperty(exports, "RequestContext", {
46
+ enumerable: true,
47
+ get: function get() {
48
+ return _contexts.RequestContext;
49
+ }
50
+ });
51
+ Object.defineProperty(exports, "Webchat", {
52
+ enumerable: true,
53
+ get: function get() {
54
+ return _index.Webchat;
55
+ }
56
+ });
57
+ Object.defineProperty(exports, "WebchatApp", {
58
+ enumerable: true,
59
+ get: function get() {
60
+ return _webchatApp.WebchatApp;
61
+ }
62
+ });
63
+ Object.defineProperty(exports, "WebchatContext", {
64
+ enumerable: true,
65
+ get: function get() {
66
+ return _contexts.WebchatContext;
67
+ }
68
+ });
69
+ Object.defineProperty(exports, "WebviewApp", {
70
+ enumerable: true,
71
+ get: function get() {
72
+ return _webview.WebviewApp;
73
+ }
74
+ });
75
+ Object.defineProperty(exports, "getBotonicApp", {
76
+ enumerable: true,
77
+ get: function get() {
78
+ return _index.getBotonicApp;
79
+ }
80
+ });
81
+ Object.defineProperty(exports, "msgToBotonic", {
82
+ enumerable: true,
83
+ get: function get() {
84
+ return _msgToBotonic.msgToBotonic;
85
+ }
86
+ });
87
+ Object.defineProperty(exports, "msgsToBotonic", {
88
+ enumerable: true,
89
+ get: function get() {
90
+ return _msgToBotonic.msgsToBotonic;
91
+ }
92
+ });
93
+ Object.defineProperty(exports, "staticAsset", {
94
+ enumerable: true,
95
+ get: function get() {
96
+ return _environment.staticAsset;
97
+ }
98
+ });
99
+
100
+ var _botonicTester = require("./botonic-tester");
101
+
102
+ var _components = require("./components");
103
+
104
+ Object.keys(_components).forEach(function (key) {
105
+ if (key === "default" || key === "__esModule") return;
106
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
107
+ if (key in exports && exports[key] === _components[key]) return;
108
+ Object.defineProperty(exports, key, {
109
+ enumerable: true,
110
+ get: function get() {
111
+ return _components[key];
112
+ }
113
+ });
114
+ });
115
+
116
+ var _contexts = require("./contexts");
117
+
118
+ var _devApp = require("./dev-app");
119
+
120
+ var _msgToBotonic = require("./msg-to-botonic");
121
+
122
+ var _nodeApp = require("./node-app");
123
+
124
+ var _environment = require("./util/environment");
125
+
126
+ var _index = require("./webchat/index.js");
127
+
128
+ var _webchatApp = require("./webchat-app");
129
+
130
+ var _webview = require("./webview");
131
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA","sourcesContent":["export { BotonicInputTester, BotonicOutputTester } from './botonic-tester'\nexport * from './components'\nexport { RequestContext, WebchatContext } from './contexts'\nexport { DevApp } from './dev-app'\nexport { msgsToBotonic, msgToBotonic } from './msg-to-botonic'\nexport { NodeApp } from './node-app'\nexport { staticAsset } from './util/environment'\nexport { getBotonicApp, Webchat } from './webchat/index.js'\nexport { WebchatApp } from './webchat-app'\nexport { WebviewApp } from './webview'\n"],"file":"index.js"}
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.readDataURL = exports.isVideo = exports.isText = exports.isPostback = exports.isOfType = exports.isMedia = exports.isLocation = exports.isImage = exports.isDocument = exports.isCustom = exports.isContact = exports.isCarousel = exports.isButtonMessage = exports.isAudio = exports.isAllowedSize = exports.getMediaType = exports.getFullMimeWhitelist = exports.INPUT_MEDIA_TYPES = void 0;
9
+
10
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
+
12
+ var _core = require("@botonic/core");
13
+
14
+ var _constants = require("./constants");
15
+
16
+ var isOfType = function isOfType(msgType, type) {
17
+ return msgType === type;
18
+ };
19
+
20
+ exports.isOfType = isOfType;
21
+
22
+ var isText = function isText(msg) {
23
+ return isOfType(msg.type, _core.INPUT.TEXT);
24
+ };
25
+
26
+ exports.isText = isText;
27
+
28
+ var isPostback = function isPostback(msg) {
29
+ return isOfType(msg.type, _core.INPUT.POSTBACK);
30
+ };
31
+
32
+ exports.isPostback = isPostback;
33
+
34
+ var isAudio = function isAudio(msg) {
35
+ return isOfType(msg.type, _core.INPUT.AUDIO);
36
+ };
37
+
38
+ exports.isAudio = isAudio;
39
+
40
+ var isImage = function isImage(msg) {
41
+ return isOfType(msg.type, _core.INPUT.IMAGE);
42
+ };
43
+
44
+ exports.isImage = isImage;
45
+
46
+ var isVideo = function isVideo(msg) {
47
+ return isOfType(msg.type, _core.INPUT.VIDEO);
48
+ };
49
+
50
+ exports.isVideo = isVideo;
51
+
52
+ var isDocument = function isDocument(msg) {
53
+ return isOfType(msg.type, _core.INPUT.DOCUMENT);
54
+ };
55
+
56
+ exports.isDocument = isDocument;
57
+
58
+ var isLocation = function isLocation(msg) {
59
+ return isOfType(msg.type, _core.INPUT.LOCATION);
60
+ };
61
+
62
+ exports.isLocation = isLocation;
63
+
64
+ var isContact = function isContact(msg) {
65
+ return isOfType(msg.type, _core.INPUT.CONTACT);
66
+ };
67
+
68
+ exports.isContact = isContact;
69
+
70
+ var isCarousel = function isCarousel(msg) {
71
+ return isOfType(msg.type, _core.INPUT.CAROUSEL);
72
+ };
73
+
74
+ exports.isCarousel = isCarousel;
75
+
76
+ var isCustom = function isCustom(msg) {
77
+ return isOfType(msg.type, _core.INPUT.CUSTOM);
78
+ };
79
+
80
+ exports.isCustom = isCustom;
81
+
82
+ var isButtonMessage = function isButtonMessage(msg) {
83
+ return isOfType(msg.type, _core.INPUT.BUTTON_MESSAGE);
84
+ };
85
+
86
+ exports.isButtonMessage = isButtonMessage;
87
+ var INPUT_MEDIA_TYPES = [_core.INPUT.AUDIO, _core.INPUT.IMAGE, _core.INPUT.VIDEO, _core.INPUT.DOCUMENT];
88
+ exports.INPUT_MEDIA_TYPES = INPUT_MEDIA_TYPES;
89
+
90
+ var isMedia = function isMedia(message) {
91
+ return INPUT_MEDIA_TYPES.some(function (type) {
92
+ return isOfType(message.type, type);
93
+ });
94
+ }; // TODO: Centralize handling attachments in class
95
+
96
+
97
+ exports.isMedia = isMedia;
98
+
99
+ var readDataURL = function readDataURL(file) {
100
+ return new Promise(function (resolve, reject) {
101
+ var reader = new FileReader();
102
+ reader.readAsDataURL(file);
103
+
104
+ reader.onload = function () {
105
+ return resolve(reader.result);
106
+ };
107
+
108
+ reader.onerror = function (error) {
109
+ return reject(error);
110
+ };
111
+ });
112
+ };
113
+
114
+ exports.readDataURL = readDataURL;
115
+
116
+ var isAllowedSize = function isAllowedSize(fileSize) {
117
+ var maxAllowedBytesSize = _constants.MAX_ALLOWED_SIZE_MB * 1024 * 1024;
118
+ if (fileSize > maxAllowedBytesSize) return false;
119
+ return true;
120
+ };
121
+
122
+ exports.isAllowedSize = isAllowedSize;
123
+
124
+ var getMediaType = function getMediaType(fileType) {
125
+ return Object.entries(_constants.MIME_WHITELIST).filter(function (_ref) {
126
+ var _ref2 = (0, _slicedToArray2["default"])(_ref, 2),
127
+ _ = _ref2[0],
128
+ formatsForType = _ref2[1];
129
+
130
+ return formatsForType.includes(fileType);
131
+ }).map(function (_ref3) {
132
+ var _ref4 = (0, _slicedToArray2["default"])(_ref3, 2),
133
+ type = _ref4[0],
134
+ _ = _ref4[1];
135
+
136
+ return type;
137
+ })[0];
138
+ };
139
+
140
+ exports.getMediaType = getMediaType;
141
+
142
+ var getFullMimeWhitelist = function getFullMimeWhitelist() {
143
+ return Object.values(_constants.MIME_WHITELIST).map(function (acceptedFormatsForType) {
144
+ return acceptedFormatsForType.join(',');
145
+ });
146
+ };
147
+
148
+ exports.getFullMimeWhitelist = getFullMimeWhitelist;
149
+ //# sourceMappingURL=message-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/message-utils.js"],"names":["isOfType","msgType","type","isText","msg","INPUT","TEXT","isPostback","POSTBACK","isAudio","AUDIO","isImage","IMAGE","isVideo","VIDEO","isDocument","DOCUMENT","isLocation","LOCATION","isContact","CONTACT","isCarousel","CAROUSEL","isCustom","CUSTOM","isButtonMessage","BUTTON_MESSAGE","INPUT_MEDIA_TYPES","isMedia","message","some","readDataURL","file","Promise","resolve","reject","reader","FileReader","readAsDataURL","onload","result","onerror","error","isAllowedSize","fileSize","maxAllowedBytesSize","MAX_ALLOWED_SIZE_MB","getMediaType","fileType","Object","entries","MIME_WHITELIST","filter","_","formatsForType","includes","map","getFullMimeWhitelist","values","acceptedFormatsForType","join"],"mappings":";;;;;;;;;;;AAAA;;AAEA;;AAEO,IAAMA,QAAQ,GAAG,SAAXA,QAAW,CAACC,OAAD,EAAUC,IAAV;AAAA,SAAmBD,OAAO,KAAKC,IAA/B;AAAA,CAAjB;;;;AAEA,IAAMC,MAAM,GAAG,SAATA,MAAS,CAAAC,GAAG;AAAA,SAAIJ,QAAQ,CAACI,GAAG,CAACF,IAAL,EAAWG,YAAMC,IAAjB,CAAZ;AAAA,CAAlB;;;;AACA,IAAMC,UAAU,GAAG,SAAbA,UAAa,CAAAH,GAAG;AAAA,SAAIJ,QAAQ,CAACI,GAAG,CAACF,IAAL,EAAWG,YAAMG,QAAjB,CAAZ;AAAA,CAAtB;;;;AACA,IAAMC,OAAO,GAAG,SAAVA,OAAU,CAAAL,GAAG;AAAA,SAAIJ,QAAQ,CAACI,GAAG,CAACF,IAAL,EAAWG,YAAMK,KAAjB,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AQmD,CAAR;;AAAA,WAAenD,IAAf;AAAA,GAFA,EAEqB,CAFrB,CAAP;AAGD,CAJM;;;;AAMA,IAAMuD,oBAAoB,GAAG,SAAvBA,oBAAuB;AAAA,SAClCR,MAAM,CAACS,MAAP,CAAcP,yBAAd,EAA8BK,GAA9B,CAAkC,UAAAG,sBAAsB;AAAA,WACtDA,sBAAsB,CAACC,IAAvB,CAA4B,GAA5B,CADsD;AAAA,GAAxD,CADkC;AAAA,CAA7B","sourcesContent":["import { INPUT } from '@botonic/core'\n\nimport { MAX_ALLOWED_SIZE_MB, MIME_WHITELIST } from './constants'\n\nexport const isOfType = (msgType, type) => msgType === type\n\nexport const isText = msg => isOfType(msg.type, INPUT.TEXT)\nexport const isPostback = msg => isOfType(msg.type, INPUT.POSTBACK)\nexport const isAudio = msg => isOfType(msg.type, INPUT.AUDIO)\nexport const isImage = msg => isOfType(msg.type, INPUT.IMAGE)\nexport const isVideo = msg => isOfType(msg.type, INPUT.VIDEO)\nexport const isDocument = msg => isOfType(msg.type, INPUT.DOCUMENT)\nexport const isLocation = msg => isOfType(msg.type, INPUT.LOCATION)\nexport const isContact = msg => isOfType(msg.type, INPUT.CONTACT)\nexport const isCarousel = msg => isOfType(msg.type, INPUT.CAROUSEL)\nexport const isCustom = msg => isOfType(msg.type, INPUT.CUSTOM)\nexport const isButtonMessage = msg => isOfType(msg.type, INPUT.BUTTON_MESSAGE)\n\nexport const INPUT_MEDIA_TYPES = [\n INPUT.AUDIO,\n INPUT.IMAGE,\n INPUT.VIDEO,\n INPUT.DOCUMENT,\n]\n\nexport const isMedia = message =>\n INPUT_MEDIA_TYPES.some(type => isOfType(message.type, type))\n\n// TODO: Centralize handling attachments in class\n\nexport const readDataURL = file =>\n new Promise((resolve, reject) => {\n const reader = new FileReader()\n reader.readAsDataURL(file)\n reader.onload = () => resolve(reader.result)\n reader.onerror = error => reject(error)\n })\n\nexport const isAllowedSize = fileSize => {\n const maxAllowedBytesSize = MAX_ALLOWED_SIZE_MB * 1024 * 1024\n if (fileSize > maxAllowedBytesSize) return false\n return true\n}\n\nexport const getMediaType = fileType => {\n return Object.entries(MIME_WHITELIST)\n .filter(([_, formatsForType]) => formatsForType.includes(fileType))\n .map(([type, _]) => type)[0]\n}\n\nexport const getFullMimeWhitelist = () =>\n Object.values(MIME_WHITELIST).map(acceptedFormatsForType =>\n acceptedFormatsForType.join(',')\n )\n"],"file":"message-utils.js"}