Web SDK

Web SDK ver 5.0

Are you interested in the v4 version? Click here.

This guide will show you how to get started as quickly as possible with the Web SDK from Tiledesk. The Web SDK will give businesses and developers the flexibility to build and customize a chat experience that meet their specific design/brand requirements.

Install the Web HTML Widget

To chat with your visitors embed the widget on your site. Copy the following script and insert it in the HTML source between the HEAD tags:

<script type="application/javascript">
window.tiledeskSettings=
{
projectid: "6048e8b09818900019fc6141"
};
(function(d, s, id) {
var w=window; var d=document; var i=function(){i.c(arguments);};
i.q=[]; i.c=function(args){i.q.push(args);}; w.Tiledesk=i;
var js, fjs=d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js=d.createElement(s);
js.id=id; js.async=true; js.src="https://widget.tiledesk.com/v5/launch.js";
fjs.parentNode.insertBefore(js, fjs);
}(document,'script','tiledesk-jssdk'));
</script>

To get your TILEDESK_PROJECT_ID go to the Tiledesk Dashboard and click on the Widget item of the menu:

Configuration

Widget version 5.0 supports remote configuration of most parameters directly from the Widget menu of the Dashboard.

You can customize the widget passing the following parameters to window.tiledeskSettings object.

  • projectid. The Tiledesk project id. Find your Tiledesk ProjectID in the Tiledesk Dashboard under the Widget menu.

  • preChatForm: You can require customers to enter information like name and email before sending a chat message by enabling the Pre-Chat form. Permitted values: true, false. The default value is false.

  • align: Make the chat available on the Right or on the Left of the screen. Permitted values: 'right', 'left'. Default value is right.

  • calloutTimer: Proactively open the chat windows to increase the customer engagement. Permitted values: -1 (Disabled), 0 (Immediatly) or a positive integer value. For exmaple: 5 (After 5 seconds), 10 (After 10 seconds).

  • calloutTitle : The title of the callout window.

  • calloutMsg : The message of the callout window.

  • userFullname: Current user fullname. Set this parameter to specify the visitor fullname.

  • userEmail: Current user email address. Set this parameter to specify the visitor email address.

  • welcomeTitle: The welcome title to show on the widget home page.

  • welcomeMsg: Set the widget welcome message. Value type : string

  • widgetTitle: Set the widget title label shown in the widget header. Value type : string. The default value is Tiledesk.

  • startFromHome: If false when loaded the widget starts directly with a new conversation. If true the widget shows the home component. The default value is true.

  • logoChat: The url of the logo to show on the widget home page.

  • lang : With this configuration it is possible to force the widget lang. The widget will try to get the browser lang, if it is not possible it will use the default "en" lang

  • hideHeaderCloseButton: Hide the close button in the widget header. Permitted values: true, false. The default value is false.

  • hideHeaderConversationOptionsMenu: Enable you to show/hide options menu in a conversation header. Permitted values: true, false. Default value: true

  • isOpen: Read-only property. Set this property true in the script to automatically open the widget as soon as it is loaded. Permitted values: true, false. Default value : false.

  • fullscreenMode: if it is true, the chat window is open in fullscreen mode. Permitted values: true, false. Default value : false

  • themeColor: allows you to change the main widget's color (color of the header, color of the launcher button, other minor elements). Permitted values: Hex color codes, e.g. #87BC65 and RGB color codes, e.g. rgb(135,188,101)

  • themeForegroundColor: allows you to change text and icons' color. Permitted values: Hex color codes, e.g. #425635 and RGB color codes, e.g. rgb(66,86,53)

  • departmentID: to skip departments selection, you can set the department ID upon which the widget must start the new conversation. See the turorial here.

  • isShown: Read only property. This property returns the visibility of the whole widget including the widget ballon. If true the widget is visible otherwise (false) the widget is hidden. Use window.tiledesk.show() and window.tiledesk.hide() methods to change the widget visibility.

  • allowTranscriptDownload: allows the user to download the chat transcript. The download button appears when the chat is closed by the operator. Permitted values: true, false. Default value: false

  • marginX: Set the side margin, left or right depending on the align property. Value type: string. Default value : "20px"

  • marginY: Set the distance from the page bottom margin. Value type: string. Default value : "20px"

  • launcherWidth: Allow you to change launcher width dimension. Value type: string. Default value : "60px"

  • launcherHeight: Allows you to change launcher height dimension. Value type: string. Default value : "60px"

  • baloonImage: Allows you to change ballon image with custom image URL. Value type: string.

  • baloonShape: Allows you to change ballon shape with custom dimension . Value type: string. Permitted values: string as top-bottom-right-left dimension, percentage dimension . Default value : "50%"

  • autoStart: Set if the widget performs an automatic anonymous authentication at the startup. Default value : true

  • startHidden: Set if the widget starts in hidden mode. Default value : false

  • persistence: You can specify how the Authentication state persists when using the Tiledesk JS SDK. This includes the ability to specify whether a signed in user should be indefinitely persisted until explicit sign out or cleared when the window is closed. Permitted values: local, session. Default value : local. Local value indicates that the state will be persisted even when the browser window is closed. An explicit sign out is needed to clear that state. Session value indicates that the state will only persist in the current session or tab, and will be cleared when the tab or window in which the user authenticated is closed.

  • showWaitTime: Show the expected response time from your agents in the home widget window. Value type : boolean. The default value is true.

  • showAvailableAgents: Show the available agents with avatar in the home widget window. Value type : boolean. The default value is true.

  • showLogoutOption: Show the logout options in the home widget window. Value type : boolean. The default value is true.

    • showAttachmentButton: Enable you to show/hide attachment button in the footer of a conversation. Permitted values: true, false. Default value: true

  • showAllConversations: Enable you to show/hide the list of all conversations. Permitted values: true, false. Default value: true

  • recipientId: Enable the widget to open a specific conversation. Value type: string

  • recipientId: Allow you to change home footer description with custom HTML code. Value type: string

  • privacyField: Allows you to change privacy field

  • dynamicWaitTimeReply: Enable you to decide whether or not to share the average response time of his team. Permitted values: true, false. Default value: true

  • openExternalLinkButton: Enable you to open or not a link in an action button externally. Permitted values: true, false. Default value: true

  • soundEnabled: Enable you to allow or not sound when new message arrived. Permitted values: true, false. Default value: true

  • isLogEnabled: Enable the widget log. Value type: boolean. The default value is false.

  • logLevel: Allows you to change the level of the log. Value type: string. Permitted values: ‘ERR’ < ‘WARN’ < ‘INFO’ < ‘DEBUG’. Default value: ‘INFO’

