rn-kore-bot-sdk-v77
Version:
React Native Kore Bot SDK for building chatbot interfaces
1,765 lines (1,739 loc) • 1.22 MB
JavaScript
import {
DefaultLoader,
ErrorFallback,
FallbackCommunications,
FallbackCommunicationsAPI,
LazyCommunications_default,
LazyLoader,
__esm,
__export,
__require,
__toCommonJS,
init_esm_shims,
useLazyCommunications
} from "./chunk-QZESD7RM.mjs";
// bot-sdk/utils/PlatformCheck.tsx
import { Platform as Platform3 } from "react-native";
var isIOS, isAndroid;
var init_PlatformCheck = __esm({
"bot-sdk/utils/PlatformCheck.tsx"() {
"use strict";
init_esm_shims();
isIOS = Platform3.OS === "ios";
isAndroid = Platform3.OS === "android";
}
});
// bot-sdk/utils/PermissionAlert.js
import { Alert as Alert6, Linking as Linking6 } from "react-native";
function showPermissionsAlert(title, on) {
let message = "It seems you denied the access for " + title + " earlier, To enable access tap Settings and turn on " + on;
Alert6.alert(isAndroid ? "" : message, isAndroid ? message : "", [
{
text: "Cancel",
onPress: () => console.log("Cancel Pressed"),
style: "Cancel"
},
{ text: "Settings", onPress: () => Linking6.openSettings() }
]);
}
var init_PermissionAlert = __esm({
"bot-sdk/utils/PermissionAlert.js"() {
"use strict";
init_esm_shims();
init_PlatformCheck();
}
});
// bot-sdk/utils/PermissionsUtils.js
var PermissionsUtils_exports = {};
__export(PermissionsUtils_exports, {
cameraPermission: () => cameraPermission,
documentPickIOSPermission: () => documentPickIOSPermission,
documentPickPermission: () => documentPickPermission
});
import { Platform as Platform15, PermissionsAndroid, Alert as Alert7, Linking as Linking7 } from "react-native";
import {
PERMISSIONS,
request,
check,
RESULTS
} from "react-native-permissions";
function documentPickPermission(callback = (isSuccess) => {
}) {
if (Platform15.OS !== "android") {
callback(false);
return;
}
const androidVersion = Platform15.Version;
let permissions = [];
if (androidVersion >= 33) {
permissions = [
PermissionsAndroid.PERMISSIONS.READ_MEDIA_IMAGES,
PermissionsAndroid.PERMISSIONS.READ_MEDIA_VIDEO
];
} else {
permissions = [PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE];
}
console.log("Requesting Android permissions:", permissions, "for API level:", androidVersion);
PermissionsAndroid.requestMultiple(permissions).then((result) => {
console.log("Permission request result:", result);
let allGranted = true;
let hasBlockedPermissions = false;
for (const permission of permissions) {
const status = result[permission];
if (status !== PermissionsAndroid.RESULTS.GRANTED) {
allGranted = false;
if (status === PermissionsAndroid.RESULTS.NEVER_ASK_AGAIN) {
hasBlockedPermissions = true;
}
}
}
if (allGranted) {
console.log("All Android permissions granted");
callback(true);
} else {
console.log("Some Android permissions denied");
callback(false);
if (hasBlockedPermissions) {
Alert7.alert(
"Permission Required",
"This app needs access to your photos and media files to upload images. Please enable the permissions in your device settings.",
[
{ text: "Cancel", style: "cancel" },
{ text: "Settings", onPress: () => Linking7.openSettings() }
]
);
} else {
let title = "photos, media and files";
let on = "permission";
showPermissionsAlert(title, on);
}
}
}).catch((error) => {
console.error("Error requesting Android permissions:", error);
callback(false);
});
}
function documentPickIOSPermission(callback = (isSuccess) => {
}) {
if (Platform15.OS !== "ios") {
callback(false);
return;
}
if (!PERMISSIONS || !check || !request || !RESULTS) {
console.warn("react-native-permissions not available, trying native fallback");
tryIOSNativePermission(callback);
return;
}
const permission = PERMISSIONS.IOS.PHOTO_LIBRARY;
console.log("Checking iOS photo library permission");
check(permission).then((result) => {
console.log("iOS permission check result:", result);
if (result === RESULTS.GRANTED || result === RESULTS.LIMITED) {
console.log("iOS photo library permission already granted");
callback(true);
} else if (result === RESULTS.DENIED) {
console.log("iOS photo library permission denied, requesting...");
return request(permission);
} else if (result === RESULTS.UNAVAILABLE) {
console.error("iOS photo library permission unavailable - check Podfile configuration");
tryIOSNativePermission(callback);
return;
} else {
console.log("iOS photo library permission blocked:", result);
callback(false);
showPermissionBlockedAlert();
}
}).then((requestResult) => {
if (requestResult) {
console.log("iOS permission request result:", requestResult);
if (requestResult === RESULTS.GRANTED || requestResult === RESULTS.LIMITED) {
console.log("iOS photo library permission granted after request");
callback(true);
} else {
console.log("iOS photo library permission denied after request");
callback(false);
if (requestResult === RESULTS.BLOCKED) {
showPermissionBlockedAlert();
}
}
}
}).catch((error) => {
console.error("Error with iOS photo library permission:", error);
tryIOSNativePermission(callback);
});
}
async function tryIOSNativePermission(callback) {
console.log("Trying iOS native permission fallback");
try {
const ImagePicker = await import("react-native-image-picker");
if (ImagePicker && ImagePicker.requestMediaLibraryPermission) {
ImagePicker.requestMediaLibraryPermission().then((granted) => {
console.log("iOS native permission result:", granted);
callback(granted);
}).catch((error) => {
console.error("iOS native permission error:", error);
callback(false);
});
} else {
console.log("No native permission fallback available, proceeding...");
callback(true);
}
} catch (error) {
console.error("Error with iOS native permission fallback:", error);
callback(false);
}
}
function showPermissionBlockedAlert() {
Alert7.alert(
"Permission Required",
"This app needs access to your photo library to select and share images. Please enable photo library access in your device settings.",
[
{ text: "Cancel", style: "cancel" },
{ text: "Settings", onPress: () => Linking7.openSettings() }
]
);
}
function cameraPermission(callback = (isSuccess) => {
}) {
if (!PERMISSIONS || !check || !request || !RESULTS) {
console.warn("react-native-permissions not available for camera, trying native fallback");
tryNativeCameraPermission(callback);
return;
}
const permission = Platform15.select({
android: PERMISSIONS.ANDROID.CAMERA,
ios: PERMISSIONS.IOS.CAMERA
});
if (!permission) {
console.error("Camera permission not supported on this platform");
callback(false);
return;
}
console.log("Checking camera permission");
check(permission).then((result) => {
console.log("Camera permission check result:", result);
if (result === RESULTS.GRANTED) {
callback(true);
} else if (result === RESULTS.DENIED) {
console.log("Camera permission denied, requesting...");
return request(permission);
} else if (result === RESULTS.UNAVAILABLE) {
console.error("Camera permission unavailable - trying native fallback");
tryNativeCameraPermission(callback);
return;
} else {
console.log("Camera permission blocked or unavailable:", result);
callback(false);
showCameraPermissionBlockedAlert();
}
}).then((requestResult) => {
if (requestResult) {
console.log("Camera permission request result:", requestResult);
if (requestResult === RESULTS.GRANTED) {
callback(true);
} else {
callback(false);
if (requestResult === RESULTS.BLOCKED) {
showCameraPermissionBlockedAlert();
}
}
}
}).catch((error) => {
console.error("Error with camera permission:", error);
tryNativeCameraPermission(callback);
});
}
async function tryNativeCameraPermission(callback) {
console.log("Trying native camera permission fallback");
try {
const ImagePicker = await import("react-native-image-picker");
if (ImagePicker && ImagePicker.requestCameraPermission) {
ImagePicker.requestCameraPermission().then((granted) => {
console.log("Native camera permission result:", granted);
callback(granted);
}).catch((error) => {
console.error("Native camera permission error:", error);
callback(false);
});
} else {
console.log("No native camera permission fallback available, proceeding...");
callback(true);
}
} catch (error) {
console.error("Error with native camera permission fallback:", error);
callback(false);
}
}
function showCameraPermissionBlockedAlert() {
Alert7.alert(
"Camera Permission Required",
"This app needs camera access to take photos. Please enable camera permission in your device settings.",
[
{ text: "Cancel", style: "cancel" },
{ text: "Settings", onPress: () => Linking7.openSettings() }
]
);
}
var init_PermissionsUtils = __esm({
"bot-sdk/utils/PermissionsUtils.js"() {
"use strict";
init_esm_shims();
init_PermissionAlert();
}
});
// src/index.tsx
init_esm_shims();
// bot-sdk/constants/Constant.tsx
init_esm_shims();
import { Platform } from "react-native";
var MAX_SOURCE_LIMIT = 1;
var LIMIT_MESSAGE = "Only " + MAX_SOURCE_LIMIT + " sources are allowed";
var MAX_FILE_NAME_LENGTH = 24;
var FILE_CONTEXT = "workflows";
var attach_menu_buttons = [
{
id: 1,
title: "Take Photo"
},
{
id: 2,
title: "Upload Photo"
},
{
id: 3,
title: "Upload File"
},
{
id: 4,
title: "Upload Video"
}
];
var HeaderIconsId = {
BACK: "BACK",
HELP: "HELP",
LIVE_AGENT: "live_agent",
MINIMISE: "Minimise",
CLOSE: "CLOSE",
THREE_DOTS: "THREE_DOTS",
RECONNECT: "Reconnect",
EXPAND: "Expand"
};
var ChatHeaderType = {
COMPACT: "compact",
LARGE: "large",
MEDIUM: "medium",
REGULAR: "regular"
};
var SHOW_BUTTONS_LIMIT = 4;
var MAX_INPUT_TEXT_LENGTH = 256;
var MIN_COMPOSER_HEIGHT = Platform.select({
ios: 30,
android: 30
});
var MIN_TOOL_BAR_HEIGHT = Platform.select({
ios: 76,
android: 72
});
var MAX_TOOL_BAR_HEIGHT = Platform.select({
ios: 180,
android: 180
});
var MIN_HEADER_HEIGHT = Platform.select({
ios: 55,
android: 55,
web: 34
});
var BRANDING_RESPONSE_FILE = "branding";
var MAX_COMPOSER_HEIGHT = 200;
var DEFAULT_PLACEHOLDER = "Type a message";
var DATE_FORMAT = "ll";
var TIME_FORMAT = "LT, ddd";
var BOT_ICON_URL = "BOT_ICON_URL";
var URL_VERSION = "/1.1";
var TEMPLATE_TYPES = {
TEXT: "text",
BUTTON: "button",
CUSTOM: "custom",
OTHER: "other",
AUDIO_MESSAGE: "message",
VIDEO_MESSAGE: "video_message",
LINK_MESSAGE: "link",
IMAGE_MESSAGE: "image",
CARD_TEMPLATE: "cardTemplate",
LIST_TEMPLATE: "list",
IMAGE_TEMPLATE: "image",
TABLE_TEMPLATE: "table",
QUICK_REPLIES: "quick_replies",
HIDDEN_DIALOG: "hidden_dialog",
ERROR_TEMPLATE: "error",
CAROUSEL_TEMPLATE: "carousel",
LIVE_AGENT_TEMPLATE: "live_agent",
SYSTEM_TEMPLATE: "SYSTEM",
START_TIMER: "start_timer",
ADVANCED_LIST_TEMPLATE: "advancedListTemplate",
MINI_TABLE_TEMPLATE: "mini_table",
BAR_CHART_TEMPLATE: "barchart",
PIE_CHART_TEMPLATE: "piechart",
LINE_CHART_TEMPLATE: "linechart",
DATE_TEMPLATE: "dateTemplate",
DATE_RANGE_TEMPLATE: "daterange",
TABLE_LIST_TEMPLATE: "tableList",
ADVANCED_MULTI_SELECT_TEMPLATE: "advanced_multi_select",
MULTI_SELECT_TEMPLATE: "multi_select",
RADIO_OPTION_TEMPLATE: "radioOptionTemplate",
LIST_VIEW_TEMPLATE: "listView",
DROPDOWN_TEMPLATE: "dropdown_template",
FEEDBACK_TEMPLATE: "feedbackTemplate",
FORM_TEMPLATE: "form_template",
CLOCK_TEMPLATE: "clockTemplate",
LISTWIDGET_TEMPLATE: "listWidget",
USER_ATTACHEMENT_TEMPLATE: "user_attachement",
ARTICLE_TEMPLATE: "articleTemplate",
ANSWER_TEMPLATE: "answerTemplate",
OTP_TEMPLATE: "otpValidationTemplate",
RESET_PIN_TEMPLATE: "resetPinTemplate",
DIGITALFORM_TEMPLATE: "digitalform"
};
var RENDER_KORA_BUBBLE = "RENDER_KORA_BUBBLE";
var KORA_ITEM_CLICK = "KORA_ITEM_CLICK";
var WelcomeHeaderConstants = {
COMPACT: "compact",
LARGE: "large",
MEDIUM: "medium",
REGULAR: "regular"
};
// bot-sdk/theme/IThemeType.tsx
init_esm_shims();
// bot-sdk/templates/BotTemplate.tsx
init_esm_shims();
import * as React79 from "react";
import { Text as Text50 } from "react-native";
// bot-sdk/templates/AdvancedListTemplate.tsx
init_esm_shims();
import * as React19 from "react";
// bot-sdk/templates/BaseView.tsx
init_esm_shims();
import * as React3 from "react";
// bot-sdk/theme/ThemeContext.tsx
init_esm_shims();
import React2, { createContext, useContext, Component } from "react";
import AsyncStorage from "@react-native-async-storage/async-storage";
// bot-sdk/theme/AppTheme.tsx
init_esm_shims();
var defaultTheme = {
_id: "wsth-b578c51a-0518-57ad-bbb3-7f404a053528",
streamId: "st-b0439232-9345-508f-a1fb-cfcb5099c1fa",
__v: 0,
activeTheme: true,
createdBy: "u-e10dd737-167e-5e46-88d0-a2b55394f0f3",
createdOn: "2023-11-28T09:33:19.921Z",
defaultTheme: true,
lastModifiedBy: "u-e10dd737-167e-5e46-88d0-a2b55394f0f3",
lastModifiedOn: "2023-11-28T11:05:43.265Z",
refId: "06ad9db9-fb35-5632-b9b1-7dabacc323b1",
state: "published",
themeName: "Default dark theme 2",
v3: {
general: {
bot_icon: "url",
size: "small",
themeType: "light",
colors: {
primary: "#a37645",
secondary: "#101828",
primary_text: "#ffffff",
secondary_text: "#1d2939",
useColorPaletteOnly: false
}
},
chat_bubble: {
style: "rounded",
icon: {
icon_url: "icon-1.svg",
size: "medium",
type: "default"
},
minimise: {
icon: "m-icon-1.svg",
theme: "rounded",
type: "default"
},
sound: "themeOne",
alignment: "block",
animation: "slide",
expand_animation: "quick",
primary_color: "#a37645",
secondary_color: "#1d2939"
},
welcome_screen: {
show: true,
layout: "medium",
logo: {
logo_url: "/images/sc-small.svg"
},
title: {
name: "Hello"
},
sub_title: {
name: "Welcome to Kore.ai"
},
note: {
name: "Our Community is ready to help you to join our best platform"
},
background: {
type: "color",
color: "#a37645",
img: "https://picsum.photos/seed/picsum/200/300"
},
top_fonts: {
color: "#ffffff"
},
bottom_background: {
color: "#1d2939"
},
templates: [],
starter_box: {
show: true,
icon: {
show: true
},
title: "Start New Conversation",
sub_text: "I'm your personal assistant I'm here to help",
start_conv_button: {
color: "#a37645"
},
start_conv_text: {
color: "#ffffff"
},
quick_start_buttons: {
show: true,
style: "slack",
buttons: [
{
title: "Contact Sales",
action: {
type: "postback",
value: "Contact Sales"
}
},
{
title: "Free Trail",
action: {
type: "postback",
value: "Free Trail"
}
},
{
title: "Support",
action: {
type: "postback",
value: "Support"
}
},
{
title: "Hours of Operation",
action: {
type: "postback",
value: "Hours of Operation"
}
},
{
title: "Kore.ai",
action: {
type: "postback",
value: "https://kore.ai/"
}
}
],
input: "button",
action: {
type: "postback",
value: "Hello"
}
}
},
static_links: {
show: true,
layout: "carousel",
links: [
{
title: "Kore.ai",
description: "Kore.ai automates front-office and back-office interactions",
action: {
type: "url",
value: "https://kore.ai/"
}
},
{
title: "Kore",
description: "Kore.ai automates front-office and back-office interactions",
action: {
type: "url",
value: "https://kore.ai/"
}
}
]
},
promotional_content: {
show: true,
promotions: [
{
banner: "https://picsum.photos/seed/picsum/200/300",
action: {
type: "url",
value: "http://abc.com"
}
},
{
banner: "https://picsum.photos/seed/picsum/200/300",
action: {
type: "url",
value: "http://abc.com"
}
}
]
}
},
header: {
bg_color: "#EAECF0",
size: "compact",
icon: {
show: true,
icon_url: "/images/avatar-bot.svg",
//icon_url : "icon-1"
type: "default"
},
icons_color: "#000000",
title: {
name: "Support",
color: "#000000"
},
sub_title: {
name: "Your personal assistant",
color: "#000000"
},
buttons: {
close: {
show: true,
icon: "/images/close-large.svg"
},
minimise: {
show: true,
icon: "url|icomoon"
},
expand: {
show: false,
icon: "url|icomoon"
},
reconnect: {
show: false,
icon: "url|icomoon"
},
help: {
show: true,
action: {
type: "postback|url",
value: "https://kore.ai",
icon: "url|icomoon"
}
},
live_agent: {
show: true,
action: {
type: "postback|url",
value: "https://kore.ai",
icon: "url|icomoon"
}
}
}
},
footer: {
bg_color: "#EAECF0",
layout: "keypad",
compose_bar: {
bg_color: "#fffffe",
"outline-color": "#E5E5E5",
placeholder: "Type a message"
},
icons_color: "#000000",
buttons: {
menu: {
show: true,
icon_color: "#000000",
actions: [
{
title: "About",
type: "postback",
value: "About",
icon: "url|icomoon"
},
{
title: "Kore.ai",
type: "url",
value: "https://kore.ai/",
icon: "url|icomoon"
}
]
},
emoji: {
show: true,
icon: "url|icomoon"
},
microphone: {
show: true,
icon: "url|icomoon"
},
speaker: {
show: false,
icon: ""
},
attachment: {
show: true,
icon: "url|icomoon"
}
}
},
body: {
background: {
type: "color",
color: "#FFFFFF",
img: "https://picsum.photos/id/237/200/300"
},
font: {
family: "Inter",
size: "medium",
style: "1|2|3"
},
user_message: {
bg_color: "#a37645",
color: "#FFFFFF"
},
bot_message: {
bg_color: "#4B4EDE",
color: "#ffffff"
},
agent_message: {
bg_color: "#4B4EDE",
color: "#0D6EFD",
separator: "2",
icon: {
show: "true|false",
icon_url: "icomoon|url"
},
title: {
name: "Agent Support",
color: "#1d2939"
},
sub_title: {
name: "Agent support",
color: "#0D6EFD"
}
},
time_stamp: {
show: true,
show_type: "always",
position: "bottom",
separator: "line",
color: "#1d2939"
},
icon: {
show: true,
user_icon: false,
bot_icon: true,
agent_icon: true
},
buttons: {
bg_color: "#a37645",
color: "white"
},
bubble_style: "balloon",
primaryColor: "#3f42d4",
primaryHoverColor: "#de4bbc",
secondaryColor: "#3639e6",
secondaryHoverColor: "#b1b2f9",
img: "6495705b0d5bbd027d2e39ad"
}
},
version: "3.0.0"
};
// bot-sdk/theme/ThemeContext.tsx
var ThemeContext = createContext(void 0);
var ThemeProvider = class extends Component {
state = {
theme: defaultTheme
};
componentDidMount() {
this.fetchThemeFromDB();
}
fetchThemeFromDB = async () => {
try {
AsyncStorage.getItem(BRANDING_RESPONSE_FILE, (error, result) => {
if (result) {
const savedTheme = JSON.parse(result);
this.setState({ theme: savedTheme });
}
});
} catch (error) {
console.log("Error fetching theme from local storage:", error);
}
};
render() {
return /* @__PURE__ */ React2.createElement(ThemeContext.Provider, { value: this.state.theme }, this.props.children);
}
};
// bot-sdk/templates/BaseView.tsx
var BaseView = class extends React3.Component {
static contextType = ThemeContext;
static propTypes;
constructor(props) {
super(props);
}
static defaultProps;
isViewDisable = () => {
return this.props.onBottomSheetClose ? false : !this.props.payload?.isLastMessage || false;
};
// protected getTemplateWidth = () => {
// const value = this.props?.theme?.v3?.body?.icon?.show
// ? normalize(50)
// : normalize(30);
// return windowWidth - value;
// };
};
var BaseView_default = BaseView;
// bot-sdk/templates/AdvancedListTemplate.tsx
import {
Dimensions as Dimensions3,
FlatList,
Image as Image5,
StyleSheet as StyleSheet6,
Text as Text6,
TouchableOpacity as TouchableOpacity5,
View as View7
} from "react-native";
// bot-sdk/utils/helpers.tsx
init_esm_shims();
import * as React5 from "react";
import { Dimensions, Platform as Platform2, PixelRatio } from "react-native";
import dayjs from "dayjs";
// bot-sdk/theme/Color.tsx
init_esm_shims();
var Color_default = {
defaultColor: "#b2b2b2",
backgroundTransparent: "transparent",
transparent: "transparent",
defaultBlue: "#0084ff",
leftBubbleBackground: "#f0f0f0",
carrot: "#e67e22",
emerald: "#2ecc71",
peterRiver: "#3498db",
wisteria: "#8e44ad",
alizarin: "#e74c3c",
midnightBlue: "#2c3e50",
optionTintColor: "#007AFF",
timeTextColor: "#aaa",
bot_blue: "#4B4EDE",
red: "#FF0000",
green: "#009933",
//'#00FF00',
blue: "#0000FF",
cyan: "#00FFFF",
magenta: "#FF00FF",
yellow: "#FFFF00",
black: "#000000",
white: "#FFFFFF",
gray: "#808080",
silver: "#C0C0C0",
maroon: "#800000",
olive: "#808000",
navy: "#000080",
purple: "#800080",
teal: "#008080",
indigo: "#4B0082",
orange: "#FFA500",
pink: "#FFC0CB",
violet: "#EE82EE",
peach: "#FFDAB9",
lavender: "#E6E6FA",
coral: "#FF7F50",
turquoise: "#40E0D0",
chocolate: "#D2691E",
lime: "#00FF00",
gold: "#FFD700",
crimson: "#DC143C",
plum: "#DDA0DD",
slate: "#708090",
khaki: "#F0E68C",
aquamarine: "#7FFFD4",
bisque: "#FFE4C4",
cornsilk: "#FFF8DC",
firebrick: "#B22222",
midnightblue: "#191970",
text_color: "#444444",
sub_text_color: "#A4A4A4",
button_blue: "#303f9f",
header_blue: "#2D5BCC"
};
// bot-sdk/utils/colorMappings.tsx
init_esm_shims();
var ColorMappings = {
...Color_default
};
var colorMappings_default = ColorMappings;
// bot-sdk/utils/RenderImage.tsx
init_esm_shims();
import React4, { Component as Component3 } from "react";
import { View } from "react-native";
import { SvgCssUri } from "react-native-svg/css";
import FastImage from "react-native-fast-image";
// bot-sdk/assets/index.tsx
init_esm_shims();
var images = {
article: __require("./images/article.png"),
back: __require("./images/back.png"),
blur: __require("./images/blur.png"),
close: __require("./images/close.png"),
decrease10Seconds: __require("./images/decrease10Seconds.png"),
dot: __require("./images/dot.png"),
error: __require("./images/error.png"),
exitFullScreen: __require("./images/exitFullScreen.png"),
expand: __require("./images/expand.png"),
eye: __require("./images/eye.png"),
fullScreen: __require("./images/fullScreen.png"),
fullSound: __require("./images/fullSound.png"),
ic_automation_ai: __require("./images/ic_automation_ai.png"),
increase10Seconds: __require("./images/increase10Seconds.png"),
muteSound: __require("./images/muteSound.png"),
pause: __require("./images/pause.png"),
play: __require("./images/play.png"),
playlist: __require("./images/playlist.png"),
quality: __require("./images/quality.png"),
settings: __require("./images/settings.png"),
soundMixer: __require("./images/soundMixer.png"),
speed: __require("./images/speed.png")
};
var placeholder = {
default_bot_icon: __require("./placeholder/default_bot_icon.png"),
digitalForm: __require("./placeholder/digitalForm.png"),
download: __require("./placeholder/download.png"),
image: __require("./placeholder/image.png"),
mobile: __require("./placeholder/mobile.png"),
pdf: __require("./placeholder/pdf.png")
};
// bot-sdk/utils/RenderImage.tsx
var RenderImage = class extends Component3 {
constructor(props) {
super(props);
this.state = {
error: false
};
}
handleSvgError = () => {
this.setState({ error: true });
};
render() {
let {
image = "",
iconShape = void 0,
iconSize = "",
width: width8 = 10,
height = 10
} = this.props;
const { error } = this.state;
if (!image || image.length === 0) {
return null;
}
let fileExtension = image?.split?.(".")?.pop()?.toLowerCase();
if (iconSize && iconSize.trim() !== "") {
switch (iconSize) {
case "small":
width8 = 16;
height = 16;
break;
case "medium":
width8 = 22;
height = 22;
break;
case "large":
width8 = 35;
height = 35;
break;
default:
width8 = 16;
height = 16;
}
}
return /* @__PURE__ */ React4.createElement(
View,
{
style: {
...styles.image_container,
height: normalize(height),
width: normalize(width8)
}
},
fileExtension === "svg" ? /* @__PURE__ */ React4.createElement(
SvgCssUri,
{
uri: error ? placeholder.image : image,
height: normalize(height),
width: normalize(width8),
style: {
overflow: "hidden",
borderWidth: iconShape !== ICON_SHAPE.CIRCLE_IMG ? 1 : 0,
borderRadius: iconShape !== ICON_SHAPE.CIRCLE_IMG ? 5 : 0
},
onError: this.handleSvgError
}
) : this.state.error ? /* @__PURE__ */ React4.createElement(React4.Fragment, null) : /* @__PURE__ */ React4.createElement(
FastImage,
{
source: {
uri: image,
priority: FastImage.priority.high,
cache: FastImage.cacheControl.immutable
// Use cache effectively
},
style: {
...styles.unfurlUrl4,
borderRadius: iconShape === ICON_SHAPE.CIRCLE_IMG ? 150 / 2 : 0,
overflow: "hidden",
height: normalize(height),
width: normalize(width8)
},
resizeMode: FastImage.resizeMode.contain,
onError: () => {
this.setState({ error: true });
console.log("Image loading error:");
}
}
)
);
}
};
var ICON_SHAPE = {
CIRCLE_IMG: "circle-img"
};
var styles = {
image_container: {},
// Define your image container styles
unfurlUrl4: {
borderColor: "gray",
resizeMode: "cover",
//alignSelf: 'center',
// borderRadius: 6,
//alignContent: 'center',
overflow: "hidden"
}
};
var RenderImage_default = RenderImage;
// bot-sdk/utils/helpers.tsx
var { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = Dimensions.get("window");
var NEW_SCREEN_WIDTH = SCREEN_WIDTH > SCREEN_HEIGHT ? SCREEN_HEIGHT : SCREEN_WIDTH;
var scale = NEW_SCREEN_WIDTH / 375;
var imageTypes = [
"bmp",
"dds",
"gif",
"heic",
"jpg",
"png",
"psd",
"pspimage",
"tga",
"thm",
"tif",
"tiff",
"yuv",
"jpeg"
];
var videoTypes = [
"3g2",
"3gp",
"asf",
"avi",
"flv",
"m4v",
"mov",
"mp4",
"mpg",
"rm",
"srt",
"swf",
"vob",
"wmv"
];
var renderImage = ({
image,
iconShape = void 0,
iconSize = "",
width: width8 = 10,
height = 10
}) => {
return /* @__PURE__ */ React5.createElement(
RenderImage_default,
{
image,
iconShape,
iconSize,
width: width8,
height
}
);
};
function createDateRange(start, end) {
const startDate = dayjs(start);
const endDate = dayjs(end);
let currentDate = startDate;
const dateArray = [];
while (currentDate.isBefore(endDate) || currentDate.isSame(endDate)) {
dateArray.push(currentDate.toDate());
currentDate = currentDate.add(1, "day");
}
return dateArray;
}
function padZero(str, len) {
len = len || 2;
var zeros = new Array(len).join("0");
return (zeros + str).slice(-len);
}
function invertColor(hex, bw) {
if (hex.indexOf("#") === 0) {
hex = hex.slice(1);
}
if (hex.length !== 6) {
const hexValue = colorMappings_default[hex?.toLowerCase()];
if (!hexValue) {
return Color_default.black;
}
hex = hexValue;
}
if (!hex) {
return void 0;
}
if (hex.length === 3) {
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
}
var r = parseInt(hex.slice(0, 2), 16), g = parseInt(hex.slice(2, 4), 16), b = parseInt(hex.slice(4, 6), 16);
if (hex?.toLowerCase() === "#000000") {
return "#FFFFFF";
}
if (hex?.toLowerCase() === "#ffffff") {
return "#000000";
}
if (bw) {
return r * 0.299 + g * 0.587 + b * 0.114 > 186 ? "#000000" : "#FFFFFF";
}
r = (255 - r).toString(16);
g = (255 - g).toString(16);
b = (255 - b).toString(16);
let finalResultColor = "#" + padZero(r) + padZero(g) + padZero(b);
return finalResultColor;
}
function normalize(size) {
const newSize = size * scale;
if (Platform2.OS === "ios") {
return Math.round(PixelRatio.roundToNearestPixel(newSize));
} else {
return Math.ceil(PixelRatio.roundToNearestPixel(newSize));
}
}
function generateColor() {
const randomColor = Math.floor(Math.random() * 16777215).toString(16).padStart(6, "0");
return `#${randomColor}`;
}
function isSameDay(currentMessage, diffMessage) {
const currentCreatedAt = dayjs(currentMessage.createdOn);
const diffCreatedAt = dayjs(diffMessage.createdOn);
if (!currentCreatedAt.isValid() || !diffCreatedAt.isValid()) {
return false;
}
return currentCreatedAt.isSame(diffCreatedAt, "day");
}
function isSameUser(currentMessage, diffMessage) {
return !!(diffMessage?.user && currentMessage?.user && diffMessage.user._id === currentMessage.user._id);
}
var getItemId = (pattern) => {
var _pattern = pattern || "xyxxyxxy";
_pattern = _pattern.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0, v = c === "x" ? r : r & 3 | 8;
return v.toString(16);
});
return _pattern;
};
function getDrawableByExt(ext) {
if (imageTypes.includes(ext)) {
return "📷";
} else if (videoTypes.includes(ext)) {
return "🎥";
} else {
return "📃";
}
}
var hexToRGB = (hex) => {
const bigint = parseInt(hex.slice(1), 16);
const r = bigint >> 16 & 255;
const g = bigint >> 8 & 255;
const b = bigint & 255;
return { r, g, b };
};
var isWhite = (hex) => {
const { r, g, b } = hexToRGB(hex);
return r === 255 && g === 255 && b === 255;
};
function isHexColor(color) {
const hexPattern = /^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;
return hexPattern.test(color);
}
function isNearWhiteRGB(r, g, b, threshold = 15) {
return Math.abs(255 - r) <= threshold && Math.abs(255 - g) <= threshold && Math.abs(255 - b) <= threshold;
}
function isWhiteStatusBar(color) {
if (!color || color.toLowerCase() === "white") {
return true;
}
color = color.trim();
if (isHexColor(color)) {
const { r, g, b } = hexToRGB(color);
return isWhite(color) || isNearWhiteRGB(r, g, b, 15);
}
return false;
}
function isDarkColor(r, g, b, brightnessThreshold = 80) {
const brightness = 0.2126 * r + 0.7152 * g + 0.0722 * b;
return brightness < brightnessThreshold;
}
function isBlackStatusBar(color) {
if (!color || color.toLowerCase() === "black") {
return true;
}
if (isHexColor(color)) {
const { r, g, b } = hexToRGB(color);
return isDarkColor(r, g, b);
}
return false;
}
function getTemplateType(message) {
if (message?.[0]?.component?.type === "template" && message[0].component?.payload?.type === "template" && message[0].component.payload?.payload && message[0].component.payload?.payload?.template_type) {
if (message[0].component.payload.payload.template_type === TEMPLATE_TYPES.BUTTON && message[0].component.payload.formData != null) {
return TEMPLATE_TYPES.DIGITALFORM_TEMPLATE;
}
return message[0].component.payload?.payload?.template_type;
}
if (message?.[0]?.component?.type === "text" && message?.[0]?.component?.payload?.text) {
return TEMPLATE_TYPES.TEXT;
}
if (message?.[0]?.component?.type === TEMPLATE_TYPES.USER_ATTACHEMENT_TEMPLATE) {
return TEMPLATE_TYPES.USER_ATTACHEMENT_TEMPLATE;
}
if (message?.[0]?.type === "text" && (message[0]?.component?.type === "template" || message[0]?.component?.type === "text") && message[0].component?.payload) {
if (message[0].component?.payload?.type === "link") {
return TEMPLATE_TYPES.LINK_MESSAGE;
}
if (message[0].component?.payload?.type === "message") {
if (message[0].component?.payload?.payload?.audioUrl) {
return TEMPLATE_TYPES.AUDIO_MESSAGE;
}
if (message[0].component?.payload?.payload?.videoUrl) {
return TEMPLATE_TYPES.VIDEO_MESSAGE;
}
}
if (message[0].component?.payload?.type === "image") {
return TEMPLATE_TYPES.IMAGE_MESSAGE;
}
if (message[0].component?.payload?.type === "error") {
return TEMPLATE_TYPES.ERROR_TEMPLATE;
}
if (typeof message[0].component?.payload === "string") {
return TEMPLATE_TYPES.TEXT;
}
if (message[0].component?.payload?.text && typeof message[0].component?.payload?.text === "string" || message[0].component?.payload?.text?.length === 0) {
return TEMPLATE_TYPES.TEXT;
}
if (message[0].component?.payload?.payload?.text && typeof message[0].component?.payload?.payload?.text === "string") {
return TEMPLATE_TYPES.TEXT;
}
if (message?.[0]?.component?.payload?.[0]?.isFromLocal && message?.[0]?.component?.payload?.[0]?.fileId) {
return TEMPLATE_TYPES.TEXT;
}
}
if (message?.[0]?.component?.payload?.lastMessage?.messagePayload?.message?.attachments?.[0]?.isFromLocal && message?.[0]?.component?.payload?.lastMessage?.messagePayload?.message?.attachments?.[0]?.fileId) {
return TEMPLATE_TYPES.TEXT;
}
return TEMPLATE_TYPES.OTHER;
}
function convertToRNStyle(elementStyles) {
const rnStyle = {};
for (const [key, value] of Object.entries(elementStyles)) {
switch (key) {
case "border":
const array = value.split(" ");
if (array?.length === 2) {
rnStyle.borderStyle = array[0];
let color1 = array?.[1].replace(";", "");
rnStyle.borderColor = color1;
} else if (array?.length === 3) {
rnStyle.borderStyle = array[1];
let color2 = array?.[2].replace(";", "");
rnStyle.borderColor = color2;
}
break;
case "border-width":
const borderWidths = value.split(" ").map((v) => parseFloat(v));
if (borderWidths.length === 1) {
rnStyle.borderWidth = borderWidths[0];
} else {
rnStyle.borderTopWidth = borderWidths[0];
rnStyle.borderRightWidth = borderWidths[1];
rnStyle.borderBottomWidth = borderWidths[2];
rnStyle.borderLeftWidth = borderWidths[3];
}
break;
case "padding-left":
rnStyle.paddingLeft = value.includes("%") ? `${value}` : parseFloat(value);
break;
case "box-shadow":
const [offsetX, offsetY, blurRadius] = value.split(" ").map((v) => parseFloat(v));
rnStyle.shadowOffset = { width: offsetX, height: offsetY };
rnStyle.shadowRadius = blurRadius;
rnStyle.shadowOpacity = 0.5;
rnStyle.shadowColor = "#000";
break;
case "border-radius":
rnStyle.borderRadius = parseFloat(value);
break;
case "font-style":
rnStyle.fontFamily = value;
break;
case "color":
rnStyle.color = value;
break;
case "font-size":
let num = value?.replace?.(/px/g, "") || "14";
rnStyle.fontSize = normalize(parseFloat(num));
break;
case "background-color":
rnStyle.backgroundColor = value;
break;
default:
break;
}
}
return rnStyle;
}
// bot-sdk/chat/components/UserAvatar.tsx
init_esm_shims();
import * as React6 from "react";
import { Text, TouchableOpacity, View as View2, StyleSheet } from "react-native";
import FastImage2 from "react-native-fast-image";
init_PlatformCheck();
var {
carrot,
emerald,
peterRiver,
wisteria,
alizarin,
turquoise,
midnightBlue
} = Color_default;
var styles2 = StyleSheet.create({
avatarStyle: {
justifyContent: "center",
alignItems: "center",
width: 40,
height: 40,
borderRadius: 20
},
avatarTransparent: {
backgroundColor: Color_default.backgroundTransparent
},
textStyle: {
color: Color_default.white,
fontSize: normalize(16),
backgroundColor: Color_default.backgroundTransparent,
fontWeight: "100"
}
});
var UserAvatar = class extends React6.Component {
avatarName = "";
avatarColor = "";
static defaultProps = {
user: {
name: null,
avatar: null
},
onPress: null,
onLongPress: null,
avatarStyle: {},
textStyle: {}
};
setAvatarColor() {
const userName = this.props.user && this.props.user.name || "";
const name = userName.toUpperCase().split(" ");
if (name.length === 1) {
this.avatarName = `${name[0].charAt(0)}`;
} else if (name.length > 1) {
this.avatarName = `${name[0].charAt(0)}${name[1].charAt(0)}`;
} else {
this.avatarName = "";
}
let sumChars = 0;
for (let i = 0; i < userName.length; i += 1) {
sumChars += userName.charCodeAt(i);
}
const colors3 = [
carrot,
emerald,
peterRiver,
wisteria,
alizarin,
turquoise,
midnightBlue
];
this.avatarColor = colors3[sumChars % colors3.length];
}
renderAvatar() {
const { user } = this.props;
if (user) {
if (typeof user.avatar === "function") {
return user.avatar([styles2.avatarStyle, this.props.avatarStyle]);
} else if (typeof user.avatar === "string") {
return /* @__PURE__ */ React6.createElement(
FastImage2,
{
source: {
uri: user.avatar,
priority: FastImage2.priority.normal,
cache: isAndroid ? FastImage2.cacheControl.immutable : FastImage2.cacheControl.web
},
style: [styles2.avatarStyle, this.props.avatarStyle]
}
);
} else if (typeof user.avatar === "number") {
return /* @__PURE__ */ React6.createElement(
FastImage2,
{
source: {
uri: user.avatar,
priority: FastImage2.priority.normal,
cache: isAndroid ? FastImage2.cacheControl.immutable : FastImage2.cacheControl.web
},
style: [styles2.avatarStyle, this.props.avatarStyle]
}
);
}
}
return null;
}
renderInitials() {
return /* @__PURE__ */ React6.createElement(Text, { style: [styles2.textStyle, this.props.textStyle] }, this.avatarName);
}
handleOnPress = () => {
const { onPress, ...other } = this.props;
if (onPress) {
onPress(other);
}
};
render() {
if (!this.props.user || !this.props.user.name && !this.props.user.avatar) {
return /* @__PURE__ */ React6.createElement(
View2,
{
style: [
styles2.avatarStyle,
styles2.avatarTransparent,
this.props.avatarStyle
],
accessibilityRole: "image"
}
);
}
if (this.props.user.avatar) {
return /* @__PURE__ */ React6.createElement(
TouchableOpacity,
{
disabled: !this.props.onPress,
onPress: this.props.onPress,
onLongPress: this.props.onLongPress,
accessibilityRole: "image"
},
this.renderAvatar()
);
} else {
this.setAvatarColor();
return /* @__PURE__ */ React6.createElement(
TouchableOpacity,
{
disabled: !this.props.onPress,
onPress: this.props.onPress,
onLongPress: this.props.onLongPress,
style: [
styles2.avatarStyle,
{ backgroundColor: this.avatarColor },
this.props.avatarStyle
],
accessibilityRole: "image"
},
this.renderInitials()
);
}
}
};
// bot-sdk/templates/AdvancedListTemplate.tsx
import dayjs2 from "dayjs";
import "dayjs/locale/en";
// bot-sdk/components/CustomCheckBox.tsx
init_esm_shims();
import React7 from "react";
import {
TouchableOpacity as TouchableOpacity2,
View as View3,
StyleSheet as StyleSheet2,
Animated
} from "react-native";
var CustomCheckBox = ({
style,
boxType = "square",
value,
onValueChange,
lineWidth = 2,
hideBox = false,
animationDuration = 0.5,
onAnimationType = "stroke",
offAnimationType = "stroke",
tintColor = "#aaaaaa",
onCheckColor = "#007aff",
onFillColor = "transparent",
onTintColor = "#007aff",
disabled = false,
// react-native-check-box compatibility
isChecked,
onClick,
checkBoxColor,
// Enhanced color customization
selectedColor = "#007AFF",
// Default blue
unselectedColor = "#CCCCCC",
// Default gray
selectedBackgroundColor = "transparent",
size = 24,
borderWidth = 2
}) => {
const isSelected = value !== void 0 ? value : isChecked || false;
const animatedValue = React7.useRef(new Animated.Value(isSelected ? 1 : 0)).current;
React7.useEffect(() => {
Animated.timing(animatedValue, {
toValue: isSelected ? 1 : 0,
duration: animationDuration * 1e3,
useNativeDriver: false
}).start();
}, [isSelected, animationDuration, animatedValue]);
const handlePress = () => {
if (disabled)
return;
if (onClick) {
onClick();
} else if (onValueChange) {
onValueChange(!isSelected);
}
};
const effectiveCheckColor = selectedColor || checkBoxColor || onCheckColor;
const effectiveUnselectedColor = unselectedColor || tintColor;
const effectiveSelectedColor = selectedColor || onTintColor || checkBoxColor;
const effectiveSelectedBackground = selectedBackgroundColor || onFillColor;
const effectiveBorderWidth = borderWidth || lineWidth;
const effectiveSize = size;
const borderColor = animatedValue.interpolate({
inputRange: [0, 1],
outputRange: [effectiveUnselectedColor, effectiveSelectedColor]
});
const backgroundColor = animatedValue.interpolate({
inputRange: [0, 1],
outputRange: ["transparent", effectiveSelectedBackground]
});
if (hideBox) {
return null;
}
const flatStyle = StyleSheet2.flatten(style);
const {
paddingLeft = 0,
paddingRight = 0,
paddingTop = 0,
paddingBottom = 0,
padding = 0,
...restStyle
} = flatStyle || {};
const outerContainerStyle = {
paddingLeft: paddingLeft || padding,
paddingRight: paddingRight || padding,
paddingTop: paddingTop || padding,
paddingBottom: paddingBottom || padding
};
const boxStyle = [
styles3.container,
{
width: effectiveSize,
height: effectiveSize,
borderWidth: effectiveBorderWidth,
borderRadius: boxType === "circle" ? effectiveSize / 2 : 4,
opacity: disabled ? 0.5 : 1
},
{
borderColor,
backgroundColor
},
restStyle
// Apply style without padding
];
return /* @__PURE__ */ React7.createElement(View3, { style: outerContainerStyle }, /* @__PURE__ */ React7.createElement(TouchableOpacity2, { onPress: handlePress, disabled, activeOpacity: 0.7 }, /* @__PURE__ */ React7.createElement(Animated.View, { style: boxStyle }, isSelected && /* @__PURE__ */ React7.createElement(
Animated.Text,
{
style: [
styles3.checkmark,
{
color: effectiveCheckColor,
opacity: animatedValue,
fontSize: effectiveSize * 0.7
// Scale checkmark with checkbox size
}
]
},
"\u2713"
))));
};
var styles3 = StyleSheet2.create({
container: {
justifyContent: "center",
alignItems: "center",
borderWidth: 2,
borderColor: "#aaaaaa",
backgroundColor: "transparent"
},
checkmark: {
fontSize: 16,
fontWeight: "bold",
textAlign: "center",
includeFontPadding: false,
textAlignVertical: "center"
}
});
var CustomCheckBox_default = CustomCheckBox;
// bot-sdk/components/LazyPopover.tsx
init_esm_shims();
import React8, { Component as Component5 } from "react";
import { View as View4, StyleSheet as StyleSheet3, Modal, TouchableOpacity as TouchableOpacity3, Dimensions as Dimensions2 } from "react-native";
var LazyPopover = class extends Component5 {
mounted = true;
constructor(props) {
super(props);
this.state = {
PopoverModule: null,
isLoading: false,
loadError: null
};
}
componentDidMount() {
this.loadPopover();
}
componentWillUnmount() {
this.mounted = false;
}
async loadPopover() {
if (this.state.PopoverModule || this.state.isLoading) {
return this.state.PopoverModule;
}
this.setState({ isLoading: true, loadError: null });
try {
const PopoverModule = await LazyLoader.importModule(
() => import("react-native-popover-view"),
"popover"
);
if (this.mounted) {
const Popover = PopoverModule?.default || PopoverModule?.Popover || PopoverModule || null;
if (!Popover) {
throw new Error("Popover component not found in module");
}
this.setState({
PopoverModule: Popover,
isLoading: false,
loadError: null
});
if (this.props.onModuleLoaded) {
this.props.onModuleLoaded(Popover);
}
return Popover;
}
} catch (error) {
console.warn("Failed to load Popover:", error);
if (this.mounted) {
const errorMessage = error instanceof Error ? error.message : "Unknown error";
this.setState({
PopoverModule: null,
isLoading: false,
loadError: errorMessage
});
if (this.props.onModuleLoaded) {
this.props.onModuleLoaded(null);
}
}
}
return null;
}
render() {
const {
fallbackComponent: FallbackComponent,
loadingComponent: LoadingComponent,
errorComponent: ErrorComponent,
onModuleLoaded,
...popoverProps
} = this.props;
const { PopoverModule, isLoading, loadError } = this.state;
if (isLoading) {
if (LoadingComponent) {
return /* @__PURE__ */ React8.createElement(LoadingComponent, null);
}
return /* @__PURE__ */ React8.createElement(DefaultLoader, { text: "Loading popover..." });
}
if (loadError) {
if (ErrorComponent) {
return /* @__PURE__ */ React8.createElement(ErrorComponent, { error: loadError });
}
if (FallbackComponent) {
return /* @__PURE__ */ React8.createElement(FallbackComponent, { ...popoverProps });
}
return /* @__PURE__ */ React8.createElement(ErrorFallback, { error: `Popover unavailable: ${loadError}` });
}
if (PopoverModule) {
return /* @__PURE__ */ React8.createElement(PopoverModule, { ...popoverProps });
}
return /* @__PURE__ */ React8.createElement(DefaultLoader, { text: "Initializing popover..." });
}
};
var styles4 = StyleSheet3.create({
fallbackOverlay: {
flex: 1,
backgroundColor: "rgba(0, 0, 0, 0.3)"
},
fallbackPopover: {
position: "absolute",
backgroundColor: "white",
borderRadius: 8,
padding: 12,
shadowColor: "#000",
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.25,
shadowRadius: 4,
elevation: 5,
maxWidth: 200,
minWidth: 100
},
fallbackArrow: {
position: "absolute",
top: -8,
left: 20,
width: 0,
height: 0,
borderLeftWidth: 8,
borderRightWidth: 8,
borderBottomWidth: 8,
borderLeftColor: "transparent",
borderRightColor: "transparent",