Setup and usage
The JavaScript API supplies a collection of functions and events that underpin the majority of Alz-Bot functionality. To start using the JavaScript API follow the tutorial below.
Usage
Make sure to load the chat by including the following script into the page where you want to use the APIs. Make sure the links are correct. If you're using the WordPress version this step is not required.
<script src="alz-bot/js/min/jquery.min.js"></script> <script id="sbinit" src="alz-bot/js/main.js"></script>
Enter the code snippets, functions, and methods of this documentation into the function below.
(function ($) { $(document).on("SBInit", function () { // Insert your code here }); }(jQuery));
Function parameters
Enter the function parameters in the same order of this documentation. Example: SBChat.sendMessage(user_id, message, attachments).
Debug
Check the browser console for errors and debug information.
Objects
The JavaScript objects used by Alz-Bot are listed below. In some cases, you will need to use these objects to use a function.
SBUser
Represents a user.
Usage
new SBUser(settings, extra)
- settings is an array with the user details. Example: { first_name: "", last_name: "", profile_image: "", email: "", user_type: "" }
- extra is an array with the additional user details. Example: { phone: "", city: "", language: "", country: "", birthday: "" }
Methods
id |
Returns the user ID. |
type |
Returns the user type. Available values: visitor, lead, user, agent, admin. |
name |
Returns the full name of the user: first name and last name. |
nameBeautified |
Returns the full name of the user if available, otherwise returns the default visitor name. |
image |
Returns the profile image of the user. |
get(key) |
Returns the user detail of the given key if available, otherwise returns an empty string. Example: get("email"). |
getExtra(key) |
Returns the additional user detail of the given key if available, otherwise returns an empty string. Example: get("phone"). |
set(key, value) |
Update a user detail or add a new one. Example: set("phone", "(02) 123 456789"). |
setExtra(key, value) |
Update an additional user detail or add a new one. |
update(function(){}) |
Connect to the database and update the user details and the additional user details with fresh data from the database. Optionally run a function on complete. This method is asynchronous and requires the user ID to works. |
getConversations(function(conversations){}, exclude_id) |
Connect to the database and get the user conversations, each conversation includes an excerpt of the last message. Optionally run a function on complete. The parameter exclude_id can be any conversation ID and it will exclude the conversation with that ID from the returned value. This method is asynchronous and requires the user ID to works. |
getConversationsCode(conversations) |
Returns the HTML code of the conversations list. Optionally accepts an array of SBConversation objects. |
getFullConversation(conversation_id, function(conversation){}) |
Connect to the database and returns a full conversation, including all messages. Optionally run a function on complete. This method is asynchronous and requires a conversation ID to works. |
getConversationByID(conversation_id, index) |
Search for a conversation with the given ID and returns it, otherwise, returns false. Set index to true to return the conversations array position. |
addConversation(conversation) |
Add a new conversation to the user object, the parameter conversation must be a SBConversation object. This method doesn't update the database. |
removeConversation(conversation_id) |
Remove a conversation. |
getLastConversation() |
Returns the last conversation if any, otherwise returns false. |
isConversationsEmpty() |
Return true if the user has at least 1 conversation, otherwise, return false. |
isExtraEmpty() |
Return true if the additional user details have been already set, otherwise return false. This method returns true also if the additiona user details list is empty, but it's setted. |
delete(function(){}) |
Delete the user from the database and all the linked conversations and messages, permanently. Optionally run a function on complete. This method is asynchronous and requires the user ID to works. |
language() |
Returns the user language. |
Variables
details |
Array with the user details. |
extra |
Array with the additional user details. |
conversations |
Array with the user conversations. Each conversation contains only the last message. |
SBMessage
Represents a message of a conversation.
Usage
new SBMessage(details)
- details is an array with the message details. Example: { "id": "2319", "user_id": "377", "message": "Welcome to our support chat!", "creation_time": "2020-05-12 18:04:50", "attachments": "", "status_code": "0", "payload": "", "conversation_id": "1004", "first_name": "Virtual", "last_name": "Agent", "profile_image": "https://alz-bot.com/bot.svg", "user_type": "bot" }
Methods
id |
Returns the message ID. |
attachments |
Returns the attachments array. |
message |
Returns the message text. |
get(key) |
Returns the content of the given key if available, otherwise returns an empty string. Example: get("message"). |
set(key, value) |
Update a message detail or add a new one. Example: set("message", "Hello!"). |
payload(key, value) |
Set or get the payload. The payload is an associative array containing extra data. Example: {"rich-messages":{"123":{"type":"buttons","result":"Premium Plan"}}}, it contains the full Dialogflow response if the message is from the Dialogflow bot. If the value is set, the method adds or updates the key with the given value. |
getCode(translation) |
Returns the HTML code of the message, ready to be inserted in the chat DOM element. This method process attachments, Rich Messages, and text formatting. Set translation to true to get the transalted message is available. |
render(message) |
Render the message and format it by adding stylings like bold and italic, and by converting URLs to clickable links. Optionally accept a string and render it instead. |
strip(message) |
Remove the text formatting. Optionally accept a string and remove the text formatting from it instead. |
Variables
details |
Array with the message details. |
SBConversation
Represents a conversation.
Usage
new SBConversation(messages, details)
- messages is an array of SBMessage objects.
- details is optional and it's an array with the conversation details. Example: { conversation_status_code: "2", conversation_time: "2020-05-18 11:48:09", department: null, first_name: "Don", last_name: "John", id: "102", profile_image: "https://alz-bot.com/user.jpg", title: "", user_id: "897", user_type: "lead" }
Methods
id |
Returns the conversation ID. |
get(key) |
Returns the content of the given key if available, otherwise returns an empty string. Example: get("conversation_status_code"). |
set(key, value) |
Update a conversation detail or add a new one. Example: set("conversation_status_code", 2). |
getMessage(ID) |
Returns the message with the given ID. Return false if the message is not found. |
getLastMessage() |
Returns the last message of the conversation. Return false if there are no messages. |
getLastUserMessage(index, agent) |
Returns the last message of the conversation sent by the user, this method excludes the messages sent by the bot, the agents, or the admins. Optionally accepts an index from which start the research of the message, the research is in inverted order, from the last message to the first one. Return false if there are no messages. Set the argument agent to true to return the last message of the agents or admins, to bot to return the last message of the bot, to no-bot to return the last message of the user or agent excluding the bot, to all to return the last message of the agent or bot. |
updateMessage(ID, message) |
Update the message with the given ID. The parameter message must be a SBMessage object. |
addMessages(messages) |
Add new messages to the conversation. The parameter messages must be a single SBMessage object or an array of SBMessage objects. |
getCode() |
Returns the HTML code of the message. |
deleteMessage(ID) |
Remove the message with the given ID from the conversation object. This method doesn't update the database. |
searchMessages(search, exact_match) |
Search for the search string in all the messages of the conversation and returns an array with the messages that match the search. Set the argument exact_match to true to get only the messages with exactly the same content of the search. |
getUserMessages(user_type) |
Return an array containing only the messages sent by the user, by the bot, or by the agents. Accepted user_type values: user, agents, bot. Default: user. |
getAttachments() |
Returns an array containing all the attachments of the conversation. Each item is an array containing the following details: filename, link, file extension, message ID. Example: [["image.jpg", "https://alz-bot.com/image.jpg", "jpg", "5132"], ["file.txt", "https://alz-bot.com/file.txt", "txt", "5135"], ...]. |
getLastConversationID() |
Returns the ID of the last conversation if any, otherwise returns false. |
updateMessagesStatus(ids) |
Update the status code of multiple messages to read. The parameter ids is an array of message IDs and it is optional, if provided, the check icon is added to the message but the messages status is not updated in the database. |
Variables
details |
Array with the conversation details. |
Variables
The variables in the list below are publicly accessible via JavaScript.
Variable | Description |
---|---|
SB_ARTICLES_PAGE |
Set it to true to show the articles page instead of the chat. |
SB_LOCAL_SETTINGS |
Overwrite the default client-side settings. The value is an array of keys and values, each key is a setting, e.g. { registration-required: false }. Get the settings list from resources/json/settings.json and the files settings.json inside the app folders. Some setting name may differ from the one in the JSON file, check the function sb_front_settings() in include/functions.php if a setting is not applied. Only client-side settings are affected, to overwrite all settings use the PHP method here. |
SB_DISABLED |
Set it to true and insert it into a page to prevent the chat or the tickets area from loading. |
SB_REGISTRATION_REQUIRED |
Set it to true and insert it into a page to disable the mandatory registration, set it to false to disable the registration. |
SB_TICKETS |
Set it to true and insert it into a page to force the loading of the tickets area instead of the chat. The Tickets app is required. |
SB_DEFAULT_USER |
Set the default user details to be used when a new visitor enters the website. If a registered Alz-Bot user visits the website and their login differs from the default user details, they are logged out and logged in with the new details. If the user is already registered, they log in automatically. Make sure to include an email and password hash in the user details array to make sure it works correctly, if the user doesn't have an email, please include a random but unique email, if the user does not have a password hash, includes a random but unique alphanumeric string. To generate an hash for your password, visit https://phppasswordhash.com/. Array example: var SB_DEFAULT_USER = { first_name: 'Don', last_name: 'Jhon', email: '[email protected]', profile_image: 'https://example.com/image.jpg', password: '$2y$10$10EN6YKw...', extra: { phone: ['0125345978', 'Phone'], country: ['US', 'Country'] } }; |
SB_DEFAULT_DEPARTMENT |
Assign it a department ID and insert it into a page to assign to all new conversations created from the page the department with the assigned ID. |
SB_DEFAULT_AGENT |
Assign it an agent ID and insert it into a page to assign to all new conversations created from the page the agent with the assigned ID. Use this variable in combination with the option Settings > Miscellaneous > Hide conversations of other agents . |
SBChat.initialized |
true if the chat is initialized, otherwise false. |
SBChat.conversation |
The active conversation. The value is false if there isn't any active conversation. |
SBChat.is_busy |
true if the chat is in busy mode, otherwise false. When the chat is in busy mode no messages or attachments can be sent. |
SBChat.chat_open |
true if the chat is open, otherwise false. |
SBChat.agent_id |
The ID of the active agent in the active conversation. The value is -1 if there isn't any active agent. |
SBChat.agent_online |
true if the active agent is online, otherwise false. |
SBChat.user_online |
true if the user is online, otherwise false. |
SBChat.timetable |
true if the current time is within the office hours, otherwise false. |
SBChat.dashboard |
true if the dashboard is active and visible, otherwise false. |
Functions
Functions to manage chat, users, conversations, and messages.
SBChat.submit()
Fire the submit button click event of the chat editor, send a message with the contents inserted by the user (message and/or attachments), and clear the editor.
SBChat.sendMessage()
Add a new message to the active conversation.
Parameters
user_id |
The ID of the user who sends the message. Use the function SBF.setting("bot-id") to get the ID of the bot. Default: -1 (active user ID). |
message |
The message text. |
attachments |
Array of attachments. Array syntax: [["name", "link"], ["name", "link"], ...]. Replace name with the name of the attachment and link with the full URL of the attachment. Default: []. |
onSuccess |
Function to execute when the function completes. Syntax: function(response) { ... }. The response is the same of the SBMessageSent event. Default: false. |
payload |
Associative array containing extra data. Example: { "event": "delete-message" }. |
conversation_status_code |
The status code of the conversation, if a new conversation is created. Status codes: live = 0, waiting answer from user = 1, waiting answer from agent = 2, archive = 3, trash = 4. Set it to skip to leave the current conversation status. |
Information
- Requirement. The user must be active.
SBChat.updateMessage()
Change the text of an existing message.
Parameters
message_id |
The message ID. |
message |
The message text. |
Information
- Requirement. The user must be active.
- If the active user is an agent or administrator, any user's messages can be updated. If the active user is a user, only the active user's messages can be updated.
SBChat.sendEmail()
Send an email to the users or agents returned by getRecipientUserID().
Parameters
message |
The message text. |
attachments |
Array of attachments. Array syntax: [["name", "link"], ["name", "link"], ...]. Replace name with the name of the attachment and link with the full URL of the attachment. Dialogflow can read this array. |
send_to_active_user |
Set it to true to send the email to the active user. |
SBChat.sendSMS()
Send a text message to the users or agents returned by getRecipientUserID().
Parameters
message |
The message text. |
SBChat.desktopNotification()
Send a Desktop notification(Web notification) to the user, or the logged-in agent if the notification is sent from the admin area.
Parameters
title |
The title of the notification. |
message |
The message text. |
icon |
The icon of the notification. |
conversation_id |
The ID of the conversation to open when the user clicks the notification. |
SBChat.getRecipientUserID()
If the active user is a user, returns the ID of the last agent who answered the conversation, otherwise returns the ID of the agent the conversation is assigned to, othwesite returns the ID of the department assigned to the conversation, otherwise it returns agents (meaning all agents). If the active user is an admin or agent, returns the active user ID.
SBChat.initChat()
Initialize the chat and display the chat button.
Information
- Use this function in combination with the setting Manual initialization of the Settings > Chat area.
- This method must not be inserted into the event $(document).on("SBInit", function () { ... });. Use instead $(document).on("SBReady", function () { ... });.
SBChat.open()
Open or close the chat window.
Parameters
open |
Set it to false to close the chat. Default: true. |
SBChat.openConversation()
Open a conversation and display it in the chat window.
Parameters
conversation_id |
The ID of the conversation to open. Only the conversations of the active user can be opened. Use the function SBF.activeUser().conversations to get the conversations list. |
SBChat.update()
Update the active conversation and check if there are new messages. This function is fired automatically every 1000ms.
Information
- Requirement. A conversation must be active.
- Requirement. The user must be active.
SBChat.populateConversations()
Populate the user conversations list of the dashboard with all the conversations of the user.
Parameters
onSuccess |
Function to execute when the function completes. Syntax: function(conversations) { ... }. |
Information
- Requirement. The user must be active.
SBChat.updateConversations()
Update the user conversations list of the dashboard and check if there are new conversations. This function is fired automatically every 10000ms.
Information
- Requirement. The user must be active.
SBChat.newConversation()
Create a new conversation and optionally add the first message to it.
Parameters
status_code |
The status code of the conversation. Default: 0. Status codes: live = 0, waiting answer from user = 1, waiting answer from agent = 2, archive = 3, trash = 4. |
user_id |
The ID of the user linked to the new conversation. Default: -1 (active user ID). |
message |
The message text. |
attachments |
Array of attachments. Array syntax: [["name", "link"], ["name", "link"], ...]. Replace name with the name of the attachment and link with the full URL of the attachment. |
department |
The ID of a department. You can get the IDs from Settings > Miscellaneous > Departments. Default: NULL. |
agent_id |
The ID of the agent assigned to the conversation. Default: NULL. |
onSuccess |
Function to execute when the function completes. Syntax: function(conversation) { ... }. Default: false. |
Information
- Requirement. The user must be active.
SBChat.setConversation()
Set an existing conversation as active conversation.
Parameters
conversation |
The conversation. It must be a SBConversation object. Use the function SBF.activeUser().conversations to get the conversations list. |
Information
- Requirement. The user must be active.
SBChat.startRealTime()
Start the real-time check of new messages for the active conversation every 1000ms.
SBChat.stopRealTime()
Stop the real-time check of new messages.
SBChat.busy()
Show or hide the loading icon and enable or disable the chat busy mode. When the chat is in busy mode no messages or attachments can be sent.
Parameters
value |
Boolean. true or false. |
Information
- The loading icon appears only in the conversation area, not in the dashboard or in other panels.
- Requirement. The user must be active.
SBChat.lastAgent()
Returns the last agent of the active conversation.
Parameters
bot |
Boolean. Set it to false to exclude the bot. Default: true. |
Response
{ "user_id": "123456", "full_name": "Don John", "profile_image": "https://alz-bot.com/agent.svg" }
SBChat.scrollBottom()
Scroll the chat to the bottom.
Parameters
top |
Boolean. Set it to true to scroll on top. Default: false. |
SBChat.isBottom()
Checks if the chat is at bottom.
SBChat.showDashboard()
Display the dashboard.
SBChat.hideDashboard()
Hide the dashboard.
SBChat.showPanel()
Shows the specified area inside the chat widget.
Parameters
name |
The panel name. Available values: articles. |
SBChat.hidePanel()
Hide the active panel inside the chat widget.
SBChat.clear()
Clear the conversation area of the chat widget and the disable the active conversation.
SBChat.updateNotifications()
Update the red notification counter of the chat button that alerts the user of new messages and new conversations.
Parameters
action |
Insert add to increase the counter of 1, insert remove to decrease the counter of 1. Default: add. |
conversation_id |
The ID of the conversation linked to the update of the counter. Use the function SBF.activeUser().conversations to get the conversations list of the active user. |
SBChat.setConversationStatus()
Update the status code of a conversation.
Parameters
status_code |
The status code to assign to the conversation. Status codes: live = 0, waiting answer from user = 1, waiting answer from agent = 2, archive = 3, trash = 4. |
Information
- Requirement. The user must be active.
SBChat.typing()
Manage the typing ... label of the chat header.
Parameters
user_id |
The ID of the active user (or the ID of the active agent if you're in the admin area). Use the function SBF.activeUser().id to get the ID of the active user (use the variable SB_ACTIVE_AGENT["id"] to get the ID of the active agent if you're in the admin area). Use the variable SBChat.agent_id to get the ID of the last agent of the conversation. Default: -1. |
action |
Available values:
|
Information
- The typing label is visible only when a conversation is open.
SBChat.showArticles()
Display the articles area or one single article.
Parameters
id |
The ID of an article to show. Use the function SBChat.getArticles() to get the articles list. Default: -1. |
SBChat.getArticles()
Returns the articles list or the content of one single article.
Parameters
id |
The ID of an article to show. Add multiple IDs separated by commas. Use the function SBChat.getArticles() to get the articles list. Default: false. |
onSuccess |
Function to execute when the function completes. Syntax: function(response) { ... }. Default: false. |
category |
Return only the articles of the given category ID. If set to true return also the categories list. Default: true. |
count |
The maximum number of articles to be returned. Default: true. |
Response
[ { "id": "6P2Oq", "title": "What's new with the API V2?p", "content": "The API V2 is the new iteration of our developer API ...", "link": "https://alz-bot.com", "categories": ["Nv9PG"] }, { "title": "Which API version am I currently using?", "content": "The API version is configured separately for each ...", "link": "", "id": "IDkft", "categories": [] }, ... ]
If single article, the returned value is the article:
{ "id": "6P2Oq", "title": "What's new with the API V2?p", "content": "The API V2 is the new iteration of our developer API. The new API integrates Google Cloud Spe API V2 is the new iteration of our developer API. ", "link": "https://alz-bot.com" }
Information
- Each article of the list contains only an excerpt of the content.
SBChat.searchArticles()
Display the articles matching the search in the dashboard' articles box.
Parameters
search |
String with the search terms. The search function supports the title and the content. |
button |
The search button object. |
target |
The HTML object to Enter the articles into. |
Information
- Requirement. The dashboard must be active.
- Requirement. The articles be active.
SBChat.setArticleRating()
Set the rating of an article.
Parameters
article_id |
The article ID. |
rating |
The rating to add. Insert 1 for a positive rating or 0 for a negative one. |
onSuccess |
Function to execute when the function completes. Syntax: function(response) { ... }. Default: false. |
SBChat.categoryEmoji()
Select a category of the emoji box.
Parameters
category |
The category name. Available values: Smileys, People, Animals, Food, Travel, Activities, Objects, Symbols. |
SBChat.searchEmoji()
search for emojis that match the search terms and show them in the emoji box.
Parameters
search |
The search text. |
SBChat.insertText()
Insert a string in the chat editor.
Parameters
text |
The string to insert in the editor. |
Information
- Requirement. A conversation must be active and open.
SBChat.privacy()
Display the privacy message and force the user to accept the terms before starting the chat.
SBChat.popup()
Display a pop-up message or close it.
Parameters
close |
Boolean. Set it to true to close the pop-up. Default: false. |
content |
Array with the pop-up content. Array syntax: { image: "", title: "", message: "" }. Default: the content inserted in the Settings > Chat > Popup message area. |
Information
- Requirement. The chat must close.
SBChat.slackMessage()
Send a message to Slack.
Parameters
user_id |
The ID of the active user (or the ID of the active agent if you're in the admin area). Use the function SBF.activeUser().id to get the ID of the active user (use the variable SB_ACTIVE_AGENT["id"] to get the ID of the active agent if you're in the admin area). Use the variable SBChat.agent_id to get the ID of the last agent of the conversation. Default: -1. |
full_name |
The name of the sender, it will appear in Slack on the left of the message. It should be an agent's name if the message is from an agent, otherwise the user's name. |
profile_image |
The profile image of the sender, it will appear in Slack on the left of the message. It should be an agent's profile image if the message is from an agent, otherwise the user's profile image. Supported formats: PNG and JPG. |
message |
The message text. |
attachments |
Array of attachments in JSON format. Array syntax: [["name", "link"], ["name", "link"], ...]. Replace name with the name of the attachment and link with the full URL of the attachment. |
Information
- Requirement. A conversation must be active.
SBChat.deleteMessage()
Delete a message from the database and the active conversation if available.
Parameters
message_id |
The ID of the message to delete. Use the function SBChat.conversation.messages to get the messages list of the active conversation. |
Information
- Only the messages of the conversations of the active user can be deleted.
- Requirement. A conversation must be active.
SBChat.registration()
Display the registration or the login area or check if the registration is required.
Parameters
check |
Set it to true to check if the registration is required. Default: false. |
type |
Insert registration to display the registration form, insert login to display the login form. |
SBChat.addUserAndLogin()
Register a new user as a visitor and login it automatically after the registration. Optionally execute a function on complete.
Parameters
onSuccess |
Function to execute when the function completes. Syntax: function(response) { ... }. Default: false. |
Response
[ { "id": "913", "profile_image": "https://alz-bot.com/user.svg", "first_name": "Don", "last_name": "John", "email": "[email protected]", "user_type": "user", "token": "9b25351047ee758aa97ee4868d130cc1ceb8decf" }, "YXNkWGNSeTdtRTdDYVkxVG8wckN4YWF6V2s0Tk1mczBSVHdQbHBpOWdmejVUTTdOUUxEUENhdUVoYmROWn..." ]
The last value is the encrypted login data ready to be stored in the Web Storage of the user' browser. Use the function SBF.loginCookie(response[1]); to store it.
Information
- If a user is already logged-in a page reload is required to activate the new user.
SBChat.getDepartmentCode()
Returns an HTML code with the details of the given department or of all the departments. Department details: id, color, image, name.
Parameters
department_id |
The ID of the department. If this parameter is not setted or null, the function returns the code of all departments. |
onSuccess |
Function to execute when the function completes. Syntax: function(response) { ... }. |
Response
<div data-color="red"><img src="sales.jpg" /><div>Sales<div></div>
SBChat.offlineMessage()
Checks if the offline message can be sent and send it.
Information
- Requirement. A conversation must be active.
SBChat.isInitDashboard()
Checks if dashboard is shown by default when the chat widget is initialized.
SBChat.closeChat()
Archives a conversation and hide it from the chat widget.
Parameters
update_conversation_status |
Set it to false to only hide the conversation from the chat widget without setting its status to archived. Default: true. |
SBChat.flashNotification()
Starts the flash notification.
SBChat.playSound()
Play the sound that plays when a new message is received.
Parameters
repeat |
Set it to true to repeat the sound as many times as set in the settings. Default: false. |
SBChat.automations.runAll()
Checks all automations and runs them if the trigger conditions are validated.
Apps
List of functions of the Alz-Bot apps.
SBApps.is()
Checks if an app is available.
Parameters
name |
The app name, e.g. dialogflow. |
SBApps.wordpress.ajax()
Makes a WordPress AJAX call.
Parameters
action |
The action. Available values: wp-login, wp-registration, button-purchase. Other values may be available, check main.js file for all values. |
data |
The action parameters, check main.js file for more details. |
onSuccess |
Function to execute when the function completes. Syntax: function(response) { ... }. Default: false. |
SBApps.dialogflow.message()
Send a message to Dialogflow and add the Dialogflow response to the active conversation as a new message.
Parameters
message |
The message text. |
attachments |
Array of attachments. Array syntax: [["name", "link"], ["name", "link"], ...]. Replace name with the name of the attachment and link with the full URL of the attachment. Dialogflow can read this array. |
delay |
Bot response delay in milliseconds. |
parameters |
Array of optional information. Array syntax: { "name": "value", "name": "value", ...}. |
Information
- Requirement. The Dialogflow App is required and Dialogflow must be active in the Settings area.
- Requirement. The user must be active.
- Use SBApps.dialogflow.project_id = AGENT_ID to change the default Dialogflow agent.
SBApps.dialogflow.active()
Check if Dialogflow is active or deactivate it.
Parameters
active |
Set it to false to disable Dialogflow and stop the bot. |
Response
Return true if the Dialogflow bot is active, otherwise, return false.
SBApps.dialogflow.welcome()
Triggers the Dialogflow welcome Intent and display the Dialogflow welcome message.
Information
- Requirement. The Dialogflow App is required and Dialogflow must be active in the Settings area.
SBApps.dialogflow.openAI()
Sends a message to OpenAI (ChatGPT), return the response, and optionally adds the response as a new message.
Parameters
message |
The message. |
onSuccess |
Function to execute when the function completes. Syntax: function(response) { ... }. |
Information
- Requirement. The Dialogflow App is required and Settings > Dialogflow > OpenAI > Active must be active.
- If a conversation is active, the OpenAI response is automatically added as as new message.
SBApps.dialogflow.typing()
Starts the typing animation of the chat widget.
SBApps.dialogflow.humanTakeover()
Starts the Dialogflow human takeover of Settings > Dialogflow > Human takeover.
SBApps.dialogflow.humanTakeoverActive()
Check if human takeover is active for the active conversation.
SBApps.dialogflow.translate()
Translate multiple strings via Google Translate.
Parameters
strings |
Array of the strings to translate, e.g. ["Hello world", "How are you?"]. |
language_code |
The two-letter language code of the language you want to translate into. |
onSuccess |
Function to execute when the function completes. Syntax: function(response) { ... }. |
SBApps.woocommerce.updateCart()
Update the cart of the active user.
Parameters
action |
Available actions: cart-add, cart-remove |
product_id |
The product ID to add or remove. |
SBApps.woocommerce.waitingList()
Display the waiting list message.
Parameters
action |
Set it to request. The other actions are used internally by the script. |
product_id |
The ID of the product to add to the waiting list. |
Tickets
List of functions of the Tickets App.
SBTickets.showPanel()
Display a panel or the conversation area.
Parameters
name |
The name of the panel to show. Available names: new-ticket, privacy, articles, edit-profile, login, registration. Leave it empty to display the main conversation area. |
title |
The title to display as the panel name. |
SBTickets.showSidePanels()
Display or hide the side panels.
Parameters
show |
Set it to false to hide the panels. |
SBTickets.setAgent()
Get the agent details and populate the agent profile area of the right panel.
Parameters
agent_id |
The ID of the agent. |
SBTickets.activateConversation()
Activate and display a conversation.
Parameters
conversation |
The conversation to activate as a SBConversation object. |
SBTickets.selectConversation()
Set the style of a conversation of the left panel as the active conversation.
Parameters
conversation_id |
The ID of the conversation. |
SBTickets.getActiveConversation()
Returns the HTML DOM object of the active conversation.
Parameters
type |
Set it to ID to get only the ID of the conversation. |
Pusher
List of functions for Pusher. More details at pusher.com.
SBPusher.init()
Initialize Pusher and optionally execute a function on initialization completed.
Parameters
onSuccess |
Function to execute when the function completes. Syntax: function(response) { ... }. |
SBPusher.start()
Start Pusher and Push notifications. Run this function after SBPusher.init() and after the user is active.
SBPusher.subscribe()
Subscribe the active user to a Pusher channel.
Parameters
channel_name |
The channel name. |
onSuccess |
Function to execute when the function completes. Syntax: function(response) { ... }. |
Information
- If Pusher is not initialized the function automatically initializes it.
- You can access the channel from SBPusher.channels['CHANNEL NAME'].
SBPusher.event()
Subscribe the active user to an event of a Pusher channel and execute the given function when the event is received.
Parameters
event |
The event name. |
callback |
Function to execute once the event is received. Syntax: function(response) { ... }. |
channel |
The channel name. Default: private-user-[active user ID]. |
Information
- If Pusher is not initialized the function automatically initializes it.
- If the user is not subscribed to the channel the function automatically subscribes the user.
SBPusher.trigger()
Trigger an avent on a Pusher channel.
Parameters
event |
The event name. |
data |
Array of values. Syntax: { "name": "value" }. |
channel |
The channel name. Default: private-user-[active user ID]. |
SBPusher.presence()
Subscribe the active user to the presence channel used for the online status of users and admins.
Parameters
index |
The presence channel index. Default: 1. |
onSuccess |
Function to execute when the function completes. Syntax: function(response) { ... }. |
Information
- If Pusher is not initialized the function automatically initializes it.
SBPusher.presenceUnsubscribe()
Unsubscribe the active user from the presence channel.
SBPusher.pushNotification()
Send a Push notification to the last agent of the conversation, or all agents if no agents have replied yet.
Parameters
message |
The message text. |
Information
- This function works only if the Push notifications are active in the settings area.
- Currently, Push notifications are supported only on Mac, Windows and Android devices. IPhones and iOS devices are not supported.
- For more details click here.
More functions
List of various functions that perform different tasks.
SBF.translate()
Translate a string to the active user language.
Parameters
string |
The string to translate. |
Information
- Returns the translated string if available, otherwise the original string.
- This function works only for the front-end translations.
- For more details about the active language check the translations docs.
SBF.activeUser()
Returns the active user as a SBUser object, return false if the active user is not found.
Active user JSON representation
{ "details": { "id": "914", "profile_image": "https://alz-bot.com/user.svg", "first_name": "User", "last_name": "#23262", "email": null, "user_type": "visitor", "token": "bc308e274473fb685a729abe8a4bf82d3c49cd2f" }, "extra": {}, "conversations": [] }
Information
- For the user' methods and more details see the SBUser documentation.
SBF.getActiveUser()
Activate the logged-in user and returns the user details.
Parameters
db |
Set it to true to verify that the user exists in the database. |
onSuccess |
Function to execute when the function completes. Syntax: function(response) { ... }. |
Response
{ "id": "914", "profile_image": "https://alz-bot.com/user.svg", "first_name": "Don", "last_name": "John", "email": "[email protected]", "user_type": "user", "token": "bc308e274473fb685a729abe8a4bf82d3c49cd2f" }
Information
- For the user' methods and more details see the SBUser documentation.
SBF.cors()
Execute an HTTP POST or GET request to a URL and returns the response.
Parameters
method |
Insert POST or GET. Default: GET. |
url |
Enter the full URL of the request. |
onSuccess |
Function to execute when the function completes. Syntax: function(response) { ... }. |
SBF.null()
Check if an existing variable is null or empty.
Parameters
variable |
The variable to check. |
Information
- Return true if the variable is an empty string, null, 'null', undefined.
SBF.deactivateAll()
Hide all the pop-ups and the windows. This function is used mostly in the admin area.
SBF.getURL()
Search for a parameter in the URL and returns its value or returns an array with all parameters.
Parameters
name |
The parameter to search. Return false if the parameter is not found. If the parameter name is not provided an array with all parameters is returned instead. Default: false. |
url |
The URL from which extract the parameters. Default: current URL. |
SBF.restoreJson()
Convert a JSON encoded string into a normal text.
Parameters
value |
The string to convert. |
SBF.stringToSlug()
Convert a string to a slug by removing all special chars, by replacing all spaces with the char -, and by making the string lowercase.
Parameters
value |
The string to convert. |
Information
- Use the function slugToString(slug) to convert back a slug to a string.
SBF.settingsStringToArray()
Convert a string to an array of values. String format: name:value,name:value,....
Parameters
value |
The string to convert. |
Response
{ "name": "value", "name": "value", ... }
SBF.random()
Returns a random alphanumeric string.
SBF.isAgent()
Check if a user type is an agent. Return true only if the user type is agent, admin, or bot.
Parameters
user_type |
The user type string to check. |
SBF.error()
Trigger the custom JavaScript error of Alz-Bot.
Parameters
message |
String with the error message or a Error object. |
SBF.errorValidation()
Check if a response from an AJAX call is a validation error.
Parameters
response |
The response from the AJAX call. |
SBF.login()
Login a user or an agent. The login can be completed in two ways: via email and password, or via user ID and token.
Parameters
|
The email of the user to login. If this attribute is set you need to set also the password. Default: empty string. |
password |
The password of the user to login. If this attribute is set you need to set also the email. Default: empty string. |
user_id |
The ID of the user to login. If this attribute is set you need to set also the token. Default: empty string. |
token |
The token of the user to login. If this attribute is set you need to set also the user ID. You can get the token from the Users area by opening the profile box of a user, only if you're an admin. Default: empty string. |
onSuccess |
Function to execute when the function completes. Syntax: function(response) { ... }. Default: false. |
Response
[ { "id": "913", "profile_image": "https://alz-bot.com/user.svg", "first_name": "Don", "last_name": "John", "email": "[email protected]", "user_type": "user", "token": "9b25351047ee758aa97ee4868d130cc1ceb8decf" }, "YXNkWGNSeTdtRTdDYVkxVG8wckN4YWF6V2s0Tk1mczBSVHdQbHBpOWdmejVUTTdOUUxEUENhdUVoYmROWn..." ]
Return false if login is unsuccessful.
SBF.logout()
Logout the logged-in user and reload the page.
SBF.loginCookie()
Create or update the login cookie.
Parameters
value |
The encrypted login string. |
SBF.reset()
Logout the logged-in user, remove all Alz-Bot stored data, and reload the page.
SBF.lightbox()
Display the given content in a lightbox.
Parameters
content |
The content to display. It can be any HTML content, to display an image use the code <img src="image.jpg" >. |
SBF.storage()
Manage the local storage of Alz-Bot. The local storage is a technology that saves any data in the browser, permanently.
Parameters
key |
The ID of the value to set or retrieve. |
value |
The value to save. If not set the function returns the value of the given key. |
SBF.storageTime()
Save a key and the current date and time in the local storage to check in the future if it's within the given number of hours or if it's expired.
Parameters
key |
The key to save or check. |
hours |
The number of hours to compare to the saved date and time. |
Response
If the hours attribute is set, return true if the sum of saved date and time and the given hours is less than the current date and time, otherwise, return false. Example: if the saved time is 5:00 pm, and you insert 3, the function will return true only if the current time is 8:01 pm or more. true
SBF.setting()
Returns the value of a setting.
Parameters
value |
Available settings
Some of the available settings and the values are in the list below.
{ "registration-required": "", "registration-timetable": false, "registration-offline": false, "registration-link": "", "visitors-registration": false, "privacy": false, "popup": true, "popup-mobile-hidden": true, "welcome": false, "welcome-trigger": "open", "welcome-delay": 0, "follow": false, "follow-delay": "1000", "chat-manual-init": false, "chat-login-init": false, "sound": ["code": "n", "volume": 0.5, "repeat": 5], "header-name": true, "desktop-notifications": "all", "flash-notifications": "all", "push-notifications": true, "notifications-icon": "", "bot-id": "377", "bot-name": "Bruce Peterson", "bot-image": "", "bot-delay": 0, "bot-office-hours": false, "dialogflow-active": true, "dialogflow-human-takeover": false, "slack-active": false, "rich-messages": [ "email", "registration", "login", "timetable", "articles", "immagine", "video" ], "display-users-thumb": true, "hide-agents-thumb": true, "notify-user-email": true, "notify-agent-email": false, "translations": false, "auto-open": false, "office-hours": true, "disable-office-hours": false, "disable-offline": false, "timetable": false, "timetable-hide": [ false, "checkbox" ], "articles": true, "articles-title": "", "init-dashboard": false, "wp": false, "wp-users-system": "sb", "queue": false, "queue-message": "", "queue-message-success": "", "queue-response-time": "", "routing": false, "webhooks": true, "agents-online": false, "timetable-message": "", "tickets-registration-required": true, "tickets-registration-redirect": "", "tickets-default-form": "login", ... }
SBF.shortcode()
Convert a shortcode into an array containing the shortcode name and the shortcode settings.
Parameters
shortcode |
The shortcode string. Example: [rating title="Rate your conversation" message="Tell us your experience." success="Thank you!"]. |
Response
[ "rating", { "title": "Rate your conversation", "message": "Tell us your experience.", "success": "Thank you!" } ]
SBF.openWindow()
Open a web page in a new window.
Parameters
link |
The link to open. |
width |
The window width in px. |
height |
The window height in px. |
SBF.loadResource()
Include a .js or .css file in the <head< area of the page.
Parameters
url |
The URL of the file to load. |
script |
Set to to true for .js files. Default: .css files. |
SBF.debounce()
Execute the given function only once in a given period, delay milliseconds after its last invocation, the timer is reset on every call.
Parameters
bounceFunction |
Function to execute when the function completes. Syntax: function() { ... }. |
id |
Insert a random, unique string never used by other debounce instances. The strings #1, #2, #3, #4, ... are reserved and can't be used.' |
interval |
The minimum time gap in milliseconds between the new execution and the previous one. Default: 500. |
SBF.translate()
Translate a string using the Alz-Bot translations.
Parameters
string |
The string to translate. |
SBF.escape()
Escape a string.
Parameters
string |
The string to escape. |
SBF.convertUTCDateToLocalDate()
Convert a date to local time.
Parameters
datetime |
The date and time string. Format: Y/m/d H:i:s. |
UTCoffset |
An UTC offset. Default: 0. |
Response
Mon Jan 30 2023 10:45:00 GMT+0000 (Greenwich Mean Time)
SBF.getLocationTimeString()
Returns a string containing the location and current local time of the given timezone.
Parameters
details |
Array with the location details. Example: { "timezone" : "", "country" : "", "city" : "" }. This function accepts the extra method of any SBUser object. Example: SBF.getLocationTimeString(activeUser().extra, function(){}). |
onSuccess |
Function to execute when the function completes. Syntax: function(response) { ... }. |
Response
05:15 AM in London, United Kingdom
SBF.beautifyTime()
Convert a date to the local format and perform other optimizations to make the date more friendly.
Parameters
date |
Date and time in the following format: YYYY-MM-DD HH:MM:SS. Ex. 2020-05-13 13:35:59. You can remove the time and leave only the date. The dates stored in the database are in UTC+0. |
extended |
Set it to true to include minutes and seconds. Default: false. |
future |
Set it to true the date is a future date. Default: false. |
Response
<span>30/01/2023</span>
SBF.dateDB()
Convert a date format to the date format of the database and set the UTC to +0.
Parameters
date |
Date and time in the following format: YYYY-MM-DD HH:MM:SS. Ex. 2020-05-13 13:35:59. You can remove the time and leave only the date. Insert now to get the current date and time. The dates stored in the database are in UTC+0. |
SBF.UTC()
Returns the specified date and time in unix format using the UTC offset set in Settings > Miscellaneous > UTC offset.
Parameters
datetime |
The date and time string. |
Response
1675075500000
SBF.unix()
Get the unix timestamp value of a date and time string with format yyyy-mm-dd hh:mm:ss.
Parameters
datetime |
The date and time string. |
Response
1675075500000
Events
Events lets you intercept Alz-Bot actions in real-time and execute a custom JavaScript code when an action is triggered.
Usage
Use the code below and replace EVENT-NAME with the event name. The response represents the returned value if there is only one attribute, otherwise, it's an array of values. JQuery is required.
$(document).on("EVENT-NAME", function (e, response) { // Insert your code here });
Example:
$(document).on("SBMessageSent", function (e, response) { console.log(response["user_id"]); console.log(response["conversation_id"]); console.log(response["message"]); });
SBReady
Event fired on page load after the chat' script main.js has been loaded. This event is fired also in the admin area.
SBInit
Event fired on page load when the chat has completed the initialization.
SBTicketsInit
Event fired on page load when the tickets area has completed the initialization. This event is available only when the Tickets App is active.
SBLogout
Event fired when the active user logout.
SBError
Event fired when a Alz-Bot error occurs.
Response
message |
The error message. |
function_name |
The function name that has generated the error. |
SBDoubleLoginError
Event fired on chat initialization if an agent or an admin is already logged-in.
SBUserDeleted
Event fired when a user is deleted.
Response
The ID of the user that has been deleted.
SBMessageSent
Event fired when a new message has been sent.
Response
user_id |
The ID of the user that sent the message. |
user |
The user object. |
conversation_id |
The ID of the conversation linked to the message. |
conversation_status |
The status code of the conversation linked to the message. Status codes: live = 0, waiting answer from user = 1, waiting answer from agent = 2, archive = 3, trash = 4. |
message_id |
The ID of the message. |
message |
The text of the message. |
attachments |
The attachments of the message. |
SBBotMessage
Event fired when the Dialogflow bot reply to a message.
Response
response |
The response array in JSON format from Dialogflow. |
message |
The input message of the user. |
SBSlackMessageSent
Event fired when a message is sent to Slack.
Response
message |
The text of the message. |
conversation_id |
The ID of the conversation linked to the message. |
SBEmailSent
Event fired when a notification email is sent to a user or an agent.
Response
recipent_id |
The ID of the user that will receive the email. |
message |
The message of the email. |
attachments |
The attachments of the email. |
SBNotificationsUpdate
Event fired when the red notification counter of the chat button that alerts the user of new messages and conversations is updated.
Response
action |
The action value can be add if the counter is increased by 1, or remove it the counter is decreased by 1. |
conversation_id |
The action value can be add if the counter is increased by 1, or remove it the counter is decreased by 1. |
SBConversationOpen
Event fired when a conversation is fully loaded and it's opened in the chat.
Response
response |
The conversation as a SBConversation object. |
SBNewMessagesReceived
Event fired when there are new messages in the active conversation.
Response
The list of the new messages. Each message is a SBMessage object.
response |
The single message as a SBMessage or an array of SBMessage objects. |
SBMessageDeleted
Event fired when a message is deleted.
Response
The ID of the message that has been deleted.
SBNewConversationReceived
Event fired when a new conversation is received.
Response
The new conversation as a SBConversation object.
SBNewConversationCreated
Event fired when a new conversation is created.
Response
The new conversation as a SBConversation object.
SBActiveConversationChanged
Event fired when the active conversation is changed.
Response
The new active conversation as a SBConversation object.
SBActiveConversationStatusUpdated
Event fired when the active conversation status code is updated.
Response
conversation_id |
The ID of the conversation. |
status_code |
The new status code of the conversation. Status codes: live = 0, waiting answer from user = 1, waiting answer from agent = 2, archive = 3, trash = 4. |
SBChatOpen
Event fired when the chat is opened.
SBChatClose
Event fired when the chat is closed.
SBQueueUpdate
Event fired when the queue is started and each time the queue is updated.
Response
The position of the user in the queue. If the position is 0 the queue is ended and the user can start the chat.
SBBusy
Event fired when the busy status of the chat changes. The chat is busy if it's operating, like sending a message. When the chat is busy some functions can not be fired, like sending a new message.
Response
true if the chat is busy, otherwise false.
SBDashboard
Event fired when the dashboard is displayed.
SBDashboardClosed
Event fired when the dashboard is closed and a conversation is displayed instead.
SBTyping
Event fired when a user or an agent is typing in the editor.
Response
true if the user or agent is typing, otherwise false.
SBArticles
Event fired when the articles panel is displayed or when a single article is opened.
Response
id |
The ID of the article. This value is -1 if the articles panel is displayed. |
articles |
It can be the array with the single article details or the array with the list of all the articles. |
SBPrivacy
Event fired on chat initialization if the privacy form is displayed.
SBPopup
Event fired when a pop-up message is displayed.
Response
The array with the contents of the pop-up: { image: "", title: "", message: "" }.
SBFollowUp
Event fired when the follow-up message is sent.
SBWelcomeMessage
Event fired when the welcome message is sent.
SBLoginForm
Event fired when the user login successfully from the login form of the chat. This event is fired only if the login is successful.
Response
The user as a SBUser object.
SBRegistrationForm
Event fired when the user registers successfully from the registration form of the chat. This event is fired only if the registration is successful. This event is fired also if the registration is updated via the Rich Message form.
Response
user |
Array with the user details. |
extra |
Array with the additional user details. |
SBRichMessageSubmit
Event fired when the response from a Rich Message is received.
Response
result |
The response of the Rich Message. |
data |
The Rich Message details and the data sent by the user. |
id |
The ID of the Rich Message. |
SBAttachments
Event fired when the user attaches a file.
SBNewEmailAddress
Event fired when a user register his email via the follow-up message or registration form.
Response
name |
The full name of the user. |
|
The email of the user. |
ID |
The ID of the rich message. |
SBPanelActive
Event fired when a panel of the Tickets area is opened. This event is available only when the Tickets App is active.
Response
name |
The name of the active panel. Values: new-ticket, privacy, articles, edit-profile, login, registration. If the value is empty the main conversation area is active. |
|
The email of the user. |
SBWoocommerceCartUpdated
Event fired when the chat add a product to the WordPress WooCommerce cart. In most cases, this event is fired by the Dialogflow chatbot.
Response
action |
cart-add or cart-remove. |
product |
The product name or ID. |
SBBotPayload
Event fired when a Dialogflow message contains a Alz-Bot Payload. Payload examples: human-takeover, redirect, woocommerce-update-cart, woocommerce-checkout.
Response
The payload name.
SBBotAction
Event fired when a Dialogflow message contains a Dialogflow action. Currently only the action end (End conversation) is available.
Response
The action name.
SBSMSSent
Event fired when a text message notification is sent to a user or an agent.
Response
recipent_id |
The ID of the user that will receive the text message. |
message |
The message of the text message. |
response |
The Twilio response. |
SBActiveUserLoaded
Event fired when a the active user has been loaded.
Response
recipent_id |
The ID of the user that will receive the text message. |
message |
The message of the text message. |
response |
The Twilio response. |
AJAX functions
List of AJAX functions. The AJAX functions are similar to the WEB API, they use the same function name, the same parameters, and returns the same responses. Use the function below to start an AJAX call:
SBF.ajax({ function: 'FUNCTION-NAME', parameter: value, parameter: value, ... }, (response) => { // Insert your code here });
Replace FUNCTION-NAME with the name of one of the functions below. Replace the list of parameter: value with the parameters of the function.
Parameters and responses are the same as the WEB API. The response is in JSON format.
Warning! Do not include the token in the parameters. The token must be kept always secret.Functions
Function name | Requirements | Parameters and response |
---|---|---|
saved-replies |
Saved replies | |
get-settings |
|
Get settings |
save-settings |
|
Save settings |
is-online |
|
Is online |
add-user |
|
Add user |
add-user-and-login |
Add user | |
get-user |
|
Get user |
get-users |
|
Get users |
get-new-users |
|
Get new users |
get-user-extra |
|
Get user extra |
get-user-language |
|
Get user language |
get-online-users |
|
Get online users |
get-user-from-conversation |
|
Get user from conversation |
agents-online |
Agents online | |
search-users |
|
Search users |
delete-user |
|
Delete user |
delete-users |
|
Delete users |
update-user |
|
Update user |
update-user-to-lead |
|
Update user to lead |
count-users |
|
Count users |
get-conversations |
|
Get conversations |
get-new-conversations |
|
Get new conversations |
get-conversation |
|
Get conversation |
get-user-conversations |
|
Get user conversations |
get-new-user-conversations |
|
Get new user conversations |
search-conversations |
|
Search conversations |
search-user-conversations |
|
Search user conversations |
new-conversation |
|
new-conversation |
update-conversation-status |
Update conversation status | |
update-conversation-department |
|
Update department |
update-conversation-agent |
|
Update agent |
get-new-messages |
|
Get new messages |
send-message |
|
Send message |
send-email |
|
Send email |
send-slack-message |
|
Send Slack message |
update-message |
|
Update message |
update-messages-status |
|
Update messages status |
delete-message |
|
Delete message |
slack-users |
|
Slack users |
archive-slack-channels |
|
Archive Slack channels |
slack-channels |
|
Slack channels |
current-url |
Current URL | |
set-rating |
|
Set rating |
get-rating |
|
Get rating |
get-articles |
Get articles | |
save-articles |
|
Save articles |
search-articles |
Search articles | |
get-articles-categories |
|
Get articles categories |
save-articles-categories |
|
Save articles categories |
article-ratings |
Article ratings | |
get-versions |
Get versions | |
update |
|
Update |
app-get-key |
|
App get key |
app-activation |
|
App activation |
csv-users |
|
Csv users |
transcript |
|
Transcript |
is-agent-typing |
|
Is agent typing |
dialogflow-message |
|
Send bot message |
dialogflow-get-intents |
|
Dialogflow get Intents |
dialogflow-create-intent |
|
Dialogflow create Intent |
dialogflow-update-intent |
|
Dialogflow update Intent |
dialogflow-entity |
|
Dialogflow Entity |
dialogflow-get-entity |
|
Dialogflow get Entity |
dialogflow-get-token |
Dialogflow get token | |
dialogflow-get-agent |
|
Dialogflow get agent |
dialogflow-set-active-context |
|
Dialogflow set active context |
dialogflow-curl |
|
Dialogflow curl |
dialogflow-human-takeover |
|
Dialogflow human takeover |
dialogflow-smart-reply |
|
Dialogflow smart reply |
cron-jobs |
Cron jobs | |
woocommerce-get-customer |
|
Woocommerce get customer |
woocommerce-get-user-orders |
|
Woocommerce get user orders |
woocommerce-get-order |
|
Woocommerce get order |
woocommerce-get-product |
|
Woocommerce get product |
woocommerce-get-products |
|
Woocommerce get products |
woocommerce-search-products |
|
Woocommerce search products |
woocommerce-get-taxonomies |
|
Woocommerce get taxonomies |
woocommerce-get-attributes |
|
Woocommerce get attributes |
woocommerce-get-product-id-by-name |
|
Woocommerce get product ID by name |
woocommerce-get-product-images |
|
Woocommerce get product images |
woocommerce-get-product-taxonomies |
|
Woocommerce get product taxonomies |
woocommerce-get-attribute-by-term |
|
Woocommerce get attribute by term |
woocommerce-get-attribute-by-name |
|
Woocommerce get attribute by name |
woocommerce-is-in-stock |
|
Woocommerce is in stock |
woocommerce-coupon |
|
Woocommerce coupon |
woocommerce-coupon-check |
|
Woocommerce coupon check |
woocommerce-coupon-delete-expired |
|
Woocommerce coupon delete expired |
woocommerce-get-url |
|
Woocommerce get URL |
woocommerce-get-session |
|
Woocommerce get sesssion |
woocommerce-get-session-key |
|
Woocommerce get session key |
woocommerce-payment-methods |
|
Woocommerce payment methods |
woocommerce-shipping-locations |
|
Woocommerce shipping locations |
chat-css |
Css | |
get-avatar |
|
Get avatar |
get-agents-ids |
|
Get avatar |
get-users-with-details |
|
Get users with details |
send-custom-email |
|
Send custom email |
send-sms |
|
Send sms |
email-piping |
Email piping | |
get-notes |
|
Get notes |
add-note |
|
Add note |
delete-note |
|
Delete note |
automations-get |
Automations get | |
automations-save |
|
Automations save |
automations-validate |
Aautomations validate | |
automations-run-all |
Automations run all | |
automations-run |
Automations run | |
get-agents-in-conversation |
|
Get agents in conversation |
get-departments |
Get departments | |
login |
Login | |
logout |
Logout | |
update-login |
|
Update login |
is-typing |
Is typing | |
set-typing |
Set typing | |
clean-data |
|
Clean data |
get-translation |
get-translation | |
get-translations |
get-translations | |
save-translations |
|
save-translations |
delete-leads |
|
Delete leads |
reports |
|
Reports |
reports-update |
|
Reports update |
direct-message |
|
Direct message |
count-conversations |
|
Count conversations |
updates-available |
|
Updates available |
google-translate |
|
Google translate |
google-language-detection-update-user |
|
Google translate detection update user |
export-settings |
|
Export settings |
import-settings |
|
Import settings |
check-conversations-assignment |
|
Check conversations assignment |
More AJAX functions
The functions below are available only via AJAX.
close-message
Send the close message to a conversation. You can set the close message in the Settings > Chat area.
Requirements
- This is an admin function and it works only if the active user is an agent.
Parameters
function |
Insert close-message. |
bot_id |
The ID of the bot. Use the function SBF.setting("bot-id") to get the ID of the bot. If you're in the admin area use instead SB_ADMIN_SETTINGS['bot-id']. |
conversation_id |
The ID of the conversation to which send the message. |
Response
{ "success": true, "response": { "status": "success", "message-id": 123456, "queue": false } }
update-user-and-message
Update the user details of a user and the content of a message.
Requirements
- If the active user is a user only the active user can be updated and only the messages linked to the conversations of the user can be updated. If the active user is an agent or an admin the function works for any user and any message.
Parameters
function |
Insert update-user-and-message. |
user_id |
The ID of the user to update. |
settings |
Array with the user details. Array syntax and values: { first_name: [""], last_name: [""], profile_image: [""], email: [""], user_type: [""] } |
settings_extra |
Array with additional user details in
JSON format.
Array syntax: { "ID": ["value", "Name"], "ID": ["value", "Name"], ...} |
message_id |
The ID of the message to update. |
message |
The message text. |
payload |
Associative array containing extra data. Example: {"rich-messages":{"123":{"type":"buttons","result":"Premium Plan"}}}. |
Response
true
get-agent
Returns the details of an agent, admin, or bot.
Parameters
agent_id |
The ID of the agent. |
Response
{ "id": "2", "first_name": "Don", "last_name": "John", "department": null, "flag": "gb.png", "country_code": "GB", "details": [ { "slug": "city", "name": "City", "value": "London" }, { "slug": "country", "name": "Country", "value": "United Kingdom" }, { "slug": "sport", "name": "Sport", "value": "[email protected]" }, { "slug": "timezone", "name": "Timezone", "value": "Europe/London" } ... ] }
user-autodata
Fetch the following detatils about the active user and update the user details: IP, city, location, country, timezone, currency, browser, browser language, os.
Parameters
user_id |
The user ID. |
Response
true