Class: TiledeskClient

TiledeskClient(options)

This class is a NodeJS stub for Tiledesk's REST APIs

Constructor

new TiledeskClient(options)

Constructor for TiledeskClient object
Parameters:
Name Type Description
options Object JSON configuration.
Properties
Name Type Description
APIKEY string Mandatory. Tiledesk APIKEY
projectId string Mandatory. Tiledesk projectId. Will be used in each call on project's APIs.
token string Mandatory. Tiledesk authentication token. Will be used in each call on project's APIs.
APIURL string Optional. Tiledesk server API endpoint.
httpsOptions string Optional. A JSON with https option as rejectUnauthorized = false
log boolean Optional. If true HTTP requests are logged.
Source:
Example
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
const tdclient = new TiledeskClient({APIKEY: 'THE_API_KEY', projectId: 'YOUR_PROJECT_ID', token: 'YOUR_AUTH_TOKEN'});
const tdclient = new TiledeskClient({APIKEY: 'THE_API_KEY', projectId: 'YOUR_PROJECT_ID', token: 'YOUR_AUTH_TOKEN', APIURL: 'SELF_HOSTED_INSTANCE_ENDPOINT'});

Methods

addRequestParticipant(requestId, participantId, callback)

Add a participant to the request's participants.
REST API
Parameters:
Name Type Description
requestId string The request ID.
participantId array the participant (agent or bot) identifier
callback resultCallback The callback that handles the response.
Source:

agent(requestId, depId, callback)

Moves the Request to an agent on the specific department.
REST API
Parameters:
Name Type Description
requestId string The request ID
depId string The new department ID
callback resultCallback The callback that handles the response.
Source:

assign(requestId, email, fullname, options, callback)

Assign an agent to the specified department using the 'assing' method.
Parameters:
Name Type Description
requestId string The request ID where applying the assignment
email string The department ID where applying the assignment
fullname string The new Lead fullname
options assignOptions The options. If null default options apply
callback resultCallback The callback that handles the response.
Source:

changeBot(requestId, botId, callback)

Updates the Request removing the current chatbot (if any) and adding the new one. Then it sends the hidden 'start' message. Orchestration APIs (Mashup of REST APIs)
Parameters:
Name Type Description
requestId string The request ID
botId string The id of the bot to add in the conversation.
callback resultCallback The callback that handles the response.
Source:

changeBotAndMessage(requestId, botId, message, callback)

Updates the Request removing the current chatbot (if any) and adding the new one. Then it sends the optional first message. Orchestration APIs (Mashup of REST APIs)
Parameters:
Name Type Description
requestId string The request ID
botId string The bot ID.
message string Optional. The first message to send as soon as the new bot is added to the conversation. This is used to trigger the greet message from the chatbot, if any is defined.
callback resultCallback The callback that handles the response.
Source:

closeRequest(requestId, callback)

Closes the Request REST API
Parameters:
Name Type Description
requestId string The request ID
callback resultCallback The callback that handles the response.
Source:

createBot(botName, isExternal, botUrl, callback)

Create a bot.
REST API
Parameters:
Name Type Description
botName string The bot's name.
isExternal boolean 'true' if you want an external bot.
botUrl string The external bot's endpoint url.
callback resultCallback The callback that handles the response.
Source:

createDepartment(name, routing, groupId, botId, callback)

Create a new department.
REST API
Parameters:
Name Type Description
name string The department's name.
routing boolean (optional) The department routing type. Permitted values: 'assigned', 'pooled' (default).
groupId string (optional) The group of users assigned to the department. If not provided the request will be routed through all available users
botId string (optional) The bot assigned to the department, if any.
callback resultCallback The callback that handles the response.
Source:

createIntent(botId, intent_display_name, question, answer, language, webhook_enabled, callback)

Create an Intent (aka Faq).
REST API
Parameters:
Name Type Description
botId string The botId. Mandatory
intent_display_name string Intent Display Name
question string The question
answer string The answer
language string The bot language
webhook_enabled boolean Is fulfillment enabled for this intent?
callback resultCallback The callback that handles the response.
Source:

