Getting started
Setup and usage

Setup and usage

The JavaScript API supplies a collection of functions and events that underpin the majority of Support Board 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 and include it before the chat script. Make sure the links are correct. If you're using the WordPress version this step is not required.

                                <script src="supportboard/js/min/jquery.min.js"></script>
                                <script id="sbinit" src="supportboard/js/main.js"></script>
                            

Enter the code snippets, functions, and methods of this documentation into the function below.

                                (function ($) {
                                    $(document).on("SBInit", function () {
                                        // Your code here
                                    });
                                }(jQuery));
                            

Function parameters

Enter the function parameters in the same order of this documentation, e.g. SBChat.sendMessage(user_id, message, attachments).

Debug

Check the browser console for errors and debug information.


Getting started
Objects

Objects

The JavaScript objects used by Support Board 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, e.g. { first_name: "", last_name: "", profile_image: "", email: "", user_type: "" }
  • extra is an array with the additional user details, e.g. { 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, e.g. get("email").
getExtra(key)
Returns the additional user detail of the given key if available, otherwise returns an empty string, e.g. get("phone").
set(key, value)
Update a user detail or add a new one, e.g. set("phone", "(02) 123 456789").
setExtra(key, value)
Update an additional user detail or add a new one.
update(function(){})
Connects to the database and update the user details and the additional user details with fresh data from the database. Optionally runs a function on complete. This method is asynchronous and requires the user ID to works.
getConversations(function(conversations){}, exclude_id)
Connects to the database and get the user conversations, each conversation includes an excerpt of the last message. Optionally runa 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){})
Connects to the database and returns a full conversation, including all messages. Optionally runs 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 get the conversations array position.
addConversation(conversation)
Adds 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()
Returns true if the user has at least 1 conversation, otherwise, returns false.
isExtraEmpty()
Returns true if the additional user details have been already set, otherwise returns false. This method returns true also if the additiona user details list is empty, but it's setted.
delete(function(){})
Deletes the user from the database and all the linked conversations and messages, permanently. Optionally runs 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, e.g. { "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://board.support/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, e.g. get("message").
set(key, value)
Updates a message detail or add a new one, e.g. set("message", "Hello!").
payload(key, value)
Sets or gets the payload. The payload is an associative array containing extra data, e.g. {"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 processes attachments, Rich Messages, and text formatting. Set translation to true to get the transalted message if it is available.
render(message)
Renders the message and format it by adding stylings like bold and italic, and by converting URLs to clickable links. Optionally accepts a string and renders it instead.
strip(message)
Removes the text formatting. Optionally accepts a string and removes 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, e.g. { 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://board.support/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, e.g. get("conversation_status_code").
set(key, value)
Update a conversation detail or add a new one, e.g. set("conversation_status_code", 2).
getMessage(ID)
Returns the message with the given ID. Returns false if the message is not found.
getLastMessage()
Returns the last message of the conversation. Returns 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.
getNextMessage(message_id, user_type)
Returns the message next to the one of the provided ID. User type argument can be user or agent.
updateMessage(ID, message)
Updates the message with the given ID. The parameter message must be a SBMessage object.
addMessages(messages)
Adds 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)
Removes the message with the given ID from the conversation object. This method doesn't update the database.
searchMessages(search, exact_match)
Searches for the specified string in all the messages of the conversation and returns an array with the messages that matches 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)
Returns an array containing only the messages sent by the user, by the bot, or by the agents. Accepted 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, e.g. [["image.jpg", "https://board.support/image.jpg", "jpg", "5132"], ["file.txt", "https://board.support/file.txt", "txt", "5135"], ...].
getLastConversationID()
Returns the ID of the last conversation if any, otherwise returns false.
updateMessagesStatus(ids)
Updates 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.

Getting started
Variables

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
Overwrites 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
Sets the default user details to be used when a new visitor enters the website. If a registered Support Board 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: 'don.jhon@email.com', 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
Returns true if the chat is initialized, otherwise returns false.
SBChat.conversation
Returns the active conversation. The value is false if there isn't any active conversation.
SBChat.is_busy
Returns true if the chat is in busy mode, otherwise returns false. When the chat is in busy mode no messages or attachments can be sent.
SBChat.chat_open
Returns true if the chat is open, otherwise returns false.
SBChat.agent_id
Returns the ID of the active agent in the active conversation. The value is -1 if there isn't any active agent.
SBChat.agent_online
Returns true if the active agent is online, otherwise returns false.
SBChat.user_online
Returns true if the user is online, otherwise returns false.
SBChat.timetable
Returns true if the current time is within the office hours, otherwise returns false.
SBChat.dashboard
Returns true if the dashboard is active and visible, otherwise returns false.

JAVASCRIPT API
Functions

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, e.g. { "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()

Changes 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()

Sends 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. Set it to a user ID to send to the specified user ID. Default: false.
onSuccess
Function to execute when the function completes. Syntax: function(response) { ... }. Default: false.

SBChat.sendSMS()

Sends a text message to the users or agents returned by getRecipientUserID().


Parameters

message
The message text.

SBChat.desktopNotification()

Sends 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()

Initializes the chat and displays 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 $(document).on("SBReady", function () { ... }); instead.

SBChat.open()

Opens or closes the chat window.


Parameters

open
Set it to false to close the chat. Default: true.

SBChat.openConversation()

Opens a conversation and displays 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()

Updates the active conversation and checks 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()

Populates 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()

Updates the user conversations list of the dashboard and checks if there are new conversations. This function is fired automatically every 10000ms.


Information

  • Requirement. The user must be active.

SBChat.newConversation()

Creates 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()

Sets 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()

Starts the real-time check of new messages for the active conversation every 1000ms.


SBChat.stopRealTime()

Stops the real-time check of new messages.


SBChat.busy()

Shows or hides 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
Set it to true to show the loading icon, set it to false to hide it.

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
Set it to false to exclude the bot. Default: true.

Response

                                {
                                    "user_id": "123456",
                                    "full_name": "Don John",
                                    "profile_image": "https://board.support/agent.svg"
                                }
                            

SBChat.scrollBottom()

Scrolls the chat to the bottom.


Parameters

top
Set it to true to scroll on top. Default: false.

SBChat.isBottom()

Checks if the chat is at bottom.


SBChat.showDashboard()

Displays the dashboard.


SBChat.hideDashboard()

Hides the dashboard.


SBChat.showPanel()

Shows the specified area inside the chat widget.


Parameters

name
The panel name. Available values: articles.

SBChat.hidePanel()

Hides 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()

Updates the red notification counter of the chat button that alerts the user of new messages and new conversations.


Parameters

action
Enter 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()

Updates 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()

Manages 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:

  • check - Check if the user with the given ID is typing and update the chat header.
  • set - Assign the typing status to the user with the given ID and update the chat header.
  • start - Display the typing status in the chat header.
  • stop - Hide the typing status from the chat header.

Information

  • The typing label is visible only when a conversation is open.

SBChat.showArticles()

Displays 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://board.support",
                                        "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://board.support"
                                }
                            

Information

  • Each article of the list contains only an excerpt of the content.

SBChat.searchArticles()

Displays 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()

Sets the rating of an article.


Parameters

article_id
The article ID.
rating
The rating to add. Enter 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()

Selects a category of the emoji box.


Parameters

category
The category name. Available values: Smileys, People, Animals, Food, Travel, Activities, Objects, Symbols.

SBChat.searchEmoji()

Searches for emojis that match the search terms and shows them in the emoji box.


Parameters

search
The search text.

SBChat.insertText()

Inserts 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()

Displays the privacy message and forces the user to accept the terms before starting the chat.


Displays a pop-up message or close it.


Parameters

close
Set it to true to close the pop-up. Default: false.
content
Array with the pop-up content. Array syntax: { image: "", title: "", message: "" }. Set it to false to use the content of Settings > Chat > Popup message. Default: false.

Information

  • Requirement. The chat must close.

SBChat.slackMessage()

Sends 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. 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()

Deletes 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()

Displays 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
Enter registration to display the registration form, insert login to display the login form.

SBChat.addUserAndLogin()

Registers 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://board.support/user.svg",
                                        "first_name": "Don",
                                        "last_name": "John",
                                        "email": "hello@example.com",
                                        "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()

Plays 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.


JAVASCRIPT API
Apps

Apps

List of functions of the Support Board 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()

Sends a message to Dialogflow and adds 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.
delay
Bot response delay in milliseconds.
parameters
Array of optional information. Array syntax: { "name": "value", "name": "value", ...}.
audio
URL or path of an audio file for speech recognition. Default: false.

Information

  • Requirement. The Artificial Intelligence 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()

Checks if Dialogflow and Open AI are active or deactivates it.


Parameters

active
Set it to false to disable Dialogflow and OpenAI stop the chatbot. Set it to activate to activate the chatbot. Default: true.
check_dialogflow
To verify only the activation of Open AI, switch it to false. Default: true.
check_open_ai
To verify only the activation of Dialogflow, switch it to false. Default: true.

Response

Return true if the Dialogflow bot is active, otherwise, return false.


SBApps.dialogflow.welcome()

Triggers the Dialogflow welcome Intent and displays the Dialogflow welcome message.


Information

  • Requirement. The Artificial Intelligence app is required and Dialogflow must be active in the Settings area.

SBApps.dialogflow.openAI()

Sends a message to OpenAI (ChatGPT), returns 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) { ... }.
audio
URL or path of an audio file for speech recognition. Default: false.

