loader

Getting started

Setup and usage

The JavaScript API supplies a collection of functions and events that underpin the majority of SmartAi Support 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 this documentation’s code snippets, functions, and methods 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

The JavaScript objects used by SmartAi support are listed below. Sometimes, 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

idReturns the user ID.
typeReturns the user type. Available values: visitor, lead, user, agent, admin.
nameReturns the full name of the user: first name and last name.
nameBeautifiedReturns the full name of the user if available, otherwise returns the default visitor name.
imageReturns 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 additional user details list is empty, but it’s set.
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

detailsArray with the user details.
extraArray with the additional user details.
conversationsArray with the user conversations. Each conversation contains only the last message.

SBMessage

Represents a message of a conversation.

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://smartai.support/bot.svg", "user_type": "bot" }

Methods

idReturns the message ID.
attachmentsReturns the attachments array.
messageReturns 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 translated 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

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://smartai.support/user.jpg", title: "", user_id: "897", user_type: "lead" }

Methods

idReturns 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(text_only)Returns the HTML code, or the formatted text, 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: useragentsbot. 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://smartai.support/image.jpg", "jpg", "5132"], ["file.txt", "https://smartai.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

detailsArray with the conversation details.

Getting started

Variables

The variables in the list below are publicly accessible via JavaScript.

SB_ARTICLES_PAGESet it to true to show the articles page instead of the chat.
SB_LOCAL_SETTINGSOverwrites 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_DISABLEDSet it to true and insert it into a page to prevent the chat or the tickets area from loading.
SB_REGISTRATION_REQUIREDSet it to true and insert it into a page to disable the mandatory registration, set it to false to disable the registration.
SB_TICKETSSet 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_USERSets 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_DEPARTMENTAssign 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_AGENTAssign 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.initializedReturns true if the chat is initialized, otherwise returns false.
SBChat.conversationReturns the active conversation. The value is false if there isn’t any active conversation.
SBChat.is_busyReturns 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_openReturns true if the chat is open, otherwise returns false.
SBChat.agent_idReturns the ID of the active agent in the active conversation. The value is -1 if there isn’t any active agent.
SBChat.agent_onlineReturns true if the active agent is online, otherwise returns false.
SBChat.user_onlineReturns true if the user is online, otherwise returns false.
SBChat.timetableReturns true if the current time is within the office hours, otherwise returns false.
SBChat.dashboardReturns true if the dashboard is active and visible, otherwise returns false.

JAVASCRIPT API

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_idThe 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).
messageThe message text.
attachmentsArray 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: [].
onSuccessFunction to execute when the function completes. Syntax: function(response) { ... }. The response is the same of the SBMessageSent event. Default: false.
payloadAssociative array containing extra data, e.g. { "event": "delete-message" }.
conversation_status_codeThe 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_idThe message ID.
messageThe 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

messageThe message text.
attachmentsArray 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_userSet 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.
onSuccessFunction 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

messageThe 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  RequiredThe title of the notification.
message  RequiredThe message text.
icon  RequiredThe icon of the notification.
conversation_idThe 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

openSet it to false to close the chat. Default: true.

SBChat.openConversation()

Opens a conversation and displays it in the chat window.

Parameters

conversation_id  RequiredThe 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

onSuccessFunction 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_codeThe 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_idThe ID of the user linked to the new conversation. Default: -1 (active user ID).
messageThe message text.
attachmentsArray 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.
departmentThe ID of a department. You can get the IDs from Settings > Miscellaneous > Departments. Default: NULL.
agent_idThe ID of the agent assigned to the conversation. Default: NULL.
onSuccessFunction 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

conversationThe 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  RequiredSet 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

botSet it to false to exclude the bot. Default: true.

Response

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

SBChat.scrollBottom()

Scrolls the chat to the bottom.

Parameters

topSet 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

nameThe 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

conversation_id  RequiredThe 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.
message_idThe ID of the unread message, set it to increase the counter by 1. Set it to false to decrease the counter by 1. Default: false.

SBChat.setConversationStatus()

Updates the status code of a conversation.

Parameters

status_code  RequiredThe 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_idThe 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.
actionAvailable 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

idThe 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