deleteBot(botId, callback)

Delete a bot by id.
REST API
Parameters:
Name Type Description
botId string The bot ID.
callback resultCallback The callback that handles the response.
Source:

deleteDepartment(depId, callback)

Delete a department by id.
REST API
Parameters:
Name Type Description
depId string The department ID.
callback resultCallback The callback that handles the response.
Source:

deleteRequestParticipant(requestId, participantId, callback)

Delete a participant from the request's participants.
REST API
Parameters:
Name Type Description
requestId string The request ID.
participantId array the participant (agent or bot) identifier
callback resultCallback The callback that handles the response.
Source:

findBotByName(botName, callback)

Get the first bot with the specified name in the project.
REST API
Parameters:
Name Type Description
botName string The bot name.
callback resultCallback The callback that handles the response.
Source:

fireEvent(event, callback)

Fire a new custom event and save it.
With this endpoint you can fire a custom event. You event name should be of the form event.emit.EVENT_NAME to correctly identify your custom event.
You can find the standard Tiledesk events here
REST API
Parameters:
Name Type Description
event string
callback resultCallback The callback that handles the response.
Source:

getAllBots(callback)

Get all the bots defined in the project.
REST API
Parameters:
Name Type Description
callback resultCallback The callback that handles the response.
Source:

getAllDepartments(callback)

Get all the deparments defined in the project.
REST API
Parameters:
Name Type Description
callback resultCallback The callback that handles the response.
Source:

getAllRequests(queryParams, callback, options)

Queries project's requests.
Parameters:
Name Type Description
queryParams queryParams The query parameters.
callback resultCallback The callback that handles the response.
options Object Optional configuration.
Properties
Name Type Description
token string The token for this request. Overrides instance token (if) provided in constructor.
projectId string The token for this request. Overrides instance token (if) provided in constructor.
Source:

getBot(botId, callback)

Get bot by id.
REST API
Parameters:
Name Type Description
botId string The bot ID.
callback resultCallback The callback that handles the response.
Source:

getDepartment(depId, callback)

Get a department by id.
REST API
Parameters:
Name Type Description
depId string The department ID.
callback resultCallback The callback that handles the response.
Source:

getDepartments(callback)

Get all the visible (aka active) departments defined in the project.
REST API
Parameters:
Name Type Description
callback resultCallback The callback that handles the response.
Source:

(async) getIntents(id_faq_kb, intent_display_name, page, limit, text, callback)

Get bot intents, filtered by parameters
REST API
Parameters:
Name Type Description
id_faq_kb string The bot's id. Mandatory.
intent_display_name string Filter by Intent Display Name. Optional
page number page number for pagination. Optional
limit number results per page. Optional
text string executes a full text search on this parameter. Optional
callback resultCallback The callback that handles the response.
Source:

(async) getLeadById(leadId, callback)

Gets the Lead.
REST API
Parameters:
Name Type Description
leadId string The Lead ID
callback resultCallback The callback that handles the response.
Source:

(async) getProjectAvailableAgents(callback)

Returns the project's available agents
REST API
Parameters:
Name Type Description
callback resultCallback The callback that handles the response.
Source:

getProjectSettings(callback)

Returns the project's JSON configuration
REST API
Parameters:
Name Type Description
callback resultCallback The callback that handles the response.
Source:

getProjectUser(userId, callback)

Returns a project's User (aka Teammate, is a User invited on a project, with additional properties and a specific project-userId)
Parameters:
Name Type Description
userId string The Teammate ID. It is the specific ID for this user on this project
callback resultCallback The callback that handles the response.
Source:

(async) getRequestById(requestId, callback)

Gets a request by ID.
Parameters:
Name Type Description
requestId string The request ID.
callback resultCallback The callback that handles the response.
Source:

getTeam(callback)

Returns all teammates (aka Project Users, Tiledesk Users invited on a specific project are named "Teammates". They have additional properties and a specific project-userId)
REST API
Parameters:
Name Type Description
callback resultCallback The callback that handles the response.
Source:

