@wildix/xbees-connect
v1.2.31
Published
This library provides easy communication between x-bees and integrated web applications
Downloads
1,515
Maintainers
Keywords
Readme
x-bees-connect client
This package is the Community plan edition of the client for UI integration applications.
Installation
Install the package in your project directory with:
yarn add @wildix/xbees-connect
npm install @wildix/xbees-connect
Usage
import Client from "@wildix/xbees-connect";
const xBeesClient = Client.getInstance();
console.log(xBeesClient.version());
API
Initialization
ready()
Sends the signal to x-bees that iFrame is ready to be shown. iFrame should send it when the application starts and is ready.
isAuthorized: (payload: string) => Promise<ResponseFromChannel>
Sends the message to x-bees that the user is authorized and no more actions are required.
isNotAuthorized: (payload: string) => Promise<ResponseFromChannel>
Sends the message to x-bees that user actions are required:
Contacts search
onSuggestContacts: ((query: string, resolve: Resolve, reject: Reject) => void) => RemoveEventListener
Starts listen for the events of searching contacts and handle autosuggestion with the provided callback */
Client.getInstance().onSuggestContacts(async (query, resolve) => {
try {
const contacts = await fetchContacts(query);
resolve(contacts);
} catch (error) {
console.log('catch', error);
}
});
onLookupAndMatchContact: ((query: ContactQuery, resolve: Resolve, reject: Reject) => void) => RemoveEventListener
Starts listen for the events of searching contact info and handle match with the provided callback
Client.getInstance().onLookupAndMatchContact(async (query, resolve) => {
try {
const contact = await fetchContactAndMatch(query);
resolve(contact);
} catch (error) {
console.log('catch', error);
}
});
Context
getContext(): Promise<Response>
Retrieves current x-bees context data. The data may be different depending on context.
getCurrentContact(): Promise<Response>
Retrieves contact data currently opened in x-bees.
getCurrentConversation(): Promise<Response>
Retrieves conversation data ({id, type}) currently opened in x-bees. If the conversation is temporary - retrieves undefined
getThemeMode(): Promise<Response>
Retrieves current theme mode (light or dark)
getTheme(): Promise<Response>
Retrieves current theme mode and theme options
onThemeChange: (callback: ThemeChangeListenerCallback) => void;
Starts to listen for the events of changing theme and returns the provided callback
onPbxTokenChange: (callback: ListenerCallback) => void;
Starts to listen for the events of changing PBX token and returns the provided callback
onCallStarted: (callback: ListenerCallback) => void;
Starts to listen for the events of starting the call and returns the provided callback
onCallEnded: (callback: ListenerCallback) => void;
Starts to listen for the events of ending the call and returns the provided callback
off: (callback: ListenerCallback) => void;
Removes particular callback from handling events
Other
version(): string
Retrieves the version of xBeesConnect
startCall(phoneNumber: string)
Sends a request to x-bees to start a call with a number
reboot()
Sends a request to x-bees to restart the iFrame, reload with actual parameters and token
setViewport({height: number; width: number})
Sends a request to x-bees about changes of the current frame size
toClipboard(payload: string)
Sends a request to x-bees to put a string to the user's clipboard
addEventListener()
Starts listening for one of the x-bees events and returns the provided callback
removeEventListener()
Stops listening for one of the x-bees events with the particular callback
onLogout()
Starts listen on logout event and send event to the xbees about logout able
sendAnalytics()
Sends analytics data to xbees for track into analytics data
Known issues
The below function can fix cases when String.replaceAll()
does not work in the mobile version. Most likely, this is some kind of WebView bug.
function replaceAll(str: string, search: string, replace: string) {
return str.split(search).join(replace);
}