Information

  • Requirement. The Artificial Intelligence app is required and Settings > Artificial Intelligence > OpenAI > Chatbot 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 > Artificial Intelligence > Human takeover.


SBApps.dialogflow.humanTakeoverActive()

Checks if human takeover is active for the active conversation.


SBApps.dialogflow.translate()

Translates 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()

Updates 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()

Displays 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.

JAVASCRIPT API
Tickets

Tickets

List of functions of the Tickets App.


SBTickets.showPanel()

Displays 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()

Displays or hide the side panels.


Parameters

show
Set it to false to hide the panels.

SBTickets.setAgent()

Gets the agent details and populates the agent profile area of the right panel.


Parameters

agent_id
The ID of the agent.

SBTickets.activateConversation()

Activates and displays a conversation.


Parameters

conversation
The conversation to activate as a SBConversation object.

SBTickets.selectConversation()

Sets 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.

JAVASCRIPT API
Pusher

Pusher

List of functions for Pusher. More details at pusher.com.


SBPusher.init()

Initializes Pusher and optionally executes a function on initialization completed.


Parameters

onSuccess
Function to execute when the function completes. Syntax: function(response) { ... }.

SBPusher.start()

Starts Pusher and the Push notifications. Run this function after SBPusher.init() and after the user is active.