idThe ID of an article to show. Add multiple IDs separated by commas. Use the function SBChat.getArticles() to get the articles list. Default: false.
onSuccessFunction to execute when the function completes. Syntax: function(response) { ... }. Default: false.
categoryReturn only the articles of the given category ID. If set to true return also the categories list. Default: true.
countThe 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://smartai.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://smartai.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  RequiredString with the search terms. The search function supports the title and the content.
button  RequiredThe search button object.
target  RequiredThe 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 RequiredThe article ID.
rating  RequiredThe rating to add. Enter 1 for a positive rating or 0 for a negative one.
onSuccessFunction to execute when the function completes. Syntax: function(response) { … }. Default: false.

SBChat.categoryEmoji()

Selects a category of the emoji box.

Parameters

category    RequiredThe 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    RequiredThe search text.

SBChat.insertText()

Inserts a string in the chat editor.

Parameters

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


SBChat.popup()

Displays a pop-up message or close it.

Parameters

closeSet it to true to close the pop-up. Default: false.
contentArray 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 RequiredThe 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 RequiredThe 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 RequiredThe 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 RequiredThe message text.
attachmentsArray 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 RequiredThe 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

checkSet it to true to check if the registration is required. Default: false.
typeEnter 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

onSuccessFunction to execute when the function completes. Syntax: function(response) { ... }. Default: false.

Response