Example 1. Widget with user fullname and email

<script type="application/javascript">
window.tiledeskSettings =
{
projectid: "6048e8b09818900019fc6141",
userFullname: "Andrea Leo",
userEmail: "[email protected]"
};
(function(d, s, id) {
var w=window; var d=document; var i=function(){i.c(arguments);};
i.q=[]; i.c=function(args){i.q.push(args);}; w.Tiledesk=i;
var js, fjs=d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js=d.createElement(s);
js.id=id; js.async=true; js.src="https://widget.tiledesk.com/v5/launch.js";
fjs.parentNode.insertBefore(js, fjs);
}(document,'script','tiledesk-jssdk'));
</script>

Example 2. Widget with preChatForm and left alignment:

<script type="application/javascript">
window.tiledeskSettings =
{
projectid: "6048e8b09818900019fc6141",
preChatForm: true,
align: 'left'
};
(function(d, s, id) {
var w=window; var d=document; var i=function(){i.c(arguments);};
i.q=[]; i.c=function(args){i.q.push(args);}; w.Tiledesk=i;
var js, fjs=d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js=d.createElement(s);
js.id=id; js.async=true; js.src="https://widget.tiledesk.com/v5/launch.js";
fjs.parentNode.insertBefore(js, fjs);
}(document,'script','tiledesk-jssdk'));
</script>

Configuration using URL parameters

You can also pass the above configurations as a Url parameter with the tiledesk_ prefix. For example:

https://widget.tiledesk.com/v5/assets/twp/index.html?tiledesk_projectid=<YOUR_PROJECT_ID>&tiledesk_isOpen=true&tiledesk_align=right&project_name=Assistente%20Virtuale&isOpen=true

Methods

Open the widget

This will open the widget:

window.Tiledesk('open');

Minimize the widget

This will minimize the widget:

window.Tiledesk('close');

Hide the widget

This will hide the widget:

window.Tiledesk('hide');

Show the widget

This will show the widget:

window.Tiledesk('show');

Reinitialize the widget

If your app is characterized by very few page refreshes (ie., content is swapped out on the client side but no page refresh happens, Angular, React, jQuery, etc..) and lots of asynchronous JS, you'll need to update Tiledesk when your user's data changes. A reInit call simulates a page refresh, causing Tiledesk to reload the widget and all the configurations.

window.Tiledesk('reInit');

Restart the widget

This method allow you to restart widget with the same user's data without make a new authentication. This also mantein all the configurations.

window.Tiledesk('restart');

Signin with anonymously