getWidgetSettings(callback)

Returns the Widget settings for the selected project.
Parameters:
Name Type Description
callback resultCallback The callback that handles the response.
Source:

moveToAgent(requestId, callback)

Moves the current conversation to an agent following the current request department rules. If no department is connected to the request it will move to the Default Department REST API
Parameters:
Name Type Description
requestId string The request ID
callback resultCallback The callback that handles the response.
Source:

openNow(callback)

Returns the current opening status based on Opening Hours (aka Operating hours).
Parameters:
Name Type Description
callback resultCallback The callback that handles the response.
REST API
Source:

removeCurrentBot(requestId, callback)

Updates the Request removing the current chatbot (if any). Orchestration APIs (Mashup of REST APIs)
Parameters:
Name Type Description
requestId string The request ID
callback resultCallback The callback that handles the response.
Source:

replaceBotByName(requestId, botId, callback)

Updates the Request removing the current chatbot (if any) and adding the new one. Then it sends the hidden 'start' message. Orchestration APIs (Mashup of REST APIs)
Parameters:
Name Type Description
requestId string The request ID
botId string The id of the bot to add in the conversation.
callback resultCallback The callback that handles the response.
Source:

sendChatMessage(message, callback)

Sends a message to a direct/group conversation.
REST API
Parameters:
Name Type Description
message chatMessage The chat21's message JSON object.
callback resultCallback The callback that handles the response.
Source:

(async) sendEmail(subject, body, to)

Send an email message
Parameters:
Name Type Description
subject string The message subject
body string The message body
to string The recipient's email address.
Source:

sendSupportMessage(requestId, message, callback)

Sends a message to a support conversation.
REST API
Parameters:
Name Type Description
requestId string The request ID.
message chatMessage The chat21's message JSON object.
callback resultCallback The callback that handles the response.
Source:

updateBot(botName, isExternal, botUrl, callback)

Update a bot.
REST API
Parameters:
Name Type Description
botName string The bot's name.
isExternal boolean 'true' if you want an external bot.
botUrl string The external bot's endpoint url.
callback resultCallback The callback that handles the response.
Source:

updateDepartment(depId, name, routing, groupId, botId, callback)

Update a new department.
REST API
Parameters:
Name Type Description
depId string The department's id.
name string The department's name.
routing boolean (optional) The department routing type. Permitted values: 'assigned', 'pooled' (default).
groupId string (optional) The group of users assigned to the department. If not provided the request will be routed through all available users
botId string (optional) The bot assigned to the department, if any.
callback resultCallback The callback that handles the response.
Source:

updateLead(leadId, nativeAttributes, attributes, tags, callback)

Update Lead's data
REST API
Parameters:
Name Type Description
leadId string The Lead ID
nativeAttributes string native attributes: name, email, phone etc.
attributes string Lead custom attributes
tags string Lead tags
callback resultCallback The callback that handles the response.
Source:

updateLeadData(leadId, email, fullname, attributes, callback)

DEPRECATED Updates a Lead's email and fullname.
REST API
Parameters:
Name Type Description
leadId string The Lead ID
email string Lead email update
fullname string Lead fullname to update
attributes string Lead attributes to update
callback resultCallback The callback that handles the response.
Source:

updateProjectUser(projectUserId, properties, callback)

Updates the Teammate's (projectUser) by ProjectUser's ID. It requires admin role.
Parameters:
Name Type Description
projectUserId string The teammate ID.
properties Object The properties to update. Only the provided properties will be updated, the other properties will stay unchanged.
role {string} - The teammate role. Permitted values: 'admin', 'agent'.
user_available {boolean} - The teammate availability. 'true' for available, 'false' for unavailable.
max_served_chat {number} - The number of concurrent chats the teammate can take at once.
attributes {Object} - The teammate custom attributes.
settings {Object} - The teammate settings.
callback resultCallback The callback that handles the response.
Source:

updateProjectUserAttributes(projectUserId, attributes, callback)