SBPusher.subscribe()

Subscribes 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()

Subscribes the active user to an event of a Pusher channel and executes 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()

Triggers 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()

Subscribes 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()

Unsubscribes the active user from the presence channel.


SBPusher.pushNotification()

Sends 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.

JAVASCRIPT API
More functions

More functions

List of various functions that perform different tasks.


SBF.translate()

Translates 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, returns false if the active user is not found.


Active user JSON representation

                                {
                                    "details": {
                                        "id": "914",
                                        "profile_image": "https://board.support/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()

Activates 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://board.support/user.svg",
                                    "first_name": "Don",
                                    "last_name": "John",
                                    "email": "hello@example.com",
                                    "user_type": "user",
                                    "token": "bc308e274473fb685a729abe8a4bf82d3c49cd2f"
                                }
                            

Information

  • For the user' methods and more details see the SBUser documentation.

SBF.cors()

Executes 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()

Checks 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()

Hides all the pop-ups and the windows. This function is used mostly in the admin area.


SBF.getURL()

Searches 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()

Converts a JSON encoded string into a normal text.


Parameters

value
The string to convert.

SBF.stringToSlug()

Converts 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()

Converts 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()

Checks 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()

Triggers the custom JavaScript error of Support Board.


Parameters

message
String with the error message or a Error object.

SBF.errorValidation()

Checks if a response from an AJAX call is a validation error.


Parameters

response
The response from the AJAX call.

SBF.login()

Logins a user or an agent. The login can be completed in two ways: via email and password, or via user ID and token.


Parameters

email
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://board.support/user.svg",
                                        "first_name": "Don",
                                        "last_name": "John",
                                        "email": "support@board.support",
                                        "user_type": "user",
                                        "token": "9b25351047ee758aa97ee4868d130cc1ceb8decf"
                                    },
                                    "YXNkWGNSeTdtRTdDYVkxVG8wckN4YWF6V2s0Tk1mczBSVHdQbHBpOWdmejVUTTdOUUxEUENhdUVoYmROWn..."
                                ]
                            