This method make a signin anonymously

window.Tiledesk('signInAnonymous');

Signin with JWT Custom Token

This method make a signin using a JWT Custom Token as described here.

window.Tiledesk('signInWithCustomToken', customJwt);

Make a logout

This will logout the widget:

window.Tiledesk('logout');

Show callout

This will show the widget callout if it is not open:

window.Tiledesk('showCallout');

Show or hide the PreChatForm

This parameter configures the PreChatForm visibility:

window.Tiledesk('setPreChatForm', true|false);

Send a message to a support conversation

This method sends a message to the current support conversation:

const recipientId = window.tiledesk.angularcomponent.component.g.recipientId;
const recipientFullname = 'Owner';
const message = 'hello';
const type = 'text';
const metadata = {};
const attributes = {};
window.tiledesk.sendSupportMessage(
message,
recipientId,
recipientFullname,
type,
metadata,
attributes
)

Send a message to a conversation

This method sends a message to the current conversation:

const recipientId = window.tiledesk.angularcomponent.component.g.recipientId;
const message = 'hello';
const type = 'text';
const metadata = {};
const attributes = {};
const tenant = window.tiledesk.angularcomponent.component.g.tenant;
const senderId = window.tiledesk.angularcomponent.component.g.senderId;
const senderFullname = 'Guest';
const recipientFullname = 'Owner';
const additional_attributes = {};
const projectid = window.tiledesk.angularcomponent.component.g.projectid
const channel_type = "group"
window.tiledesk.sendMessage(
tenant,
senderId,
senderFullname,
message,
type,
metadata,
recipientId,
recipientFullname,
additional_attributes,
projectid,
channel_type
)

Events

window.Tiledesk(event_name, handler)

Register an event handler to an event type.

Available events:

event_name

description

onLoadParams

Fired when the parameters are loaded.

onInit

Fired when the widget is initialized

onAuthStateChanged

The event is generated when the user logs in or logs out

onOpen

Fired when the widget is open

onClose

Fired when the widget is closed

onBeforeMessageSend

Fired before the message sending.

onAfterMessageSend

This event is generated after the message has been sent.

onOpenEyeCatcher

Fired when the callout box is open

onClosedEyeCatcher

Fired when the callout box is closed

onCloseMessagePreview

Fired when the user click on close button in message preview while new message is received and widget is closed

onNewConversationComponentInit

Fired just after a new conversation is initialized

onBeforeDepartmentsFormRender

Fired just before rendering Departments in the Departments view

onMessageCreated

Fired when the widget receive a message

onNewConversation

Fired when the widget start a new conversation

onConversationUpdated

Fired when the widget receive a conversation update

Initial events lifecycle:

onLoadParams -> onInit -> onAuthStateChanged

The handler will have the signature function(event_data).

event_data is a Javascript CustomEvent. More info about CustomEvent here

Arguments:

Parameter

Type

Required

Description

event_name

String

YES

Event name to bind to

handler

Function

YES

Function with the signature function(event_data)

Example 3. Logging of widget events

<script type="application/javascript">
window.Tiledesk('onBeforeMessageSend', function(event_data) {
var message = event_data.detail.message;
console.log("onBeforeMessageSend called ", message);
});
window.Tiledesk('onAfterMessageSend', function(event_data) {
var message = event_data.detail.message;
console.log("onAfterMessageSend called ", message);
});
</script>

Load Parameters event

This event will be fired before the tiledesk parameters is loaded. Use this event to change at runtime your Tiledesk settings.

Important payload of event_data:

Parameter

Type

Description

detail.default_settings

Object

the constructor default settings

Example 4. Widget with visitor fullname and email from localStorage

<script type="application/javascript">
//set fullname to localstorage
localStorage.setItem("user_fullname", "Andrea from localStorage");
localStorage.setItem("user_email", "[email protected]");
window.Tiledesk('onLoadParams', function(event_data) {
window.tiledeskSettings.userFullname = localStorage.getItem("user_fullname");
window.tiledeskSettings.userEmail = localStorage.getItem("user_email");
});
</script>

Example 5. Widget with welcome message with current date

<script type="application/javascript">
window.Tiledesk('onLoadParams', function(event_data) {
window.tiledeskSettings.welcomeMsg = " Hello at: " + new Date().toLocaleString();
});
</script>

Before sending messsage

This event will be fired before the message sending. Use this event to add user information or custom attributes to your chat message.

Important payload of event_data:

Parameter

Type

Description

detail.message

Object

the message that is being sent

Example 6. Programmatic setting custom user metadata

