Getting started

Setup and usage

The PHP API supplies a collection of PHP functions that underpin the majority of Support Board functionality. To start using the PHP API follow the steps below.

Usage

Include the file functions.php in your PHP file. The file is located in the include folder of the plugin folder. You're done! You can start using the functions of this documentation.

                                require('include/functions.php');
                            

PHP API

Manage Users

Functions to manage users, agents, and admins.


sb_login()

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


Arguments

email
The email of the user to log in. If this attribute is set you need to set also the password. Default: empty string.
password
The password of the user to log in. If this attribute is set you need to set also the email. Default: empty string.
user_id
The ID of the user to log in. If this attribute is set you need to set also the token. Default: empty string.
token
The token of the user to log in. 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. Default: empty string.

Response

                                [
                                    {
                                        "id": "913",
                                        "profile_image": "https://board.support/user.svg",
                                        "first_name": "User",
                                        "last_name": "#29902",
                                        "email": null,
                                        "user_type": "visitor",
                                        "token": "9b25351047ee758aa97ee4868d130cc1ceb8decf"
                                    },
                                    "YXNkWGNSeTdtRTdDYVkxVG8wckN4YWF6V2s0Tk1mczBSVHdQbHBpOWdmejVUTTdOUUxEUENhdUVoYmROWn..."
                                ]
                            

The last value is the encrypted login data ready to be stored in the Web Storage of the user' browser. Return false if the login is unsuccessful.


sb_logout()

Log out the logged-in user, only on the server-side.


Response

true

This function logout the user only from the server. Use the Javascript API function SBF.storage('login', ''); to log out the user also in the client-side.


sb_get_active_user()

Return the user details of the logged-in user.


Arguments