Only updates the attributes for the specified Teammate. It requires admin role.
Parameters:
Name Type Description
projectUserId string The teammate ID.
attributes Object The teammate custom attributes.
callback resultCallback The callback that handles the response.
Source:

updateProjectUserAvailable(projectUserId, userAvailable, callback)

Only updates the available status for the specified Teammate. It requires admin role.
Parameters:
Name Type Description
projectUserId string The teammate ID.
userAvailable boolean The teammate availability. 'true' for available, 'false' for unavailable.
callback resultCallback The callback that handles the response.
Source:

updateProjectUserCurrentlyLoggedIn(properties, callback)

Updates the authenticated Teammate's (projectUser). The teammate must be invited to the specified project for the update operation taking success.
REST API
Parameters:
Name Type Description
properties Object The properties to update. Only the provided properties will be updated, the other properties will stay unchanged.
Properties
Name Type Description
role string The teammate role. Permitted values: 'admin', 'agent'.
user_available boolean The teammate availability. 'true' for available, 'false' for unavailable.
max_served_chat number The number of concurrent chats the teammate can take at once.
attributes Object The teammate custom attributes.
settings Object The teammate settings.
callback resultCallback The callback that handles the response.
Source:

updateRequestAttributes(requestId, attributes, callback)

Updates request's 'attributes' property.
REST API
Parameters:
Name Type Description
requestId string The request ID
attributes Object The Request's custom attributes object. It's a payload that carries custom information attached to this request.
callback resultCallback The callback that handles the response.
Source:

updateRequestDepartment(requestId, depId, options, callback)

Updates the Request department REST API
Parameters:
Name Type Description
requestId string The request ID
depId string The new department ID
options Object Optional configuration.
Properties
Name Type Description
nobot string Optional. Defaults to false. If true ignores (if set) the bot in the Department.
callback resultCallback The callback that handles the response.
Source:

updateRequestParticipants(requestId, participants, callback)

Updates the request's participants.
REST API
Parameters:
Name Type Description
requestId string The request ID.
participants array the participants (agents or bots) identifiers array
callback resultCallback The callback that handles the response.
Source:

(async) updateRequestProperties(requestId, properties, callback)

Updates request's properties.
REST API
Parameters:
Name Type Description
requestId string The request ID
properties requestProperties The Request's properties
callback resultCallback The callback that handles the response.
Source:

(static) anonymousAuthentication(projectId, apikey, options, callback)

Returns an anonymous user token to connect to a specific project's services.
REST API
Parameters:
Name Type Description
projectId string The projectId for this anonymous user.
apikey string Your API key.
options Object API call options.
Properties
Name Type Description
APIURL string Optional APIURL for connecting to a Tiledesk self-hosted instance.
log string If true it logs HTTP request.
callback resultCallback The callback that handles the response.
Source:

(static) authEmailPassword(projectId, apikey, options, callback)

Parameters:
Name Type Description
projectId resultCallback The projectId for this anonymous user.
apikey string Your API key.
options Object API call options.
Properties
Name Type Description
APIURL string Optional APIURL for connecting to a Tiledesk self-hosted instance.
log string If true it logs HTTP request.
callback resultCallback The callback that handles the response.
Source:

(static) customAuthentication(token, apikey, options, callback)

Returns a Tiledesk token based on a custom token.
See JWT authentication for more info.
REST API
Parameters:
Name Type Description
token string Your custom token.
apikey string Your API key.
options Object API call options.
Properties
Name Type Description
APIURL string Optional APIURL for connecting to a Tiledesk self-hosted instance.
log string If true it logs HTTP request.
callback resultCallback The callback that handles the response.
Source:

(static) newRequestId(projectId)

Returns a new request ID for the specified Project.
A request's ID has the format:

support-group-PROJECT_ID-UNIQUE_ID

UNIQUE_ID MUST be unique in your Project. This method always returns an UUID for the UNIQUE_ID component.
Parameters:
Name Type Description
projectId string The project ID for the new request.
Source: