Setup and usage
The PHP API supplies a collection of PHP functions that underpin the majority of GB Talk functionality. To start using the PHP API follow the steps below.
Information
- Some functions are protected for security reasons..
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
|
|
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://chat.gbtalk.net/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. Returns 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.logout(); to log out the user also in the client-side.
sb_get_active_user()
Returns the user details of the logged-in user.
Arguments
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 returns the logged-in WordPress user. Use this code to generate the array: sb_encryption(json_encode(['id' => "", 'email' => "")). Default: false. |
Response
[
{
"id": "913",
"profile_image": "https://chat.gbtalk.net/user.svg",
"first_name": "User",
"last_name": "#29902",
"email": null,
"user_type": "visitor",
"token": "9b25351047ee758aa97ee4868d130cc1ceb8decf"
},
"YXNkWGNSeTdtRTdDYVkxVG8wckN4YWF6V2s0Tk1mczBSVHdQbHBpOWdmejVUTTdOUUxEUENhdUVoYmROWn..."
]
sb_get_user()
Returns 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://chat.gbtalk.net/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()
Returns the extra user details of the given user ID, or the requested one.
Arguments
user_id |
The ID of the user. |
slug |
The slug of the setting to retrieve. If this argument is not set, all user details are returned. Default: false. |
default |
The default value to return if the user details are not found. Default: false. |
Response
[
{
"slug": "browser",
"name": "Browser",
"value": "Chrome"
},
{
"slug": "current_url",
"name": "Current URL",
"value": "https://gbtalk.net/"
},
{
"slug": "os",
"name": "OS",
"value": "Windows 10"
},
{
"slug": "phone",
"name": "Phone",
"value": "3203057977"
},
...
]
sb_get_user_name()
Returns the full name of the active user, or the given one.
Arguments
user |
The user object. |
Response
The user name string
sb_get_users()
Returns 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. |
extra |
Set it to true to include all users extra details as well. Set it as an array of user extra detail slugs to include only a subset of extra details. Default: false. |
user_ids |
Array of IDs. If set, returns only the users with ID included in the given array of IDs. Default: false. |
Response
[
{
"id": "880",
"first_name": "User",
"last_name": "#29938",
"email": null,
"profile_image": "https://gbtalk.net/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://gbtalk.net/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()
Returns the users created after the given date/ID.
Arguments
datetime |
User ID or 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://gbtalk.net/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://gbtalk.net/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()
Returns the online users or the online agents and admins.
Arguments
sorting |
The name of the database table used for sorting. Default: creation_time. |
agents |
Set it to true to return only agents and admins. Default: false. |
Response
[
{
"id": "881",
"first_name": "Don",
"last_name": "John",
"email": null,
"profile_image": "https://gbtalk.net/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://gbtalk.net/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_get_online_user_ids()
Returns an array with the IDs of the online users and agents.
Arguments
agents |
Set it to true to return only agents and admins. Default: false. |
Response
[ 881, 548, 125, ... ]
sb_get_users_with_details()
Returns an array with the user IDs and details of the users who have the requested details.
Arguments
details |
Array of user details. Ex. [ "email", "phone" ]. |
user_ids |
Array, or comma-separated string of user IDs. If this argument is set, only the users which have their ID included are returned. Set it to all or false to search all users, set it to agents to search only agents and admins. Default: false. |
Response
{
"email": [
{
"id": 4561,
"value": "albert@example.com"
},
{
"id": 98436,
"value": "jessica@example.com"
},
...
],
"phone": [
{
"id": 12563,
"value": "+4462367136"
},
{
"id": 778956,
"value": "+4462999345"
},
...
],
...
}
sb_get_agents_ids()
Returns an array with the IDs of Agents.
Arguments
admins |
Set it to false to exclude the admins. Default: true; |
Response
[
881,
153,
...
]
sb_search_users()
Returns 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://chat.gbtalk.net/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://chat.gbtalk.net/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(json_encode(['id' => "", 'email' => "")). Default: false. |
hash_password |
Set it to false to skip the password hashing. Use this setting if the passowrd is already hashed. Default: true. |
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 returns 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 |
Enter 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. |
hash_password |
Set it to false to skip the password hashing. Use this setting if the passowrd is already hashed. Default: true. |
Response
true
Other possible responses: duplicate-email, invalid-user-type, SQL error message.
sb_update_user_value()
Update a single detail, or extra detail, of an existing user, agent, or admin.
Arguments
user_id |
The ID of the user to update. |
slug |
The unique name of the detail. Ex. first_name, email, city, birthday. |
value |
The new value of the detail. |
name |
The name of the extra detail. Required only if the user detail to update is an extra detail. |
Response
true
sb_update_login()
Update the login details of the logged-in user and returns the login data for the client-side. Use the Javascript API function SBF.loginCookie(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. |
|
|
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://gbtalk.net
Return false if the URL is not found. Return true if the url argument is set.
sb_count_users()
Returns 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_is_agent()
Check if the given user type string is an admin, an agent, or the bot.
Arguments
user |
A GB Talk user, or a string. |
exclude_bot |
Set it to true to return false if the active user is the bot. Default: false. |
exclude_bot |
Set it to true to return true only if the active user is an administrator. Default: false. |
Response
Return true if the user type string is "admin", "agent", or "bot", otherwise return false.
sb_supervisor()
Check if the active admin is the supervisor and return the supervisor settings if true.
Response
Return the supervisor settings if the active agent ID is the same of the one set in Settings > Admin > Supervisor > Admin ID, otherwise returns false.
sb_get_department()
Returns the department of the active user. This function is used in the admin area.
Response
Returns 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 the active user: city, location, country, timezone, currency, browser, browser language, os. These details are generated automatically.
Arguments
user_id |
The ID of the active 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 returns 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. |
source |
Array to set the typing status on external services. Facebook Messenger: ['fb', USER-ID, FB-PAGE-ID]. |
Response
true
sb_is_online()
Check if the given date and time are recognized as online by GB Talk.
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_is_user_online()
Check if the user is online. This function is compatible with Pusher and Slack.
Arguments
user_id |
The user ID. |
Response
true if online, false if offline.
sb_agents_online()
Check if at least one agent or admin is online.
Response
true if there are agents or admin online, or false if all Agents are offline.
sb_get_bot_id()
Returns the ID of the bot.
Response
123456
sb_get_user_from_conversation()
Returns the details of the user, or last agent, of the given conversation.
Arguments
conversation_id |
The conversation ID. |
agent |
Set it to true to get the last agent who replied to the conversation. Default: false. |
Response
{
"id": "123456",
"email": "email@example.com"
}
sb_get_avatar()
Generate the user profile image by using the first letter of first name, and last name, save the image, and return the image URL.
Arguments
first_name |
The first name of the user. |
last_name |
The last name of the user. |
Response
https://example.com/supportboard/uploads/13-04-21/9455859.png
sb_get_active_user_ID()
Returns the ID of the active user.
Response
The User ID.
sb_get_user_by
Return user info by a given field.
Arguments
by |
The field. Accepted values: email, first_name, last_name, phone, [exta]. [extra] is any user additional detail slug. |
value |
The value of the field. |
Response
{
"id": "881",
"first_name": "Don",
"last_name": "John",
"email": "example@example.com",
"user_type": "visitor",
"department": null
}
Conversations
Functions to manage conversations and messages.
sb_get_conversation()
Returns 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://chat.gbtalk.net/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://chat.gbtalk.net/agent.svg",
"user_type": "agent"
},
...
],
"details": {
"user_id": "802",
"first_name": "Don",
"last_name": "John",
"profile_image": "https://chat.gbtalk.net/user.svg",
"user_type": "lead",
"id": "946",
"title": "",
"conversation_time": "2020-05-0410:06:30",
"conversation_status_code": "3",
"department": null
}
}
sb_get_conversations()
Returns 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. |
department |
Returns only the conversations assigned to the provided department ID. |
source |
Returns only the conversations created from the provided 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). |
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://chat.gbtalk.net/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://chat.gbtalk.net/media/user.svg",
"conversation_status_code": "2",
"user_type": "lead"
},
...
]
sb_get_new_conversations()
Returns the conversations created after the given date/ID or with a message created after the given date/ID. Each conversation includes the last message of the conversation.
Arguments
datetime |
Conversation ID or 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": "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://chat.gbtalk.net/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://chat.gbtalk.net/media/user.svg",
"conversation_status_code": "2",
"user_type": "lead"
},
...
]
sb_get_user_conversations()
Returns 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. |
exclude_id |
Exclude a conversation from the results. |
agents |
Set it to true if the user is an agent or admin. Default: false. |
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://chat.gbtalk.net/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://chat.gbtalk.net/media/user.svg",
"user_type": "agent",
"conversation_status_code": "3"
},
...
]
sb_get_last_conversation_id_or_create()
Returns the ID of the last user conversation if any, otherwise create a new conversation and returns its ID.
Arguments
user_id |
The ID of the user. |
conversation_status_code |
The status code of the conversation to create if not conversations are found. Status codes: live = 0, waiting answer from user = 1, waiting answer from agent = 2, archive = 3, trash = 4. |
Response
The conversation ID
sb_get_new_user_conversations()
Returns the user conversations created after the given date/ID or with a message created after the given date/ID. Each conversation includes the last message of the conversation.
Arguments
user_id |
The ID of the user of the conversations to get. |
datetime |
Conversation ID or 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://chat.gbtalk.net/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://chat.gbtalk.net/media/user.svg",
"user_type": "agent",
"conversation_status_code": "3"
},
...
]
sb_search_conversations()
Returns 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. |
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://chat.gbtalk.net/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://chat.gbtalk.net/media/user.svg",
"conversation_status_code": "0",
"user_type": "user"
},
...
]
sb_search_user_conversations()
Returns 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://chat.gbtalk.net/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://chat.gbtalk.net/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 string. |
department |
The ID of a department. You can get the IDs from Settings > Miscellaneous > Departments. Default: -1. |
agent_id |
The ID of the agent assigned to the conversation. Default: -1. |
source |
Set the conversation source. Default: false. |
extra |
Extra conversation values. Default: false. |
Response
{
"messages": [],
"details": {
"user_id": "882",
"first_name": "Don",
"last_name": "John",
"profile_image": "https://chat.gbtalk.net/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 |
Enter 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()
Returns the messages of a conversation created after the given date/ID.
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. |
last_id |
ID of the last message, use this parameter to exclude all messages with a lower ID. |
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://chat.gbtalk.net/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://chat.gbtalk.net/user.svg",
"user_type": "lead"
},
...
]
sb_send_message()
Add a new message to an existing conversation.
Arguments
sender_id |
The ID of the user who sends the message. |
conversation_id |
The ID of the conversation. |
message |
The content of the message. |
attachments |
Array of attachments. Array syntax: [["name", "link"], ["name", "link"], ...]. Replace name with the name of the attachment and link with the full URL of the attachment. It's up to you to upload attachments to a remote server, this argument only accepts the URL of the files already uploaded. Default: []; |
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. Set it to skip to leave the current conversation status. |
payload |
Array of additional information. You can insert any value. Array syntax: { "key": value, "key": value, ... }. Use this attribute to set an event, available events: delete-message, open-chat. |
queue |
Set it to true if the queue is active in Settings > Miscellaneous > Queue. Default: false. |
recipient_id |
The ID of the user who receive the message. Use this attribute to get the user language. |
Response
{
"status": "success",
"message-id": 123456,
"queue": false,
"notifications": ["sms", "email"]
}
Other possible responses: invalid-status-code, SQL error message. The notifications response include the notifications sent to the user or agents.
sb_direct_message()
Sends a direct chat message, email, or text message to a single user, or several users. No email and text message notifications are sent for direct chat message. You need to send the notifications manually via sb_email() and sb_send_sms().
Arguments
user_ids |
Array, or comma-separated string of user IDs to send the message to. Set it to all to send the message to all users. |
message |
The message. |
subject |
The email subject. Only required for emails. |
Response
true
sb_messaging_platforms_send_message()
Sends a message to the messaging platform linked to the conversation.
Arguments
message |
The message. |
conversation_id |
The conversation ID. |
message_id |
The ID of the GB Talk message. Use this argument to avoid duplicated messages. |
Response
true
sb_update_message()
Update an existing message.
Arguments
message_id |
The ID of the message. |
message |
The content of the message. |
attachments |
Array of attachments. Array syntax: [["name", "link"], ["name", "link"], ...]. Replace name with the name of the attachment and link with the full URL of the attachment. It's up to you to upload attachments to a remote server, this argument only accepts the URL of the files already uploaded. Default: [];. |
payload |
Array of additional information. You can insert any value. Array syntax: { "key": value, "key": value, ... }. |
Response
true
sb_delete_message()
Delete an existing message.
Arguments
message_id |
The ID of the message to delete. |
Response
true
sb_close_message()
Sends the close message to a user conversation. The close message' contents can be set in the Settings > Chat > Close message area.
Arguments
conversation_id |
The ID of the conversation to send the message to. |
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(); |
Response
{
"status": "success",
"message-id": 123456
}
sb_text_formatting_to_html()
Convert the text formatting of chat messages to the equivalent HTML codes and returns the message.
Arguments
message |
The text message. |
Response
Lorem ipsum dolor <b>sit amet</b>, <i>consectetur adipiscing elit</i>, <code>sed</code> do eiusmod tempor incididunt.
sb_clear_text_formatting()
Remove the text formatting from a chat messages.
Arguments
message |
The text message. |
Response
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.
sb_conversation_security_error()
Verify if the active user is authorized to update the conversation. Agents and admins can always update all conversations, users can only update their own conversations.
Arguments
conversation_id |
The conversation ID. |
Response
Returns true if the active user is not authorized, otherwise, returns false.
sb_set_agent_active_conversation()
Communicate that an agent is replying to a conversation. The conversation is marked as busy for 2 hours if this function is not executed again by the same agent for another conversation.
Arguments
conversation_id |
The conversation ID. |
agent_id |
The agent ID. Default: active user ID. |
sb_is_active_conversation_busy()
Checks if an agent is replying to a conversation. This function checks if the function sb_set_agent_active_conversation() has been executed for the given conversation by another agent within 2 hours.
Arguments
agent_id |
The agent ID. |
skip |
Set it to the active user ID to exclude the active agent from the check. Default: -1. |
Response
Returns true if an agent is replying to the conversation.
sb_sb_get_agents_in_conversation()
Returns an array with all the agents with at least one message in the conversation.
Arguments
conversation_id |
The conversation ID. It can be an array of conversation IDs. |
Response
{
"1546": [
{
"id": 5463,
"first_name": "Don",
"last_name": "John",
"profile_image": "https://chat.gbtalk.net/user.svg",
"conversation_id": 1546
},
{
"id": 6413,
"first_name": "Steven",
"last_name": "Travolta",
"profile_image": "https://chat.gbtalk.net/user.svg",
"conversation_id": 1546
},
...
],
...
}
Database
Functions to read data from the database and to save data in it.
sb_db_get()
Returns the data of a SQL query.
Arguments
query |
The SQL query. |
single |
Set it to false if the query should returns 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 returns a value. Default: false. |
Response
Return true, the returns 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
Returns 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
Returns the converted array.
sb_db_check_connection()
Checks 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, returns the connection error message.
More functions
Various functions that perform different tasks.
sb_email()
Sends an email to an existing user using the email templates, and settings, of the Settings > Notifications area. The email is translated automatically.
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. It's up to you to upload attachments to a remote server, this argument only accepts the URL of the files already uploaded. Default: []. |
sender_id |
The ID of the sender user. Default: active user ID. |
Response
true
sb_email_send()
Sends a generic email to an email address. The sender email and name are the ones set in Settings > Notifications > Email settings.
Arguments
to |
The email address. |
subject |
The email subject. |
message |
The message of the email. |
sender_suffix |
Append the provided text to the sender name. Default: empty. |
Response
true
sb_email_piping()
Runs the email piping synchronization with GB Talk and converts emails to chat messages.
Arguments
force |
Set it to true to the execution of the synchronization, by default the synchronization is executed a maximum of one time per minute. Default: false. |
Response
true
sb_send_sms()
Sends a text message to a user or agent. If the template argument is true, the message is translated automatically.
Arguments
message |
The text message. |
to |
The phone number. |
template |
Set it to false to send only the message without the template content. Default: the message is sent within the template of Settings > SMS notifications. |
conversation_id |
Set it if the message contains the URL parameter {conversation_url_parameter}. |
attachments |
Array of attachment. Array syntax: [["name", "link"], ["name", "link"], ...] or ["link", "link", ...]. Replace name with the name of the attachment and link with the full URL of the attachment. It's up to you to upload attachments to a remote server, this argument only accepts the URL of the files already uploaded. Default: false. |
Response
{
"sid": "SM1f0e8ae6ade43cb3c0ce4525424e404f",
"date_created": "Fri, 13 Aug 2010 01:16:24 +0000",
"date_updated": "Fri, 13 Aug 2010 01:16:24 +0000",
"date_sent": null,
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"to": "+15305431221",
"from": "+15104564545",
"body": "A Test Message",
"status": "queued",
"flags":["outbound"],
"api_version": "2010-04-01",
"price": null,
"uri": "\/2010-04-01\/Accounts\/ACXXXX\/Messages\/SM1f004f.json"
}
sb_send_agents_notifications()
Sends all the agent notifications: email notification, push notification, and SMS notification.
Arguments
message |
The message text. |
bottom_message |
Additional message to append at the end of the email notification. |
conversation_id |
The ID of the conversation linked to the message. If this value is not set the notifications are sent to all agents. |
attachments |
Array of attachments. Array syntax: [["name", "link"], ["name", "link"], ...]. Replace name with the name of the attachment and link with the full URL of the attachment. It's up to you to upload attachments to a remote server, this argument only accepts the URL of the files already uploaded. Default: false. |
user |
User of the conversation as array of user details. |
extra |
Array of values. Enter the value force: true to force the notifications also if the agent is online. Enter the value email: [email_content] to send a different message only for the email notification. |
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 returns 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 returns if the key is not found or if it's empty. Default: false. |
Response
Returns the value of the key or the default value.
sb_get_articles()
Returns an array with all the articles or a single article.
Arguments
id |
The ID of the article. Add multiple IDs separated by commas. To get the article IDs execute this function without any argument. Default: false. |
count |
The maximum number of returned articles. Default: all. |
full |
Set it to true to get full-length articles contents. Default: false. |
categories |
Boolean. Set it to true to get the array of all categories. If true the response is a double array, first item articles, second item categories. Default: false. |
articles_language |
Get the articles in the language of the given language code. If there are no articles in the given language code, the articles in the default language are returned instead. Set it to all to get all the translations. Default: false. |
Response
[
{
"id": "6P2Oq",
"title": "What's new with the API V2?p",
"content": "The API V2 is the new iteration of o ...",
"link": "https://chat.gbtalk.net"
"categories": ["ols85"]
},
{
"id": "qf7kD"
"title": "Should I move to the new API?",
"content": "Yes. The newest version (V2) of the Actions ...",
"link": "https://chat.gbtalk.net",
"categories": []
},
...
]
Single article response
{
"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...",
"link": "https://chat.gbtalk.net",
"categories": ["ols85"]
}
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 function
sb_get_articles() to get the articles array.
Array syntax:
[["id" => "", "title" => "", "content" => "", "link" => ""] , ["title" => "", "content" => "", "link" => "", "id" => ""], ...] |
categories |
Array of category IDs. Set it to delete_all to delete all categories. |
translations |
The array with the articles translations. Use the function
sb_get_articles() to get the articles array.
Array syntax:
[ "es" => [["id" => "", "title" => "", "content" => "", "link" => ""], ...], "it" => [...], ...] |
Response
true
sb_search_articles()
Returns the articles matching the search.
Arguments
search |
String with the search terms. The search function supports the title and the content. |
articles_language |
Search only the articles in the language of the given language code. If there are no articles in the given language code, the search returns the articles in the default language. Set it to all to get all the translations. Default: false. |
Response
[
{
"id": "6P2Oq",
"title": "What's new with the API V2?p",
"content": "The API V2 is the new iteration of o ...",
"link": "https://chat.gbtalk.net",
"categories": ["ols85"]
},
{
"id": "qf7kD"
"title": "Should I move to the new API?",
"content": "Yes. The newest version (V2) of the Actions ...",
"link": "https://chat.gbtalk.net",
"categories": []
},
...
]
sb_get_articles_categories()
Returns an array with all the articles categories.
Response
[
{
"id": "Nv9PG",
"title": "Business"
},
{
"id": "csPVh",
"title": "Travel And Tourism"
},
{
"id": "pl5S7",
"title": "Finance"
},
...
]
sb_save_articles_categories()
Save or update the articles categories array.
Arguments
categories |
Array of categories. Array syntax: [ { "id": "123456", "title": "Category name" }, { "id": "123456", "title": "Category name" }, ...]. Get the existing categories array with the function get_articles_categories(). |
Response
true
sb_article_ratings()
Get the ratings of an article or add a new rating to it.
Arguments
article_id |
The ID of the article. |
rating |
The rating to add. Insert 1 for a positive rating or 0 for a negative one. If this argument is set the function adds the rating, otherwise returns the existing ratings. Default: false. |
Response
[-1, 1, 1, -1, ...]
Returns true if the rating argument is set.
sb_csv_users()
Export all the users in a CSV file and returns the URL.
Response
Returns the URL of the CSV file.
sb_transcript()
Export a conversation in a CSV or TXT file and returns the URL.
Arguments
conversation_id |
The ID of the conversation to export. |
type |
Set it to csv to export the conversation as a CSV file, set it to txt to export the conversation as a text file, set it to false to use the type set in Settings > Admin > Transcript type. Default: false. |
Response
Returns the URL of the CSV file.
sb_json_array()
Convert a JSON string to an array.
Arguments
json |
The JSON string. |
default |
The value to returns if the conversion is unsuccessful. Default: []. |
Response
Returns a PHP array if the conversion is successful, otherwise, returns 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
string |
The string to encrypt or decrypt. |
encrypt |
Set it to false to decrypt. Default: true. |
Response
Returns 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
Returns the slug or the converted string.
sb_curl()
Sends 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"]. |
method |
The HTTP method. Default: POST. |
Response
Returns a PHP array with the data of the JSON array returned by the server.
sb_download()
Returns the data of a URL.
Arguments
URL |
The destination URL. |
Response
The file or the data returned by the server.
sb_download_file()
Download a file, save it in the uploads folder, and return the URL.
Arguments
URL |
The destination URL. |
file_name |
The file name of the saved file. Default: original file name. |
mime |
Set it to true to retrieve the file extension automatically. Set it to a mime type string to assign the mime extension to the file name. |
Response
The URL of the file saved in the uploads folder.
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
Returns 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
sb_get_shortcode()
Convert a shortcode into an array containing the shortcode name and the shortcode settings.
Arguments
shortcode |
The shortcode string. Example: [rating title="Rate your conversation" message="Tell us your experience." success="Thank you!"]. |
name |
The shortcode name. Example: inputs. Default: false. |
type |
Set it to merge if the shortcode is a merge field like {}. |
Response
{
"shortcode": "[rating title="Rate your conversation" message="Tell us your experience." success="Thank you!"]",
"shortcode_name": "rating",
"title": "Rate your conversation",
"message": "Tell us your experience.",
"success": "Thank you!"
}
sb_get_notes()
Returns the internal notes of a conversation.
Arguments
conversation_id |
The conversation ID. |
Response
[
{
"id": 98207,
"user_id": "1538",
"name": "Lorem ipsum dolor sit amet",
"message": "Lorem ipsum dolor sit amet, consectetur elit, sed do eiusmod tempor incididunt."
},
{
"id": 76986,
"user_id": "1596",
"name": "Lorem ipsum dolor",
"message": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor."
},
...
]
sb_add_note()
Add a new internal note.
Arguments
conversation_id |
The conversation ID to which link the note to. |
user_id |
The ID of the agent or admin who create the note. |
name |
The note name. |
message |
The note message. |
Response
The note ID
sb_delete_note()
Delete an internal note.
Arguments
conversation_id |
The ID of the conversation linked with the note. |
note_id |
The note ID. |
Response
true
sb_automations_get()
Returns all automations.
Response
[
{
"emails": [
{
"id": "0BOaG",
"conditions": [
[
"datetime",
"is-between",
"10/04/2021 - 13/04/2021"
],
[
"include_urls",
"contains",
"https://example.com"
],
...
],
"name": "Excepteur sint",
"message": "Excepteur sint occaecat cupidatat non proident.",
"subject": "Cupidatat non proident"
},
...
],
"sms": [
{
"id": "vo2sY",
"conditions": [
[
"datetime",
"is-exactly",
"13/04/2021"
]
],
"name": "Excepteur sint",
"message": "Excepteur sint occaecat cupidatat non caecat cupidatat non proident"
},
{
"id": "hwkmQ",
"name": "Excepteur sint occaecat cupidatat non proident",
"message": "Excepteur sint occaecat cupidatat non occaecat cupidatat non proident"
},
...
],
"messages": [],
"popups": [
{
"id": "ckN24",
"conditions": [
[
"user_type",
"is-user"
],
[
"languages",
"en"
]
],
"name": "s",
"message": "Excepteur sint occaecat cupidatat non prcaecat cupidatat non proident",
"title": "Excepteur sint occaecat",
"profile_image": "https://example.com/image.jpg"
},
...
],
"design": [
{
"id": "bX1qA",
"conditions": [
[
"user_type",
"is-user"
]
],
"name": "Excepteur sint",
"message": "Excepteur sint occaecat cupidatat caecat cupidatat non proident",
"title": "",
"color_1": "rgb(0, 235, 26)",
"color_2": "rgb(255, 0, 0)",
"color_3": "rgb(255, 0, 0)",
"background": "https://example.com/image.jpg",
"brand": "https://example.com/image.jpg",
"icon": "https://example.com/image.jpg"
},
...
]
},
{
"fr": {
"messages": [
{
"id": "y6hNE",
"name": "XXXX",
"message": "XXXX"
}
]
},
...
}
]
sb_automations_save()
Save all automations.
Arguments
automations |
Automations array. Get it from sb_get_automations(). |
translations |
Automations translations array. Get it from sb_get_automations(). |
Response
true
sb_automations_validate()
Validate an automations.
Arguments
automation |
The automation. |
Response
{
"conditions": [
[
"user_type",
"is-user"
],
...
],
"repeat_id": ""
}
Returns only the client-side conditions and invalid server-side conditions that can be validated in a later time. If no conditions are returned, the automation is valid and can be executed. Returns false if the automation is invalid.
sb_automations_run_all()
Validate all automations, execute the valid ones, and returns the automations with client-side conditions, invalid server-side conditions, and popup, design automations.
Response
[
{
"id": "0BOaG",
"conditions": [
[
"datetime",
"is-between",
"10/04/2021 - 13/04/2021"
],
[
"include_urls",
"contains",
"https://example.com"
],
...
],
"name": "Excepteur sint",
"message": "Excepteur sint occaecat cupidatat non proident.",
"subject": "Cupidatat non proident",
"type": "emails"
},
{
"id": "bX1qA",
"conditions": [
[
"user_type",
"is-user"
]
],
"name": "Excepteur sint",
"message": "Excepteur sint occaecat cupidatat caecat cupidatat non proident",
"title": "",
"color_1": "rgb(0, 235, 26)",
"color_2": "rgb(255, 0, 0)",
"color_3": "rgb(255, 0, 0)",
"background": "https://example.com/image.jpg",
"brand": "https://example.com/image.jpg",
"icon": "https://example.com/image.jpg",
"type": "design"
},
...
]
sb_automations_run()
Execute a single automation and optionally validate it before executing it.
Arguments
automation |
The automation. |
validate |
Set it to true to validate the automation before executing it. Default: false. |
Response
true