<script type="application/javascript">
window.Tiledesk('onBeforeMessageSend', function(event_data) {
var message = event_data.detail.message;
message.attributes.userCompany = "Frontiere21";
});
</script>

Example 7. Add a custom attribute (page title) to the message.

<script type="application/javascript">
window.Tiledesk('onBeforeMessageSend', function(event_data) {
var message = event_data.detail.message;
message.attributes.pagetitle = document.title;
});
</script>

After messsage sent

This event is generated after the message has been sent.

Important payload of event_data:

Parameter

Type

Description

detail.message

Object

the message that was sent

Example 8:

<script type="application/javascript">
window.Tiledesk('onAfterMessageSend', function(event_data) {
var message = event_data.detail.message;
console.log("onAfterMessageSend called ", message);
});
</script>

onAuthStateChanged

This event is generated when the authentication state changed (Ex: user sign-in, user logout, etc.) Important payload of event_data:

Parameter

Type

Description

detail

Object

the auth event

Auth Event description:

Parameter

Type

Description

event

string

Possible values: 'online' when user is logged in, 'offline' when user is logged out

isLogged

boolean

Possible values: true if the user is logged, false if not logged

user_id

string

The current user identifier

global

object

An object with all the widget global parameters

default_settings

object

The initial widget config parameters (window.tiledeskSettings)

appConfigs

object

The remote widget config parameters obtained from the remote Tiledesk server

Example 9:

<script type="application/javascript">
window.Tiledesk('onAuthStateChanged', function (event_data) {
console.log("onAuthStateChanged ----> ", event_data.detail.event);
if (!event_data.detail.isLogged) {
console.log("NOT logged");
window.tiledesk.signInWithCustomToken("JWT CHANGE IT");
} else {
console.log("logged in");
}
});
</script>

onBeforeDepartmentsFormRender

This event is generated before rendering the Departments selection View. Use this event if you want to filter the default Departments list based on some conditions.

Important payload of event_data:

Parameter

Type

Description

detail.departments

Object

the array of the default Departments

Example 10:

In the following example Departments are filtered based on the current widget language. Actually a Department doesn't provide a specific "language" field. In this example Department language is put in the Department description field.

<script type="application/javascript">
window.Tiledesk('onBeforeDepartmentsFormRender', function(event_data) {
var departments = event_data.detail.departments;
var lang = window.tiledesk.angularcomponent.component.g.lang;
if (lang && lang === 'en') {
return departments.filter(function(dep) {
if (dep.description && dep.description.includes('English')) {
return dep;
}
});
} else {
return departments.filter(function(dep) {
if (dep.description && dep.description.includes('French')){
return dep;
}
});
}
});
</script>

onNewConversationComponentInit

This event is generated as soon as a new conversation view is rendered. Use this event if you want to execute some actions on a Conversation start.

Important payload of event_data:

Parameter

Type

Description

detail.newConvId

Object

the id of the conversation that fired the event

Example 11:

In the following example a hidden message is sent as soon as a conversation starts. Sending a hidden message is useful to fire a bot welcome message, if one is invited in the conversation.

<script type="application/javascript">
window.Tiledesk('onNewConversationComponentInit', function(event_data) {
const message = 'hello';
const recipientId = event_data.detail.newConvId;
const recipientFullname = 'Owner';
const type = 'text';
const metadata = {};
const attributes = {test:'test attributes', subtype: 'info'};
window.tiledesk.sendSupportMessage(
message,
recipientId,
recipientFullname,
type,
metadata,
attributes
)
});
}
</script>

onMessageCreated

This event is generated when the widget receive a message.

Important payload of event_data:

Parameter

Type

Description

detail

Object

the message that was received

Example 12:

<script type="application/javascript">
window.Tiledesk('onMessageCreated', function(event_data) {
var message = event_data.detail;
console.log("TRIGGER onMessageCreated -> ", message);
});
</script>

onConversationUpdated

This event is generated when the widget receive a conversation update.

Important payload of event_data:

Parameter

Type

Description

detail

Object

the conversation that was received

Example:

<script type="application/javascript">
var now = Date.now();
window.Tiledesk('onConversationUpdated', function(event_data) {
var dateConvUpdate = event_data.detail.conversation.timestamp
console.log(" TRIGGER onConversationUpdated -> ", event_data.detail.conversation);
console.log("now-> ", now);
console.log("dateConvUpdate-> ", dateConvUpdate);
if(now < dateConvUpdate){
console.log(" New conversation!!!");
}
});
</script>

Enabling authenticated visitors in the Chat widget

You can configure your widget to authenticate visitors using the Javascript API and JWT token. More info Widget Authentication