storage
The long alphanumeric string stored in the Web Storage of the user' browser. Use the Javascript API function SBF.storage('login'); to get it.
db
Set it to true to check if the user exists in the database. Default: false.
login_app
Encrypted array with the email and password of the logged-in WordPress user. This argument is used only in the WordPress version. If set the function will return the logged-in WordPress user. Use this code to generate the array: sb_encryption('encrypt', json_encode(['id' => "", 'email' => "")). Default: false.

Response

                                [
                                    {
                                        "id": "913",
                                        "profile_image": "https://board.support/user.svg",
                                        "first_name": "User",
                                        "last_name": "#29902",
                                        "email": null,
                                        "user_type": "visitor",
                                        "token": "9b25351047ee758aa97ee4868d130cc1ceb8decf"
                                    },
                                    "YXNkWGNSeTdtRTdDYVkxVG8wckN4YWF6V2s0Tk1mczBSVHdQbHBpOWdmejVUTTdOUUxEUENhdUVoYmROWn..."
                                ]
                            

sb_get_user()

Return the user details of the given user ID.


Arguments

user_id
The ID of the user.
extra
Set it to true to get also the extra user details. Default: false.

Response

                                {
                                    "id": "123456",
                                    "first_name": "John",
                                    "last_name": "Doe",
                                    "email": "johon@example.com",
                                    "profile_image": "https://board.support/user.svg",
                                    "user_type": "visitor",
                                    "creation_time": "2020-05-12 14:28:57",
                                    "last_activity": "2020-05-12 14:28:57",
                                    "department": null,
                                    "token": "a521773c5a566a251c3fb00e93162b20ff955b12",
                                    "password": "",
                                    "details": [
                                        {
                                            "slug": "location",
                                            "name": "Location",
                                            "value": "New York, United States"
                                        },
                                        {
                                            "slug": "country_code",
                                            "name": "Country code",
                                            "value": "America/New_York"
                                        }
                                        ...
                                    ]
                                }
                            

sb_get_user_extra()

Return the additional user details of the given user ID.


Arguments

user_id
The ID of the user.

Response

                                [
                                    {
                                        "slug": "browser",
                                        "name": "Browser",
                                        "value": "Chrome"
                                    },
                                    {
                                        "slug": "current_url",
                                        "name": "Current URL",
                                        "value": "https://board.support/"
                                    },
                                    {
                                        "slug": "os",
                                        "name": "OS",
                                        "value": "Windows 10"
                                    },
                                    {
                                        "slug": "phone",
                                        "name": "Phone",
                                        "value": "3203057977"
                                    }
                                    ...
                                ]
                            

sb_get_users()

Return the user details of all the users.


Arguments

sorting
Set the order of the returned values. Insert ["column", "order"] and replace column with one of the following values: first_name, last_name, email, profile_image, user_type, creation_time, last_activity, department. Replace order with ASC or DESC.
user_types
Array in JSON format of user types to include in the returned value. Array syntax: ["", "", "", ...]. Accepted values: visitor, lead, user, agent, admin. Default: all.
search
String with the search terms.
pagination
Integer from 1 to N to limit the results number. Insert 1 to get the first 100 results, 2 for the results from 101 to 200, etc.

Response

                                [
                                    {
                                        "id": "880",
                                        "first_name": "User",
                                        "last_name": "#29938",
                                        "email": null,
                                        "profile_image": "https://board.support/user.svg",
                                        "user_type": "visitor",
                                        "creation_time": "2020-05-13 08:58:18",
                                        "last_activity": "2020-05-13 09:07:39",
                                        "department": null,
                                        "token": "6d969f64f5ed6263714b9b39f3d3700b66f16820"
                                    },
                                    {
                                        "id": "879",
                                        "first_name": "User",
                                        "last_name": "#86773",
                                        "email": null,
                                        "profile_image": "https://board.support/user.svg",
                                        "user_type": "visitor",
                                        "creation_time": "2020-05-13 08:38:41",
                                        "last_activity": "2020-05-13 08:58:12",
                                        "department": null,
                                        "token": "2e5064670707d06b661d04353f4a462ec927f19a"
                                    }
                                    ...
                                ]
                            

sb_get_new_users()

Return the users created after the given date.


Arguments

datetime
Date and time in the following format: YYYY-MM-DD HH:MM:SS. Ex. 2020-05-13 13:35:59. You can remove the time and leave only the date. The dates stored in the database are in UTC+0.

Response

                                [
                                    {
                                        "id": "880",
                                        "first_name": "User",
                                        "last_name": "#29938",
                                        "email": null,
                                        "profile_image": "https://board.support/user.svg",
                                        "user_type": "visitor",
                                        "creation_time": "2020-05-13 08:58:18",
                                        "last_activity": "2020-05-13 09:07:39",
                                        "department": null,
                                        "token": "6d969f64f5ed6263714b9b39f3d3700b66f16820"
                                    },
                                    {
                                        "id": "879",
                                        "first_name": "User",
                                        "last_name": "#86773",
                                        "email": null,
                                        "profile_image": "https://board.support/user.svg",
                                        "user_type": "visitor",
                                        "creation_time": "2020-05-13 08:38:41",
                                        "last_activity": "2020-05-13 08:58:12",
                                        "department": null,
                                        "token": "2e5064670707d06b661d04353f4a462ec927f19a"
                                    }
                                    ...
                                ]
                            

sb_get_online_users()

Return the online users including agents and admins.


Arguments

exclude_id
Array of users IDs in JSON format to exclude from the returned values. Array syntax: [123, 123, 123, ...]

Response

                                [
                                    {
                                        "id": "881",
                                        "first_name": "Don",
                                        "last_name": "John",
                                        "email": null,
                                        "profile_image": "https://board.support/user.svg",
                                        "user_type": "visitor",
                                        "creation_time": "2020-05-13 09:18:59",
                                        "last_activity": "2020-05-13 09:32:34",
                                        "department": null,
                                        "token": "e435a5c67f4276cdb9c6fc19b7c015990ffc3268"
                                    },
                                    {
                                        "id": "880",
                                        "first_name": "User",
                                        "last_name": "#29938",
                                        "email": null,
                                        "profile_image": "https://board.support/user.svg",
                                        "user_type": "visitor",
                                        "creation_time": "2020-05-13 08:58:18",
                                        "last_activity": "2020-05-13 09:32:28",
                                        "department": null,
                                        "token": "6d969f64f5ed6263714b9b39f3d3700b66f16820"
                                    }
                                    ...
                                ]
                            

sb_search_users()

Return the users matching the search.


Arguments

search
String with the search terms. Additional user details are supported too.

Response

                                [
                                    {
                                        "id": "881",
                                        "first_name": "Don",
                                        "last_name": "John",
                                        "email": null,
                                        "profile_image": "https://board.support/user.svg",
                                        "user_type": "visitor",
                                        "creation_time": "2020-05-13 09:18:59",
                                        "last_activity": "2020-05-13 09:32:34",
                                        "department": null,
                                        "token": "e435a5c67f4276cdb9c6fc19b7c015990ffc3268"
                                    },
                                    {
                                        "id": "880",
                                        "first_name": "User",
                                        "last_name": "#29938",
                                        "email": null,
                                        "profile_image": "https://board.support/user.svg",
                                        "user_type": "visitor",
                                        "creation_time": "2020-05-13 08:58:18",
                                        "last_activity": "2020-05-13 09:32:28",
                                        "department": null,
                                        "token": "6d969f64f5ed6263714b9b39f3d3700b66f16820"
                                    }
                                    ...
                                ]
                            

sb_add_user()

Create a new user.


Arguments

settings
Array with the user details. Array keys and syntax: [ "profile_image" => "", "first_name" => "", "last_name" => "", "email" => "", "password" => "", "user_type" => "", "department" => "" ]. Accepted user_type values: visitor, lead, user, agent, admin. Default: visitor if the email is not provided, otherwise, user.
settings_extra
Array of additional user details. Array syntax: ["key" => ["value", "Name"], "key" => ["value", "Name"], ...]. Any detail is accepted. Built-in details (keys): phone, city, language, country, birthday, company, facebook, twitter, linkedin, website, ip, country_code, browser, currency, location, os, time_zone, current_url.
login_app
Encrypted array with the email and password of the logged-in WordPress user. This argument is used only in the WordPress version. If set, the new user will use the user details of the given WordPress user ID. Use this code to generate the array: sb_encryption('encrypt', json_encode(['id' => "", 'email' => "")). Default: false.

Response

                                123456
                            

Responses: ID of the new user on success, otherwise, duplicate-email, invalid-user-type, SQL error message.


sb_add_user_and_login()

Create a new user, log in it, and return the login data for the client-side.


Arguments

This function uses the same arguments of the sb_add_user() function.


Response

This function returns the same response of the sb_login() function.


sb_add_new_user_extra()

Add additional user details to the user of the given ID. Existing user details will not be updated.


Arguments

user_id
The ID of the user to update.
settings
Array of additional user details. Array syntax: ["key" => ["value", "Name"], "key" => ["value", "Name"], ...]. Any detail is accepted. Built-in details (keys): phone, city, language, country, birthday, company, facebook, twitter, linkedin, website, ip, country_code, browser, currency, location, os, time_zone, current_url.

Response

                                true
                            

sb_update_user()

Update the details of an existing user.


Arguments

user_id
Insert the ID of the user to update.
settings
Array with the user details. Array keys and syntax: [ "profile_image" => "", "first_name" => "", "last_name" => "", "email" => "", "password" => "", "user_type" => "", "department" => "" ]. Accepted user_type values: visitor, lead, user, agent, admin. Default: visitor if the email is not provided, otherwise, user.
settings_extra
Array of additional user details. Array syntax: ["key" => ["value", "Name"], "key" => ["value", "Name"], ...]. Any detail is accepted. Built-in details (keys): phone, city, language, country, birthday, company, facebook, twitter, linkedin, website, ip, country_code, browser, currency, location, os, time_zone, current_url.

Response

                                true
                            

Other possible responses: duplicate-email, invalid-user-type, SQL error message.


sb_update_login()

Update the login details of the logged-in user and return the login data for the client-side. Use the Javascript API function SBF.storage('login', response); to update the login details also in the client-side, the response is the response data returned by this function.


Arguments

profile_image
The URL of the profile image of the user.
first_name
The first name of the user.
last_name
The last name of the user.
email
The email of the user.
department
The ID of the department of the user. You can get the IDs from Settings > Miscellaneous > Departments. No department ID validation is performed, so double-check the department ID to be sure it exists.

Response

                                YXNkWGNSeTdtRTdDYVkxVG8wckN4YWF6V2s0Tk1mczBSVHdQbHBpOWdmejVUTTdOUUxEUENhdUVoYmROWn...
                            

sb_delete_user()

Delete a user and all the linked conversations and messages.


Arguments

user_id
The ID of the user to delete.

Response

                                true
                            

sb_delete_users()

Delete multiple users and all the linked conversations and messages.


Arguments

user_ids
Array of IDs of the users to delete. Array syntax: [123, 123, 123, ...]

Response

                                true
                            

sb_delete_leads()

Delete all leads, including all the linked conversations and messages.


Response

                                true
                            

sb_current_url()

Get or set the current URL of the user or the last visited URL.


Arguments

user_id
The ID of the user
url
The URL to set as "Current URL". If this argument is set the function will only set the value and it will not return any URL.

Response

                                https://board.support
                            

Return false if the URL is not found. Return true if the url argument is set.


sb_count_users()

Return the total users' count grouped by user type.


Response

                                {
                                    "all": "335",
                                    "lead": "288",
                                    "user": "15",
                                    "visitor": "28"
                                }
                            

sb_update_user_to_lead()

Change the user type to lead.


Arguments

user_id
The ID of the user.

Response

                                true
                            

sb_slack_users()

Return the agents-slack members' connection information. The Slack App is required.


Response

                                {
                                    "slack_users": [
                                        {
                                            "id": "U328T701Z",
                                            "name": "Support Schio"
                                        },
                                        {
                                            "id": "UR5F0GK7T",
                                            "name": "Robert Pitt"
                                        }
                                        ...
                                    ],
                                    "agents": [
                                        {
                                            "id": "2",
                                            "name": "Alex Smith"
                                        },
                                        {
                                            "id": "445",
                                            "name": "Federico Schiocchet"
                                        },
                                        {
                                            "id": "724",
                                            "name": "Alberto Prade"
                                        }
                                        ...
                                    ],
                                    "saved": {
                                        "U328T701Z": "445",
                                        "UR5F0GK7T": "2"
                                        ...
                                    }
                                }
                            

Response

                                true
                            

sb_is_agent()

Check if the given user type string is an admin, an agent, or the bot.


Arguments

user_type
The user type string.

Response

Return true if the user type string is "admin", "agent", or "bot", otherwise return false.


sb_get_department()

Return the department of the active user. This function is used in the admin area.


Response

Return the department ID if set, otherwise, return false.


sb_password_verify()

Check if the given password matches the given password hash. The password hash is saved in the database in the password column of the sb_users table.


Arguments

password
The password to check.
hash
The password hash.

Response

Return true if the password matches the hash, otherwise, return false.


sb_user_autodata()

Add the following user details to a user: city, location, country, timezone, currency, browser, browser language, os. These details are generated automatically.


Arguments

user_id
The ID of the user.

Response

                                true
                            

sb_is_typing()

Check if a user or an agent is typing a message in a conversation.


Parameters

user_id
The ID of the user, or the agent, to check.
conversation_id
The ID of conversation to check.

Response

Return true if the user is typing, otherwise, return false.


sb_is_agent_typing()

Check if an agent is typing a message in a conversation, and return the agent details.


Parameters

conversation_id
The ID of conversation to check.

Response

                                {
                                  "id": "",
                                  "first_name": "",
                                  "last_name": ""
                                }
                            

Return false if no agents are typing.


sb_set_typing()

Assign the typing status to a user or an agent relative to a conversation.


Parameters

user_id
The ID of the user or the agent.
conversation_id
The ID of conversation.

Response

                                true
                            

sb_is_online()

Check if the given date and time are recognized as online by Support Board.


Arguments

datetime
Date and time in the following format: YYYY-MM-DD HH:MM:SS. Ex. 2020-05-13 13:35:59. You can remove the time and leave only the date.

Response

true if online, false if offline.


sb_get_bot_id()

Return the ID of the bot.


Response

                                123456
                            

PHP API

Manage Conversations

Functions to manage conversations and messages.


sb_get_conversation()

Return a conversation and the messages of the conversation.


Arguments

user_id
The ID of the user linked to the conversation.
conversation_id
The ID of the conversation.

Response

                                {
                                    "messages": [
                                        {
                                            "id": "2044",
                                            "user_id": "802",
                                            "message": "Hello!",
                                            "creation_time": "2020-05-0410:06:30",
                                            "attachments": "",
                                            "status_code": "0",
                                            "payload": "",
                                            "conversation_id": "946",
                                            "first_name": "Don",
                                            "last_name": "John",
                                            "profile_image": "https://board.support/user.svg",
                                            "user_type": "lead"
                                        },
                                        {
                                            "id": "2045",
                                            "user_id": "377",
                                            "message": "Hello,howcanIhelp?",
                                            "creation_time": "2020-05-0410:06:33",
                                            "attachments": "",
                                            "status_code": "0",
                                            "payload": "",
                                            "conversation_id": "946",
                                            "first_name": "Bruce",
                                            "last_name": "Peterson",
                                            "profile_image": "https://board.support/agent.svg",
                                            "user_type": "agent"
                                        }
                                        ...
                                    ],
                                    "details": {
                                        "user_id": "802",
                                        "first_name": "Don",
                                        "last_name": "John",
                                        "profile_image": "https://board.support/user.svg",
                                        "user_type": "lead",
                                        "id": "946",
                                        "title": "",
                                        "conversation_time": "2020-05-0410:06:30",
                                        "conversation_status_code": "3",
                                        "department": null
                                    }
                                }
                            

sb_get_conversations()

Return all the conversations. Each conversation includes the last message of the conversation.


Arguments

pagination
Integer from 1 to N to limit the results number. Insert 1 to get the first 100 results, 2 for the results from 101 to 200, etc.
status_code
The status code of the returned conversations. Default: all the conversations in the inbox, excluding conversations in trash and archive. Status codes: live = 0, waiting answer from user = 1, waiting answer from agent = 2, archive = 3, trash = 4.
routing
Set it to true if the queue or routing is active in Settings > Miscellaneous. Default: false.

Response

                                [
                                    {
                                        "id": "1431",
                                        "user_id": "632",
                                        "message": "Hello!",
                                        "creation_time": "2020-04-24 10:53:35",
                                        "attachments": "",
                                        "status_code": "0",
                                        "payload": "",
                                        "conversation_id": "764",
                                        "message_user_type": "lead",
                                        "first_name": "Don",
                                        "last_name": "John",
                                        "profile_image": "https://board.support/media/user.svg",
                                        "conversation_status_code": "2",
                                        "user_type": "lead"
                                    },
                                    {
                                        "id": "1430",
                                        "user_id": "631",
                                        "message": "Hi! Can you help me?",
                                        "creation_time": "2020-04-24 10:38:37",
                                        "attachments": "",
                                        "status_code": "0",
                                        "payload": "",
                                        "conversation_id": "763",
                                        "message_user_type": "lead",
                                        "first_name": "Jessica",
                                        "last_name": "Brenson",
                                        "profile_image": "https://board.support/media/user.svg",
                                        "conversation_status_code": "2",
                                        "user_type": "lead"
                                    }
                                    ...
                                ]
                            

sb_get_new_conversations()

Return the conversations created after the given date or with a message created after the given date. Each conversation includes the last message of the conversation.


Arguments

datetime
Date and time in the following format: YYYY-MM-DD HH:MM:SS. Ex. 2020-05-13 13:35:59. You can remove the time and leave only the date. The dates stored in the database are in UTC+0.
routing
Set it to true if the queue or routing is active in Settings > Miscellaneous. Default: false.

Response

                                [
                                    {
                                        "id": "1431",
                                        "user_id": "632",
                                        "message": "Hello!",
                                        "creation_time": "2020-04-24 10:53:35",
                                        "attachments": "",
                                        "status_code": "0",
                                        "payload": "",
                                        "conversation_id": "764",
                                        "message_user_type": "lead",
                                        "first_name": "Don",
                                        "last_name": "John",
                                        "profile_image": "https://board.support/media/user.svg",
                                        "conversation_status_code": "2",
                                        "user_type": "lead"
                                    },
                                    {
                                        "id": "1430",
                                        "user_id": "631",
                                        "message": "Hi! Can you help me?",
                                        "creation_time": "2020-04-24 10:38:37",
                                        "attachments": "",
                                        "status_code": "0",
                                        "payload": "",
                                        "conversation_id": "763",
                                        "message_user_type": "lead",
                                        "first_name": "Jessica",
                                        "last_name": "Brenson",
                                        "profile_image": "https://board.support/media/user.svg",
                                        "conversation_status_code": "2",
                                        "user_type": "lead"
                                    }
                                    ...
                                ]
                            

sb_get_user_conversations()

Return the conversations of a user. Each conversation includes the last message of the conversation.


Arguments

user_id
The ID of the user of the conversations to get.

Response

                                [
                                    {
                                        "id": "2266",
                                        "user_id": "377",
                                        "message": "Hello, how are you?",
                                        "creation_time": "2020-05-12 17:30:35",
                                        "attachments": "",
                                        "status_code": "0",
                                        "payload": "",
                                        "conversation_id": "995",
                                        "first_name": "Don",
                                        "last_name": "John",
                                        "profile_image": "https://board.support/media/user.svg",
                                        "user_type": "lead",
                                        "conversation_status_code": "3"
                                    },
                                    {
                                        "id": "2266",
                                        "user_id": "5",
                                        "message": "Please leave a feedback.",
                                        "creation_time": "2020-05-12 17:30:35",
                                        "attachments": "",
                                        "status_code": "0",
                                        "payload": "",
                                        "conversation_id": "995",
                                        "first_name": "Adam",
                                        "last_name": "Gates",
                                        "profile_image": "https://board.support/media/user.svg",
                                        "user_type": "agent",
                                        "conversation_status_code": "3"
                                    }
                                    ...
                                ]
                            

sb_get_new_user_conversations()

Return the user conversations created after the given date or with a message created after the given date. Each conversation includes the last message of the conversation.


Arguments

user_id
The ID of the user of the conversations to get.
datetime
Date and time in the following format: YYYY-MM-DD HH:MM:SS. Ex. 2020-05-13 13:35:59. You can remove the time and leave only the date. The dates stored in the database are in UTC+0.

Response

                                [
                                    {
                                        "id": "2266",
                                        "user_id": "377",
                                        "message": "Hello, how are you?",
                                        "creation_time": "2020-05-12 17:30:35",
                                        "attachments": "",
                                        "status_code": "0",
                                        "payload": "",
                                        "conversation_id": "995",
                                        "first_name": "Don",
                                        "last_name": "John",
                                        "profile_image": "https://board.support/media/user.svg",
                                        "user_type": "lead",
                                        "conversation_status_code": "3"
                                    },
                                    {
                                        "id": "2266",
                                        "user_id": "5",
                                        "message": "Please leave a feedback.",
                                        "creation_time": "2020-05-12 17:30:35",
                                        "attachments": "",
                                        "status_code": "0",
                                        "payload": "",
                                        "conversation_id": "995",
                                        "first_name": "Adam",
                                        "last_name": "Gates",
                                        "profile_image": "https://board.support/media/user.svg",
                                        "user_type": "agent",
                                        "conversation_status_code": "3"
                                    }
                                    ...
                                ]
                            

sb_search_conversations()

Return the conversations matching the search terms.


Arguments

search
String with the search terms. The search function supports attachment names, messages of the conversations, user email, and name of a message of the conversation.
routing
Set it to true if the queue or routing is active in Settings > Miscellaneous. Default: false.

Response

                                [
                                    {
                                      "id": "2130",
                                      "user_id": "806",
                                      "message": "Hello! How can I help you?",
                                      "creation_time": "2020-05-05 15:45:38",
                                      "attachments": "",
                                      "status_code": "0",
                                      "payload": "",
                                      "conversation_id": "952",
                                      "message_user_type": "admin",
                                      "first_name": "User",
                                      "last_name": "#24254",
                                      "profile_image": "https://board.support/media/user.svg",
                                      "conversation_status_code": "4",
                                      "user_type": "lead"
                                    },
                                    {
                                      "id": "2127",
                                      "user_id": "805",
                                      "message": "Hi, I need help!",
                                      "creation_time": "2020-05-05 08:12:57",
                                      "attachments": "",
                                      "status_code": "0",
                                      "payload": "",
                                      "conversation_id": "951",
                                      "message_user_type": "user",
                                      "first_name": "Don",
                                      "last_name": "John",
                                      "profile_image": "https://board.support/media/user.svg",
                                      "conversation_status_code": "0",
                                      "user_type": "user"
                                    }
                                    ...
                                ]
                            

sb_search_user_conversations()

Return the conversations of the active user or given user ID that matches the search terms.


Arguments

search
String with the search terms. The search function supports attachment names, messages of the conversations, and the conversation title.
id
The ID of the user. Default: active user ID

Response

                                [
                                    {
                                        "id": "3362",
                                        "user_id": "2",
                                        "message": "Hello! How can I help you?",
                                        "creation_time": "2020-06-24 17:34:39",
                                        "attachments": "",
                                        "status_code": "0",
                                        "payload": "",
                                        "conversation_id": "1364",
                                        "first_name": "Don",
                                        "last_name": "John",
                                        "profile_image": "https://board.support/media/user.svg",
                                        "user_type": "lead",
                                        "conversation_status_code": "0"
                                    },
                                    {
                                        "id": "3345",
                                        "user_id": "1195",
                                        "message": "Hi, I need help!",
                                        "creation_time": "2020-06-24 17:06:23",
                                        "attachments": "",
                                        "status_code": "0",
                                        "payload": "",
                                        "conversation_id": "1363",
                                        "first_name": "Don",
                                        "last_name": "John",
                                        "profile_image": "https://board.support/media/user.svg",
                                        "user_type": "lead",
                                        "conversation_status_code": "2"
                                    }
                                    ...
                                ]
                            

sb_new_conversation()

Create a new conversation.


Arguments

user_id
The ID of the user linked to the conversation.
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.
title
The title of the conversation. Default: empty.
department
The ID of a department. You can get the IDs from Settings > Miscellaneous > Departments. Default: NULL.

Response

                                {
                                    "messages": [],
                                    "details": {
                                        "user_id": "882",
                                        "first_name": "Don",
                                        "last_name": "John",
                                        "profile_image": "https://board.support/user.svg",
                                        "user_type": "lead",
                                        "id": "1007",
                                        "title": "",
                                        "conversation_time": "2020-05-15 12:51:39",
                                        "conversation_status_code": "0",
                                        "department": null
                                    }
                                }
                            

Other possible responses: Conversation details array on success, otherwise, user-not-found, SQL error message


sb_update_conversation_status()

Update the status code of a conversation.


Arguments

conversation_id
The ID of the conversation.
status_code
The status code of the conversation. Status codes: live = 0, waiting answer from user = 1, waiting answer from agent = 2, archive = 3, trash = 4.

Response

                                true
                            

Return invalid-status-code if the status code is invalid.


sb_update_conversation_department()

Update the department of a conversation and optionally send an email to all the agents in the new department.


Arguments

conversation_id
The ID of the conversation to update.
department
The ID of a department. You can get the IDs from Settings > Miscellaneous > Departments. No department ID validation is performed, so double-check the department ID to be sure it exists.
message
A message to send to the agents. If set, an email with the message will be sent to all the agents to notify the department change.

Response

                                true
                            

sb_set_rating()

Assign a rating to a conversation and optionally update a message of the conversation.


Arguments

settings
Insert the following array: [ "settings" => [ "conversation_id" => "ID", "rating" => "RATING" ] ]. Replace ID with the ID of the conversation to rate, replace rating with 1 for a positive rating, with 0 for a negative rating.
payload
The message payload in JSON format.
message_id
The ID of the message to update.
message
The content of the message.
user_id
The user ID of the conversation linked to the message.

Response

                                true
                            

sb_get_rating()

Get the ratings of the conversations assigned to an agent.


Arguments

user_id
The ID of the agent.

Response

                                [4, 2]
                            

The response array: [count of positive ratings, count of negative ratings]. In the example above there are 4 positive ratings and 2 negative ratings.


sb_get_new_messages()

Return the messages of a conversation created after the given date.


Arguments

user_id
The ID of the user of the conversation.
conversation_id
The ID of the conversation.
datetime
Date and time in the following format: YYYY-MM-DD HH:MM:SS. Ex. 2020-05-13 13:35:59. You can remove the time and leave only the date. The dates stored in the database are in UTC+0.

Response

                                [
                                    {
                                        "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"
                                    },
                                    {
                                        "id": "2320",
                                        "user_id": "877",
                                        "message": "Thank you! I need help.",
                                        "creation_time": "2020-05-12 18:04:51",
                                        "attachments": "",
                                        "status_code": "0",
                                        "payload": "",
                                        "conversation_id": "1004",
                                        "first_name": "Don",
                                        "last_name": "John",
                                        "profile_image": "https://board.support/user.svg",
                                        "user_type": "lead"
                                    }
                                    ...
                                ]
                            

sb_send_message()

Add a new message to an existing conversation.


Arguments

user_id
The ID of the user of the conversation.
conversation_id
The ID of the conversation.
message
The content of the message.
attachments
Array of attachments in JSON format. Array syntax: [["name", "link"], ["name", "link"], ...]. Replace name with the name of the attachment and link with the full URL of the attachment.
conversation_status
The status code of the conversation. Status codes: live = 0, waiting answer from user = 1, waiting answer from agent = 2, archive = 3, trash = 4.
payload
Array in JSON format of additional information. You can insert any value. Array syntax: { "key": value, "key": value, ... }.
queue
Set it to true if the queue is active in Settings > Miscellaneous > Queue. Default: false.

Response

                                {
                                    "status": "success",
                                    "message-id": 123456,
                                    "queue": false
                                }
                            

Other possible responses: invalid-status-code, SQL error message.


sb_send_bot_message()

Send a message to Dialogflow and add the Dialogflow response to an existing conversation as a new message. The Dialogflow App is required and Dialogflow must be active in the settings area.


Arguments

conversation_id
The ID of the conversation.
message
The content of the message.
token
The Dialogflow access token. For performance reasons always include this token. You will get the token after the first call of this function, from the response.
language
The language of the bot. Default: the main bot language.
attachments
Array of attachments in JSON format. Array syntax: [["name", "link"], ["name", "link"], ...]. Replace name with the name of the attachment and link with the full URL of the attachment. Dialogflow can read this array.

Response

                                {
                                    "token": "ya29.a0AfH6SMB5Y04TwKvxeah5pCEtcupfncTOLMlewxlnUAhH5H4HE4SVIeOPWSfxRVfHNcJIoR-IvRTtrEe4P9VXHa",
                                    "messages": [
                                        {
                                            "message": "Hi! How are you doing?",
                                            "attachments": []
                                        }
                                    ],
                                    "response": {
                                        "responseId": "1a5e30d0-d6d4-4f0c-83e3-2fb9e31c2a5e-e15c53b8",
                                        "queryResult": {
                                            "queryText": "Hello",
                                            "action": "input.welcome",
                                            "parameters": [],
                                            "allRequiredParamsPresent": true,
                                            "fulfillmentText": "Hi! How are you doing?",
                                            "fulfillmentMessages": [
                                                {
                                                    "platform": "ACTIONS_ON_GOOGLE",
                                                    "simpleResponses": {"simpleResponses": [ { "textToSpeech": "Example"} ]}
                                                },
                                                {
                                                    "text": { "text": [ "Hi! How are you doing?" ]  }
                                                }
                                            ],
                                            "intent": {
                                                "name": "projects/api-project-655517752147/agent/intents/fe275c2e-f39d-4db3-92c2-e55582ce38fb",
                                                "displayName": "Default Welcome Intent"
                                            },
                                            "intentDetectionConfidence": 1,
                                            "languageCode": "en"
                                        },
                                        "alternativeQueryResults": [
                                            {
                                                "queryText": "Hello",
                                                "languageCode": "en"
                                            }
                                        ]
                                    }
                                }
                            

Other possible responses: dialogflow-not-active, SQL, or cURL error message.


sb_send_slack_message()

Send a message to Slack. The Slack App is required and Slack must be active in the settings area.


Arguments

user_id
The ID of the user linked to the message.
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 URL of 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. Default:
message
The string containing the message.
attachments
Array of attachments in JSON format. Array syntax: [["name", "link"], ["name", "link"], ...]. Replace name with the name of the attachment and link with the full URL of the attachment.
channel
The Slack channel linked to the message. For performance reasons always include the channel. You will get the channel after the first call of this function, from the response (example: C011JFFGSKY).

Response

                                ["success", "C011JFFGSKY"]
                            

Other possible responses: slack-not-active, SQL, or cURL error message.


sb_update_message()

Update an existing message.


Arguments

user_id
The ID of the user of the message.
message_id
The ID of the message.
message
The content of the message.
attachments
Array of attachments in JSON format. Array syntax: [["name", "link"], ["name", "link"], ...]. Replace name with the name of the attachment and link with the full URL of the attachment.
payload
Array in JSON format of additional information. You can insert any value. Array syntax: { "key": value, "key": value, ... }.

Response

                                true
                            

sb_delete_message()

Delete an existing message.


Arguments

user_id
The ID of the user of the conversation linked to the message.
message_id
The ID of the message to delete.

Response

                                true
                            

sb_close_message()

Send the close message to a user conversation. The close message' contents can be set in the Settings > Chat > Close message area.


Arguments

bot_id
The ID of the sender user. Usually the bot ID. You can get the bot ID with the function sb_get_bot_id();
conversation_id
The ID of the conversation to send the message to.

Response

                                {
                                    "status": "success",
                                    "message-id": 123456
                                }
                            

PHP API

Database

Functions to read data from the database and to save data in it.


sb_db_get()

Return the data of a SQL query.


Arguments

query
The SQL query.
single
Set it to false if the query should return multiple results. Default: true.

Response

The result of the query as a single value or as an array of values. Return SBError if the query is invalid.


sb_db_query()

Execute a SQL query to update the data in the database.


Arguments

query
The SQL query.
return
Set it to true if the query should return a value. Default: false.

Response

Return true, the return value, or SBError if the query is invalid.


sb_db_escape()

Escapes special characters in a string for use it in an SQL query. Use this function to escape every variable used in a SQL query containing strings without a known value.


Arguments

value
The string to escape.

Response

Return the escaped string.


sb_db_json_enconde()

Convert an array to JSON and escape the values for use them in an SQL query. Use this function to convert every variable containing arrays that is used in a SQL query.


Arguments

array
The array to convert and escape.

Response

Return the converted array.


sb_db_check_connection()

Check if the database connection is valid or check if the details provided are valid. All arguments are optional. If an argument is not provided will be used the one provided during the installation.


Arguments

name
The database name.
user
The database username.
password
The database password.
host
The database host.
name
The database port.

Response

Return true if the connection is valid, otherwise, return the connection error message.


PHP API

Language and Translations

Functions to translate strings in other languages and to manage the translations.


sb_()

Translate a string to the active user language. Use the function sb_e($string) to translate and echo the string.


Arguments

string
The string to translate.

Response

Return the translated string if available, otherwise, return the original string.


sb_get_translations()

Return the translations of the back-end and the front-end, for all the available languages.


Response

                                {
                                    "ar": {
                                        "name": "Arabic",
                                        "front": {
                                            "Activities": "أنشطة",
                                            "All": "الكل",
                                            "All articles": "جميع المقالات",
                                            "All fields are required.": "جميع الحقول مطلوبة",
                                            ...
                                        },
                                        "admin": {
                                            "A conversation was started by": "",
                                            "Activate": "",
                                            "Activation complete! Page reload in progress...": "",
                                            "Add a saved reply": "",
                                            ...
                                        }
                                    },
                                    "da": {
                                        "name": "Danish",
                                        "front": {
                                            "Activities": "Aktiviteter",
                                            "All": "Alle",
                                            "All articles": "Alle artikler",
                                            "All fields are required.": "Alle felter skal udfyldes.",
                                            ...
                                        },
                                        "admin": {
                                            "A conversation was started by": "",
                                            "Activate": "",
                                            "Activation complete! Page reload in progress...": "",
                                            "Add a saved reply": "",
                                            ...
                                        }
                                    },
                                    ...
                                }
                            

sb_save_translations()

Save the translations and overwrite the translations files. Warning! If the given translations array is corrupted you could corrupt the translations files. Make a backup of the translations folder ( \resources\languages\) first. Each time a translation is saved a backup is created automatically in the uploads folder.


Arguments

translations
The translations array with all the translations. Use the function sb_get_translations() to get the array.

Response

true

sb_get_user_language()

Return the active language code used by the user. By default, it's the user browser language.


Response

The language code. Examples: es, it, en.


PHP API

More functions

Various functions that perform different tasks.


sb_email()

Send an email to an existing user using the email templates of the Settings > Notifications area.


Arguments

recipient_id
The ID of the user to which send the email.
message
The message of the email.
attachments
Array of attachments in JSON format. Array syntax: [["name", "link"], ["name", "link"], ...]. Replace name with the name of the attachment and link with the full URL of the attachment. Default: [];
sender_id
The ID of the sender user. Default: active user ID.

Response

                                true
                            

sb_push_notification()

Send a Push notification to an agent, a group of agents, or all agents. Push notifications must be enabled in the settings area.


Arguments

title
The title of the notification.
message
The message text.
icon
The icon of the notification. Default: Support Board icon or notifications icon.
interest
Insert the ID of the agent, an array of agents IDs (ex. [1, 2, 3]), or the string agents to send the notification to all agents.
conversation_id
The ID of the conversation to open when the user clicks the notification.

Response

                                {
                                    "publishId": "pubid-781799f5-6el4-4789-bc60-ee293543781"
                                }
                            

Return false it the Push notifications are disabled in the settings area.


sb_get_setting()

Return a setting saved in the Settings area.


Arguments

setting
The setting ID. You can get the IDs of all the settings from the file resources\json\settings.json.

Response

Return the value of the setting.


sb_get_settings()

Return an array with all the settings.


Response

                                {
                                    "chat-manual-init": [
                                        false,
                                        "checkbox"
                                    ],
                                    "chat-login-init": [
                                        false,
                                        "checkbox"
                                    ],
                                    "init-dashboard": [
                                        true,
                                        "checkbox"
                                    ],
                                    "chat-timetable-disable": [
                                        false,
                                        "checkbox"
                                    ],
                                    "rtl": [
                                        false,
                                        "checkbox"
                                    ],
                                    "front-auto-translations": [
                                        true,
                                        "checkbox"
                                    ],
                                    ...
                                }
                            

sb_save_settings()

Save the chat settings. This function overwrite all settings with the given ones.


Arguments

settings
Array of settings. You can get the array of the current settings with the function sb_get_settings().
extra_settings
Array of additional settings. Each value of the array is saved in a new row of the table sb_settings of the database.

Response

                                true
                            

sb_is_error()

Check if a variable is of type SBError. Use the method $error->code() to get the error code, the method $result->function_name() to get the function name that generated the error, the method $result->message() to get the error message.


Arguments

object
The variable to check.

Response

Return true if the variable is of type SBError, otherwise, return false.


sb_is_validation_error()

Check if a variable is of type SBValidationError. Use the method $error->code() to get the error code.


Arguments

object
The variable to check.

Response

Return true if the variable is of type SBValidationError, otherwise, return false.


sb_isset()

Check if an array key exists and return its value only if it exists and if it isn't an empty string.


Arguments

array
The array in which to look for the key.
key
The key to search.
default
The value to return if the key is not found or if it's empty. Default: false.

Response

Return the value of the key or the default value.


sb_archive_slack_channels()

Archive all the Slack channels. If you have a lot of channels, this operation may take a long time to complete and you could need to execute it again multiple times. Important: All of your slack channels will be archived. The Slack App is required.


Response

                                true
                            

sb_get_articles()

Return an array with all the articles or a single article.


Arguments

id
The ID of the article. To get the articles IDs execute this function without any argument. Default: -1.
count
The maximum number of returned articles. Default: all.
full
Set it to true to get full-length articles contents. Default: false.

Response

                                [
                                    {
                                        "id": "6P2Oq",
                                        "title": "What's new with Dialogflow API V2?p",
                                        "content": "Dialogflow API V2 is the new iteration of o ...",
                                        "link": "https://dialogflow.com/v2-faq"
                                    },
                                    {
                                        "title": "Should I move to the new API?",
                                        "content": "Yes. The newest version (V2) of the Actions ...",
                                        "link": "https://dialogflow.com/v2-faq",
                                        "id": "qf7kD"
                                    },
                                    ...
                                ]
                            
                                {
                                    "id": "6P2Oq",
                                    "title": "What's new with Dialogflow API V2?p",
                                    "content": "Dialogflow API V2 is the new iteration of our developer API. The new API integrates...",
                                    "link": "https://dialogflow.com/v2-faq"
                                }
                            

sb_save_articles()

Save all the articles. This function replaces all the existing articles with the articles of the given array.


Arguments

articles
The array with the articles. Use the API get-articles to get the articles array. Example: [["id" => "6P2Oq", "title" => "What's new with Dialogflow API V2?", "content" => "Dialogflow API V2 is the new iteration of our developer API. The new API integrates Google Cloud Spe", "link" => "https://dialogflow.com"] , ["title" => "Which API version am I currently using?", "content" => "The Dialogflow API version is configured separately for each agent. To see which API version click the link.", "link" => "", "id" => "IDkft"], ...].

Response

                                true
                            

sb_search_articles()

Return the articles matching the search.


Arguments

search
String with the search terms. The search function supports the title and the content.

Response

                                [
                                    {
                                        "id": "6P2Oq",
                                        "title": "What's new with Dialogflow API V2?p",
                                        "content": "Dialogflow API V2 is the new iteration of o ...",
                                        "link": "https://dialogflow.com/v2-faq"
                                    },
                                    {
                                        "title": "Should I move to the new API?",
                                        "content": "Yes. The newest version (V2) of the Actions ...",
                                        "link": "https://dialogflow.com/v2-faq",
                                        "id": "qf7kD"
                                    },
                                    ...
                                ]
                            

sb_get_versions()

Return the installed version of Support Board and the Apps.


Response

                                {
                                    "sb": "3.0.4",
                                    "dialogflow": "1.0.2",
                                    "slack": "1.0.3"
                                }
                            

sb_update()

Start the update of Support Board and all the apps. This function forces the update and always overwrite all plugin and apps files.


Response

                                success
                            

sb_wp_synch()

Start the synchronization of the WordPress users and import the new WordPress users into Support Board. This function is available only in the WordPress version.


Response

                                true
                            

sb_app_get_key()

Return the License Key of a Support Board App like the Slack App or the Dialogflow App.


Arguments

app_name
Insert one of the following values: slack , dialogflow .

Response

                                9300AB16-014ZEE12-91E199EA-997CEX40
                            

sb_app_activation()

Activate an app, download it, and install it.


Arguments

app_name
Insert one of the following values: slack , dialogflow .
key
The License Key of the App. You can get the key with the function app-get-key.

Response

                                success
                            

sb_csv_users()

Export all the users in a CSV file and return the URL.


Response

Return the URL of the CSV file.


sb_csv_conversations()

Export a conversation in a CSV file and return the URL.


Arguments

conversation_id
The ID of the conversation to export.

Response

Return the URL of the CSV file.


sb_dialogflow_intent()

Create a new intent in Dialogflow. Will be used the bot synchronized in the admin area. The Dialogflow App is required.


Arguments

expressions
Array with the training phrases. Array syntax: ["", "", ...].
response
String containing the response of the bot when the user input matches a user expression.
agent_language
The language code of the intent. Default: the main bot language. For the language codes list visit cloud.google.com/dialogflow/docs/reference/language.

sb_json_array()

Convert a JSON string to an array.


Arguments

json
The JSON string.
default
The value to return if the conversion is unsuccessful. Default: [].

Response

Return a PHP array if the conversion is successful, otherwise, return the default value.


sb_office_hours()

Check if the current time is within the office hours.


Response

Return true if the current time is within the office hours, otherwise, return false.


sb_encryption()

Encrypt a string or decrypt an encrypted string.


Arguments

action
Insert encrypt to encrypt a string, insert decrypt to decrypt an encrypted string.
string
The string to encrypt or decrypt.

Response

Return the encrypted string or the decrypted string.


sb_string_slug()

Convert a string to a slug or a slug to a string. When converting a string to a slug all spaces are converted to - and all chars are in lowercase. When converting a slug to a string all the occurrences of the chat - are converted to spaces and the first chat is in uppercase.


Arguments

string
The string to convert.
action
Insert slug to convert a string to a slug, insert string to convert a slug to a string. Default: "slug".

Response

Return the slug or the converted string.


sb_curl()

Send data to a URL to get a JSON response.


Arguments

url
The destination URL that will receive the data.
post_fields
Array with the attributes. It can be an array, example: ["attribute" => "value", "attribute" => "value", ...]. It can be a string containing an array in JSON format.
header
The HTTP header. It is usually an array like [ 'Content-Type: application/json', 'Content-Length: 123456'].

Response

Return a PHP array with the data of the JSON array returned by the server.


sb_download()

Download a file or return data from a URL.


Arguments

URL
The destination URL.

Response

The file or the data returned by the server.


sb_csv()

Create a CSV file from an array.


Arguments

items
Array containing the data to save in the CSV file. It must be a basic array, each item is a new row in the CSV file.
header
Array containing the header elements. Example: ["ID", "First Name", "Last Name", "Email"].
filename
The name of the CSV file.

Response

Return the URL of the CSV file. The file is saved into the uploads folder. By default, it's located in the supportboard plugin folder or in the wp-content/uploads folder if you're using the WordPress version.


sb_file()

Create a new file containing the given content and save it in the destination path.


Arguments

path
The file system destination path, the file will be saved there.
content
The content of the file.

Response

                                true
                            

sb_clean_data()

This function performs the following tasks: delete visitors older than 24h, delete messages in trash older than 30 days, archive conversation older than 24h with status code equal to 0 or 1 (waiting an answer from the user or without any user reply).


Response

true