Returns false if login is unsuccessful.


SBF.logout()

Logouts the logged-in user and reload the page.


SBF.loginCookie()

Creates or updates the login cookie.


Parameters

value
The encrypted login string.

SBF.reset()

Logouts the logged-in user, removes all Support Board stored data, and reloads the page.


Displays 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()

Manages the local storage of Support Board. 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()

Saves 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, returntrue 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.


SBF.setting()

Returns the value of a setting, or assign a value to it.


Parameters

key
The setting name
value
The setting value. Default: -1.

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,
                                    "dialogflow-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()

Converts a shortcode into an array containing the shortcode name and the shortcode settings.


Parameters

shortcode
The shortcode string, e.g. [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()

Opens 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()

Includes 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()

Executes the given function only once per given millisecon, 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()

Translates a string using the Support Board translations.


Parameters

string
The string to translate.

SBF.escape()

Escapes a string.


Parameters

string
The string to escape.

SBF.convertUTCDateToLocalDate()

Converts 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, e.g. { "timezone" : "", "country" : "", "city" : "" }. This function accepts the extra method of any SBUser object, e.g. 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()

Converts 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. E.g. 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()

Converts a date format to the date format of the database and sets the UTC to +0.


Parameters

date
Date and time in the following format: YYYY-MM-DD HH:MM:SS. E.g. 2020-05-13 13:35:59. You can remove the time and leave only the date. Enter 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()

Gets 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

JAVASCRIPT API
Events

Events

Events lets you intercept Support Board 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) {
                                    // 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 Support Board 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.
conversation_source
The conversation source. Available sources: em (Email), tk (Ticket), wa (WhatsApp), fb (Facebook Messenger), ig (Instagram), tw (Twitter), wc (WeChat), tx (Text message), gb (Google Business Messages), ln (LINE), vb (Viber).

SBBotMessage

Event fired when the chatbot replies 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

messages
Array of SBMessage objects.
conversation_id
The conversation ID linked to the messages.

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.

SBPopulateConversations

Event fired after all the user conversations has been fetched.


Response

conversations
Array of conversations as SBConversation objects.

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

Returns 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

Returns true if the user or agent is typing, otherwise returns 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.

SBRichMessageShown

Event fired when an asynchronously loaded Rich Message is displayed.


Response

name
The name of the Rich Message.
settings
The Rich Message settings.
response
The HTML code of the Rich Message.

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.
email
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.
email
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 Support Board 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 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 text message.
response
The Twilio response.

SBOpenAIMessage

Event fired when OpenAI(ChatGPT) returns a response.


Response

response
The OpenAI response.
message
The text message.
response
The Twilio response.

MISCELLANEOUS
AJAX

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) => {
                                   // 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
upload-path
  • Admin function. The active user must be an admin.
More details
update-bot
  • Admin function. The active user must be an admin.
More details
get-last-message
  • Admin function. The active user must be an admin.
More details
delete-attachments
  • Admin function. The active user must be an admin.
More details
execute-bot-message
  • If the active user is a user the function works only with the conversations of the active user. If the active user is an agent or admin the function works for any conversation.
More details
logs
  • Admin function. The active user must be an agent or admin.
More details
newsletter
  • Admin function. The active user must be an agent or admin.
More details
get-last-agent-in-conversation
  • Admin function. The active user must be an agent or admin.
More details
messaging-platforms-send-message
  • Admin function. The active user must be an agent or admin.
More details
aws-s3
  • If the active user is a user the function works only with the active user ID. If the active user is an agent or admin the function works for any user.
More details
is-allowed-extension
  • If the active user is a user the function works only with the active user ID. If the active user is an agent or admin the function works for any user.
More details
translate-string
  • If the active user is a user the function works only with the active user ID. If the active user is an agent or admin the function works for any user.
More details
saved-replies
More details
get-settings
  • Admin function. The active user must be an admin.
More details
save-settings
  • Admin function. The active user must be an admin.
More details
get-multi-setting
  • Admin function. The active user must be an admin.
More details
save-external-setting
  • Admin function. The active user must be an admin.
More details
get-external-setting
  • Admin function. The active user must be an admin.
More details
export-settings
  • Admin function. The active user must be an admin.
More details
import-settings
  • Admin function. The active user must be an admin.
More details
is-online
  • Admin function. The active user must be an agent or an admin.
More details
add-user
  • The main user details attributes must be inserted into the attribute settings as an array, the attributes extra becomes extra_settings. Each attribute value must be enclosed in an array. Example:
    SBF.ajax({ function: "update-user", user_id: SBF.activeUser().id, settings: { first_name: ["Jack"], email: ["example@email.com"] }, settings_extra: { phone: ["+123456789"] }});
  • Admin function. The active user must be an admin.
More details
add-user-and-login
More details
get-user
  • If the active user is a user the function works only with the active user ID. If the active user is an agent or admin the function works for any user.
More details
get-user-by
  • Admin function. The active user must be an admin.
More details
get-users
  • Admin function. The active user must be an agent or an admin.
More details
get-new-users
  • Admin function. The active user must be an agent or admin.
More details
get-user-extra
  • If the active user is a user the function works only for the active user. If the active user is an agent or admin the function works for any user.
More details
get-user-language
  • Admin function. The active user must be an agent or admin.
More details
get-online-users
  • Admin function. The active user must be an agent or admin.
More details
get-user-from-conversation
  • Admin function. The active user must be an agent or admin.
More details
agents-online
More details
search-users
  • Admin function. The active user must be an agent or admin.
More details
delete-user
  • Admin function. The active user must be an admin.
More details
delete-users
  • Admin function. The active user must be an admin.
More details
update-user
  • The main user details attributes must be inserted into the attribute settings as an array, the attributes extra becomes extra_settings. Each attribute value must be enclosed in an array. Example:
    SBF.ajax({ function: "update-user", user_id: SBF.activeUser().id, settings: { first_name: ["Jack"], email: ["example@email.com"] }, settings_extra: { phone: ["+123456789"] }});
  • If the active user is a user the function works only with the active user ID. If the active user is an agent or admin the function works for any user.
More details
update-user-to-lead
  • If the active user is a user the function works only with the active user ID. If the active user is an agent or admin the function works for any user.
More details
count-users
  • Admin function. The active user must be an agent or admin.
More details
get-conversations
  • Admin function. The active user must be an agent or admin.
  • Include the argument routing with value true if the queue or routing is active in Settings > Miscellaneous. Include it as the last argument. Default: false.
More details
get-new-conversations
  • Admin function. The active user must be an agent or admin.
  • Include the argument queue with value true if the queue or routing is active in Settings > Miscellaneous. Include it as the last argument. Default: false.
More details
get-conversation
  • If the active user is a user the function works only for the active user conversations. If the active user is an agent or admin the function works for the conversations of any user.
More details
get-user-conversations
  • If the active user is a user the function works only for the active user. If the active user is an agent or admin the function works for any user.
More details
get-new-user-conversations
  • If the active user is a user the function works only for the active user. If the active user is an agent or admin the function works for any user.
More details
search-conversations
  • Admin function. The active user must be an agent or admin.
More details
search-user-conversations
  • If the active user is a user the function works only for the active user. If the active user is an agent or admin the function works for any user.
  • The argument user_id is not required. Default: active user ID.
More details
new-conversation
  • If the active user is a user the function works only for the active user. If the active user is an agent or admin the function works for any user.
More details
update-conversation-status
More details
update-conversation-department
  • If the active user is a user the function works only for the conversations of the active user. If the active user is an agent or admin the function works for any conversation.
More details
update-conversation-agent
  • If the active user is a user the function works only for the conversations of the active user. If the active user is an agent or admin the function works for any conversation.
More details
get-new-messages
  • If the active user is a user the function works only for the active user. If the active user is an agent or admin the function works for any user.
More details
send-message
  • If the active user is a user the function works only for the active user. If the active user is an agent or admin the function works for any user.
More details
send-email
  • If the active user is a user the email can be sent only to agents or admins. If the active user is an agent or an admin the email can be sent to any user.
More details
send-slack-message
  • If the active user is a user the function works only for the active user. If the active user is an agent or an admin the function works for any user.
More details
update-message
  • If the active user is a user the function works only for the active user messages. If the active user is an agent or an admin the function works for any user message.
More details
update-messages-status
  • If the active user is a user the function works only for the active user messages. If the active user is an agent or an admin the function works for any user message.
More details
delete-message
  • If the active user is a user the function works only for the active user messages. If the active user is an agent or an admin the function works for any user message.
More details
slack-users
  • Admin function. The active user must be an agent or admin.
More details
archive-slack-channels
  • Admin function. The active user must be an agent or admin.
More details
slack-channels
  • Admin function. The active user must be an admin.
More details
current-url
More details
set-rating
  • If the active user is a user the function works only for the conversations of the active user. If the active user is an agent or admin the function works for the conversations of any user.
More details
get-rating
  • Admin function. The active user must be an agent or admin.
More details
get-articles
More details
save-articles
  • Admin function. The active user must be an agent or admin.
More details
search-articles
More details
get-articles-categories
  • Admin function. The active user must be an admin.
More details
save-articles-categories
  • Admin function. The active user must be an admin.
More details
article-ratings
More details
get-versions
More details
update
  • Admin function. The active user must be an agent or admin.
More details
app-get-key
  • Admin function. The active user must be an admin.
More details
app-activation
  • Admin function. The active user must be an admin.
More details
csv-users
  • Admin function. The active user must be an admin or an agent.
More details
transcript
  • If the active user is a user the function works only for the conversations of the active user. If the active user is an agent or an admin the function works for the conversations of any user.
More details
is-agent-typing
  • Admin function. The active user must be an admin or an agent.
More details
dialogflow-message
  • The function works only for the active user.
More details
dialogflow-get-intents
  • Admin function. The active user must be an admin.
More details
dialogflow-create-intent
  • Admin function. The active user must be an admin.
More details
dialogflow-update-intent
  • Admin function. The active user must be an admin.
More details
dialogflow-entity
  • Admin function. The active user must be an admin.
More details
dialogflow-get-entity
  • Admin function. The active user must be an admin or agent.
More details
dialogflow-get-token
More details
dialogflow-get-agent
  • Admin function. The active user must be an admin or agent.
More details
dialogflow-set-active-context
  • If the active user is a user the function works only for the active user. If the active user is an agent or admin the function works for any user.
More details
dialogflow-curl
  • Admin function. The active user must be an admin.
More details
dialogflow-human-takeover
  • If the active user is a user the function works only for the active user. If the active user is an agent or admin the function works for any user.
More details
dialogflow-smart-reply
  • Admin function. The active user must be an admin or agent.
More details
cron-jobs
More details
woocommerce-get-customer
  • Admin function. The active user must be an admin or agent.
More details
woocommerce-get-user-orders
  • Admin function. The active user must be an admin or agent.
More details
woocommerce-get-order
  • Admin function. The active user must be an admin or agent.
More details
woocommerce-get-product
  • Admin function. The active user must be an admin or agent.
More details
woocommerce-get-products
  • Admin function. The active user must be an admin or agent.
More details
woocommerce-search-products
  • Admin function. The active user must be an admin or agent.
More details
woocommerce-get-taxonomies
  • Admin function. The active user must be an admin.
More details
woocommerce-get-attributes
  • Admin function. The active user must be an admin.
More details
woocommerce-get-product-id-by-name
  • Admin function. The active user must be an admin or agent.
More details
woocommerce-get-product-images
  • Admin function. The active user must be an admin or agent.
More details
woocommerce-get-product-taxonomies
  • Admin function. The active user must be an admin or agent.
More details
woocommerce-get-attribute-by-term
  • Admin function. The active user must be an admin or agent.
More details
woocommerce-get-attribute-by-name
  • Admin function. The active user must be an admin or agent.
More details
woocommerce-is-in-stock
  • Admin function. The active user must be an admin or agent.
More details
woocommerce-coupon
  • Admin function. The active user must be an admin or agent.
More details
woocommerce-coupon-check
  • Admin function. The active user must be an admin or agent.
More details
woocommerce-coupon-delete-expired
  • Admin function. The active user must be an admin or agent.
More details
woocommerce-get-url
  • Admin function. The active user must be an admin or agent.
More details
woocommerce-get-session
  • Admin function. The active user must be an admin.
More details
woocommerce-get-session-key
  • Admin function. The active user must be an admin or agent.
More details
woocommerce-payment-methods
  • Admin function. The active user must be an admin or agent.
More details
woocommerce-shipping-locations
  • Admin function. The active user must be an admin or agent.
More details
chat-css
More details
get-avatar
  • If the active user is a user the function works only for the active user. If the active user is an agent or admin the function works for any user.
More details
get-agents-ids
  • Admin function. The active user must be an admin or agent.
More details
get-users-with-details
  • Admin function. The active user must be an admin or agent.
More details
send-custom-email
  • Admin function. The active user must be an admin or agent.
More details
send-sms
  • If the active user is a user the function works only for the active user. If the active user is an agent or admin the function works for any user.
More details
email-piping
More details
get-notes
  • Admin function. The active user must be an admin or agent.
More details
add-note
  • Admin function. The active user must be an admin or agent.
More details
delete-note
  • Admin function. The active user must be an admin or agent.
More details
automations-get
More details
automations-save
  • Admin function. The active user must be an admin.
More details
automations-validate
More details
automations-run-all
More details
automations-run
More details
automations-is-sent
  • Admin function. The active user must be an agent or admin.
More details
get-agents-in-conversation
  • If the active user is a user the function works only for conversations of the active user. If the active user is an agent or admin the function works for any conversation.
More details
get-departments
More details
login
More details
logout
More details
update-login
  • If the active user is a user the function works only for conversations of the active user. If the active user is an agent or admin the function works for any conversation.
More details
is-typing
More details
set-typing
More details
clean-data
  • Admin function. The active user must be an admin or agent.
More details
get-translation
More details
get-translations
More details
save-translations
  • Admin function. The active user must be an agent or admin.
More details
delete-leads
  • Admin function. This is an admin function and it works only if the active user is an admin.
More details
reports
  • Admin function. This is an admin function and it works only if the active user is an admin.
More details
reports-update
  • Admin function. This is an admin function and it works only if the active user is an admin.
More details
direct-message
  • Admin function. The active user must be an agent or admin.
More details
count-conversations
  • Admin function. The active user must be an agent or admin.
More details
updates-available
  • Admin function. The active user must be an admin.
More details
google-translate
  • Admin function. The active user must be an admin or an agent.
More details
google-language-detection-update-user
  • If the active user is a user the function works only for conversations of the active user. If the active user is an agent or admin the function works for any conversation.
More details
check-conversations-assignment
  • Admin function. The active user must be an admin or an agent.
More details

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 admin the function works for any user and any message.

Parameters

function
Enter 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. 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, e.g. {"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@example.com"
                                        },
                                        {
                                            "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
                            

get-agent-department

Returns the department of the active agent or admin.


Response

Returns the department ID if set, otherwise, returns false.