Utils
The sdk.utils object provides a wide range of utility functions that help you build dynamic, user-friendly, and responsive views inside MonoChat. These include formatting, file uploading, timers, role checks, notifications, and more.
Categories
Formatting
formatDate(date)– Returns a formatted date string.formatDateTime(date)– Returns a full date-time string.formatDateTimeLocal(date)– Returns locale-aware date-time string.currency.priceString(isoCode, price, options)– Formats a price with currency.
HTML/Serialization
slugify(string)– Converts a string into a URL-safe slug.serialize(obj)– Serializes an object into a string.deserialize(string)– Converts a serialized string back into an object.
Loading State
loading.show()– Blocks the view with a loading spinner.loading.remove()– Removes the loading overlay.
Uploads
uploadAsync(dropzone)– Uploads files from a dropzone and returns their URLs.uploadFileAsync(file)– Uploads a single file.getSignedFileUrl(url)– Returns a promise of the URL to show a stored file from: signed for 60 minutes when it is on a private bucket (MonoChat's own storage or omni-message's media), unchanged otherwise. Use it for every stored media URL a view shows.
QR Codes
generateQrCodeAsync({ data })– Returns a QR code image in base64 for given input.
Drawer
drawer.show({...})– Opens a drawer with specified custom function.drawer.hide()– Hides the currently opened drawer.drawer.close()– Closes the drawer fully.
Chat composer
sdk.chat.composer.put(message, { includeMedia, mode }) puts a draft into the reply box of the session open in the inbox (sdk.env.session), for the agent to check and send. Nothing is sent. It returns true when the draft was handed over.
message– a{ type, payload }message, the shape a chat bubble takes, or a plain string for text.includeMedia(defaulttrue) – for animage,videoordocument, opens the file in the inbox's media preview drawer with its caption, where the channel's rules for the file apply. Withfalse, only the caption goes into the reply box.mode(default'replace') –'replace'replaces what the agent has typed,'append'adds the text after it.
Types the reply box cannot hold (button, list, location, products…) are refused with a toast; send those with business.tenants.chat.sessions.messages.create. The call also shows a toast and does nothing when its session is not the one open in the inbox.
await sdk.chat.composer.put({ type: 'image', payload: { image: { fileUrl, caption: 'Our new menu' } } }, { includeMedia: false, mode: 'append' })
Notifications
notify.success(message)– Shows a success toast.notify.failure(message)– Shows a failure/error toast.
Confirmation Dialog
confirmation({ title, text }, onConfirm, onCancel)– Opens a confirm dialog.
Refresh Tokens
setRefreshToken(key)– Triggers a refresh for a key.listenRefreshToken(key)– Listens reactively for changes to a refresh key.