[
    {
        "id": "913",
        "profile_image": "https://smartai.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: idcolorimagename.

Parameters

department_idThe ID of the department. If this parameter is not setted or null, the function returns the code of all departments.
onSuccess RequiredFunction 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_statusSet 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

repeatSet 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

List of functions of the Support Board apps.


SBApps.is()

Checks if an app is available.

Parameters

name RequiredThe app name, e.g. dialogflow.

SBApps.wordpress.ajax()

Makes a WordPress AJAX call.

Parameters

action RequiredThe action. Available values: wp-login, wp-registration, button-purchase. Other values may be available, check main.js file for all values.
data RequiredThe action parameters, check main.js file for more details.
onSuccessFunction 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

messageThe message text.
attachmentsArray 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.
delayBot response delay in milliseconds.
parametersArray of optional information. Array syntax: { "name": "value", "name": "value", ...}.
audioURL 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

activeSet it to false to disable Dialogflow and OpenAI stop the chatbot. Set it to activate to activate the chatbot. Default: true.
check_dialogflowTo verify only the activation of Open AI, switch it to false. Default: true.
check_open_aiTo 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 RequiredThe message.
onSuccessFunction to execute when the function completes. Syntax: function(response) { ... }.
audioURL 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 RequiredArray of the strings to translate, e.g. [“Hello world”, “How are you?”].
language_code RequiredThe two-letter language code of the language you want to translate into. For Traditional Chinese use zt, for Simplified Chinese use zh, for Brazilian Portuguese use pt.
onSuccess RequiredFunction to execute when the function completes. Syntax: function(response) { ... }.

SBApps.woocommerce.updateCart()

Updates the cart of the active user.

Parameters

actionAvailable actions: cart-addcart-remove
product_idThe product ID to add or remove.

SBApps.woocommerce.waitingList()

Displays the waiting list message.

Parameters

actionSet it to request. The other actions are used internally by the script.
product_idThe ID of the product to add to the waiting list.

JAVASCRIPT API

Tickets

List of functions of the Tickets App.


SBTickets.showPanel()

Displays a panel or the conversation area.

Parameters

nameThe 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.
titleThe title to display as the panel name.

SBTickets.showSidePanels()

Displays or hide the side panels.

Parameters

showSet 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_idThe ID of the agent.

SBTickets.activateConversation()

Activates and displays a conversation.

Parameters

conversationThe 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_idThe ID of the conversation.

SBTickets.getActiveConversation()

Returns the HTML DOM object of the active conversation.

Parameters

typeSet it to ID to get only the ID of the conversation.

JAVASCRIPT API

Pusher

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


SBPusher.init()

Initializes Pusher and optionally executes a function on initialization completed.

Parameters

onSuccessFunction 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 RequiredThe channel name.
onSuccessFunction 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  RequiredThe event name.
callback  RequiredFunction to execute once the event is received. Syntax: function(response) { ... }.
channelThe 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 event on a Pusher channel.

Parameters

event  RequiredThe event name.
dataArray of values. Syntax: { "name": "value" }.
channelThe 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

indexThe presence channel index. Default: 1.
onSuccessFunction 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  RequiredThe 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

List of various functions that perform different tasks.


SBF.translate()

Translates a string to the active user language.

Parameters

string RequiredThe 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://smartai.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

dbSet it to true to verify that the user exists in the database.
onSuccessFunction to execute when the function completes. Syntax: function(response) { ... }.

Response

{
    "id": "914",
    "profile_image": "https://smartai.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

methodInsert POST or GET. Default: GET.
url  RequiredEnter the full URL of the request.
onSuccess RequiredFunction to execute when the function completes. Syntax: function(response) { … }.

SBF.null()

Checks if an existing variable is null or empty.

Parameters

Variable  RequiredThe 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

nameThe 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.
urlThe URL from which extract the parameters. Default: current URL.

SBF.restoreJson()

Converts a JSON encoded string into a normal text.

Parameters

value  RequiredThe 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 RequiredThe 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  RequiredThe 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 agentadmin, or bot.

Parameters

user_type RequiredThe user type string to check.

SBF.error()

Triggers the custom JavaScript error of SmartAi support.

Parameters

message RequiredString with the error message or a Error object.

SBF.errorValidation()

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

Parameters

response RequiredThe 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

emailThe email of the user to login. If this attribute is set you need to set also the password. Default: empty string.
passwordThe password of the user to login. If this attribute is set you need to set also the email. Default: empty string.
user_idThe ID of the user to login. If this attribute is set you need to set also the token. Default: empty string.
tokenThe 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.
onSuccessFunction to execute when the function completes. Syntax: function(response) { ... }. Default: false.

Response

[
    {
        "id": "913",
        "profile_image": "https://smartai.support/user.svg",
        "first_name": "Don",
        "last_name": "John",
        "email": "support@smartai.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

valueThe encrypted login string.

SBF.reset()

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


SBF.lightbox()

Displays the given content in a lightbox.

Parameters

contentThe 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 RequiredThe ID of the value to set or retrieve.
valueThe 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  RequiredThe key to save or check.
hoursThe 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.


SBF.setting()

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

Parameters

key RequiredThe setting name
valueThe 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 RequiredThe 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 RequiredThe link to open.
widthThe window width in px.
heightThe window height in px.

SBF.loadResource()

Includes a .js or .css file in the <head< area of the page.

Parameters

url RequiredThe URL of the file to load.
scriptSet 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 RequiredFunction to execute when the function completes. Syntax: function() { ... }.
idInsert a random, unique string never used by other debounce instances. The strings #1, #2, #3, #4, … are reserved and can’t be used.’
intervalThe 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 RequiredThe string to translate.

SBF.escape()

Escapes a string.

Parameters

string RequiredThe string to escape.

SBF.convertUTCDateToLocalDate()

Converts a date to local time.

Parameters

datetime RequiredThe date and time string. Format: Y/m/d H:i:s.
UTCoffsetAn 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 RequiredArray 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 RequiredFunction 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 RequiredDate 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.
extendedSet it to true to include minutes and seconds. Default: false.
futureSet 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 RequiredDate 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 RequiredThe 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 RequiredThe date and time string.

Response

1675075500000

JAVASCRIPT API

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

messageThe error message.
function_nameThe 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_idThe ID of the user that sent the message.
userThe user object.
conversation_idThe ID of the conversation linked to the message.
conversation_statusThe 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_idThe ID of the message.
messageThe text of the message.
attachmentsThe attachments of the message.
conversation_sourceThe 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

responseThe response array in JSON format from Dialogflow.
messageThe input message of the user.

SBSlackMessageSent

Event fired when a message is sent to Slack.

Response

messageThe text of the message.
conversation_idThe 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_idThe ID of the user that will receive the email.
messageThe message of the email.
attachmentsThe 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

conversation_idThe action value can be add if the counter is increased by 1, or remove it the counter is decreased by 1.
message_idThe ID of the unread message, if set, the counter is increased by 1. If false the counter is decreased by 1.

SBConversationOpen

Event fired when a conversation is fully loaded and it’s opened in the chat.

Response

responseThe conversation as a SBConversation object.

SBNewMessagesReceived

Event fired when there are new messages in the active conversation.

Response

messagesArray of SBMessage objects.
conversation_idThe 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_idThe ID of the conversation.
status_codeThe 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

conversationsArray 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

idThe ID of the article. This value is  -1  if the articles panel is displayed.
articlesIt 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

userArray with the user details.
extraArray with the additional user details.

SBRichMessageShown

Event fired when an asynchronously loaded Rich Message is displayed.

Response

nameThe name of the Rich Message.
settingsThe Rich Message settings.
responseThe HTML code of the Rich Message.

SBRichMessageSubmit

Event fired when the response from a Rich Message is received.

Response

resultThe response of the Rich Message.
dataThe Rich Message details and the data sent by the user.
idThe 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

nameThe full name of the user.
emailThe email of the user.
IDThe 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

nameThe 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.
emailThe 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

actioncart-add or cart-remove.
productThe product name or ID.

SBBotPayload

Event fired when a Dialogflow message contains a Support Board Payload. Payload examples: human-takeoverredirectwoocommerce-update-cartwoocommerce-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_idThe ID of the user that will receive the text message.
messageThe text message.
responseThe Twilio response.

SBActiveUserLoaded

Event fired when a the active user has been loaded.

Response

recipent_idThe ID of the user that will receive the text message.
messageThe text message.
responseThe Twilio response.

SBOpenAIMessage

Event fired when OpenAI(ChatGPT) returns a response.

Response

responseThe OpenAI response.
messageThe text message.
responseThe Twilio response.

MISCELLANEOUS

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 nameRequirementsParameters and response
upload-pathAdmin function. The active user must be an admin.More details
update-botAdmin function. The active user must be an admin.More details
get-last-messageAdmin function. The active user must be an admin.More details
delete-attachmentsAdmin function. The active user must be an admin.More details
execute-bot-messageIf 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
logsAdmin function. The active user must be an agent or admin.More details
newsletterAdmin function. The active user must be an agent or admin.More details
get-last-agent-in-conversationAdmin function. The active user must be an agent or admin.More details
messaging-platforms-send-messageAdmin function. The active user must be an agent or admin.More details
aws-s3If 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-extensionIf 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-stringIf 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-repliesMore details
get-settingsAdmin function. The active user must be an admin.More details
save-settingsAdmin function. The active user must be an admin.More details
get-multi-settingAdmin function. The active user must be an admin.More details
save-external-settingAdmin function. The active user must be an admin.More details
get-external-settingAdmin function. The active user must be an admin.More details
export-settingsAdmin function. The active user must be an admin.More details
import-settingsAdmin function. The active user must be an admin.More details
is-onlineAdmin function. The active user must be an agent or an admin.More details
add-userThe 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-loginMore details
get-userIf 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-byAdmin function. The active user must be an admin.More details
get-usersAdmin function. The active user must be an agent or an admin.More details
get-new-usersAdmin function. The active user must be an agent or admin.More details
get-user-extraIf 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-languageAdmin function. The active user must be an agent or admin.More details
get-online-usersAdmin function. The active user must be an agent or admin.More details
get-user-from-conversationAdmin function. The active user must be an agent or admin.More details
agents-onlineMore details
search-usersAdmin function. The active user must be an agent or admin.More details
delete-userAdmin function. The active user must be an admin.More details
delete-usersAdmin function. The active user must be an admin.More details
update-userThe 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-leadIf 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-usersAdmin function. The active user must be an agent or admin.More details
get-conversationsAdmin 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-conversationsAdmin 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-conversationIf 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-conversationsIf 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-conversationsIf 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-conversationsAdmin function. The active user must be an agent or admin.More details
search-user-conversationsIf 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-conversationIf 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-statusMore details
update-conversation-departmentIf 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-agentIf 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-messagesIf 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-messageIf 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-emailIf 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-messageIf 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-messageIf 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-statusIf 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-messageIf 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-usersAdmin function. The active user must be an agent or admin.More details
archive-slack-channelsAdmin function. The active user must be an agent or admin.More details
slack-channelsAdmin function. The active user must be an admin.More details
current-urlMore details
set-ratingIf 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-ratingAdmin function. The active user must be an agent or admin.More details
get-articlesMore details
save-articlesAdmin function. The active user must be an agent or admin.More details
search-articlesMore details
get-articles-categoriesAdmin function. The active user must be an admin.More details
save-articles-categoriesAdmin function. The active user must be an admin.More details
article-ratingsMore details
get-versionsMore details
updateAdmin function. The active user must be an agent or admin.More details
app-get-keyAdmin function. The active user must be an admin.More details
app-activationAdmin function. The active user must be an admin.More details
csv-usersAdmin function. The active user must be an admin or an agent.More details
transcriptIf 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-typingAdmin function. The active user must be an admin or an agent.More details
dialogflow-messageThe function works only for the active user.More details
dialogflow-get-intentsAdmin function. The active user must be an admin.More details
dialogflow-create-intentAdmin function. The active user must be an admin.More details
dialogflow-update-intentAdmin function. The active user must be an admin.More details
dialogflow-entityAdmin function. The active user must be an admin.More details
dialogflow-get-entityAdmin function. The active user must be an admin or agent.More details
dialogflow-get-tokenMore details
dialogflow-get-agentAdmin function. The active user must be an admin or agent.More details
dialogflow-set-active-contextIf 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-curlAdmin function. The active user must be an admin.More details
dialogflow-human-takeoverIf 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-replyAdmin function. The active user must be an admin or agent.More details
cron-jobsMore details
woocommerce-get-customerAdmin function. The active user must be an admin or agent.More details
woocommerce-get-user-ordersAdmin function. The active user must be an admin or agent.More details
woocommerce-get-orderAdmin function. The active user must be an admin or agent.More details
woocommerce-get-productAdmin function. The active user must be an admin or agent.More details
woocommerce-get-productsAdmin function. The active user must be an admin or agent.More details
woocommerce-search-productsAdmin function. The active user must be an admin or agent.More details
woocommerce-get-taxonomiesAdmin function. The active user must be an admin.More details
woocommerce-get-attributesAdmin function. The active user must be an admin.More details
woocommerce-get-product-id-by-nameAdmin function. The active user must be an admin or agent.More details
woocommerce-get-product-imagesAdmin function. The active user must be an admin or agent.More details
woocommerce-get-product-taxonomiesAdmin function. The active user must be an admin or agent.More details
woocommerce-get-attribute-by-termAdmin function. The active user must be an admin or agent.More details
woocommerce-get-attribute-by-nameAdmin function. The active user must be an admin or agent.More details
woocommerce-is-in-stockAdmin function. The active user must be an admin or agent.More details
woocommerce-couponAdmin function. The active user must be an admin or agent.More details
woocommerce-coupon-checkAdmin function. The active user must be an admin or agent.More details
woocommerce-coupon-delete-expiredAdmin function. The active user must be an admin or agent.More details
woocommerce-get-urlAdmin function. The active user must be an admin or agent.More details
woocommerce-get-sessionAdmin function. The active user must be an admin.More details
woocommerce-get-session-keyAdmin function. The active user must be an admin or agent.More details
woocommerce-payment-methodsAdmin function. The active user must be an admin or agent.More details
woocommerce-shipping-locationsAdmin function. The active user must be an admin or agent.More details
chat-cssMore details
get-avatarIf 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-idsAdmin function. The active user must be an admin or agent.More details
get-users-with-detailsAdmin function. The active user must be an admin or agent.More details
send-custom-emailAdmin function. The active user must be an admin or agent.More details
send-smsIf 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-pipingMore details
get-notesAdmin function. The active user must be an admin or agent.More details
add-noteAdmin function. The active user must be an admin or agent.More details
delete-noteAdmin function. The active user must be an admin or agent.More details
automations-getMore details
automations-saveAdmin function. The active user must be an admin.More details
automations-validateMore details
automations-run-allMore details
automations-runMore details
automations-is-sentAdmin function. The active user must be an agent or admin.More details
get-agents-in-conversationIf 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-departmentsMore details
loginMore details
logoutMore details
update-loginIf 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-typingMore details
set-typingMore details
clean-dataAdmin function. The active user must be an admin or agent.More details
get-translationMore details
get-translationsMore details
save-translationsAdmin function. The active user must be an agent or admin.More details
delete-leadsAdmin function. This is an admin function and it works only if the active user is an admin.More details
reportsAdmin function. This is an admin function and it works only if the active user is an admin.More details
reports-updateAdmin function. This is an admin function and it works only if the active user is an admin.More details
direct-messageAdmin function. The active user must be an agent or admin.More details
count-conversationsAdmin function. The active user must be an agent or admin.More details
updates-availableAdmin function. The active user must be an admin.More details
google-translateAdmin function. The active user must be an admin or an agent.More details
google-language-detection-update-userIf 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-assignmentAdmin 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 RequiredInsert close-message.
bot_id RequiredThe 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 RequiredThe 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 RequiredEnter update-user-and-message.
user_id RequiredThe ID of the user to update.
settingsArray with the user details. Array syntax and values: { first_name: [""], last_name: [""], profile_image: [""], email: [""], user_type: [""] }
settings_extraArray with additional user details. Array syntax: { "ID": ["value", "Name"], "ID": ["value", "Name"], ...}.
message_idThe ID of the message to update.
messageThe message text.
payloadAssociative 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 RequiredThe 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 RequiredThe 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Empowering your journey with seamless, intelligent support from our SmartAI system
Integration
subscribe us
SmartAI Support | Copyright 2024 | All Rights Reserved.