Programmatic access

Once the script tag that loads web chat finished, you can control it using the webchattonic global variable, to modify its behavior.

The following is a list of all the current possibilities.

Open/Close window

Use webchattonic.toggleContainer() to open/close the web.
You can also use webchattonic.openContainer() or webchattonic.closeContainer() to open or close the web chat respectively.

Notification counter

Use webchattonic.emitBadge() to show a badge with a number of "notifications" to lure the users into opening the web chat window (this can also be set to do automatically after a few seconds every time for every user)

Making sounds

Use webchattonic.emitSound(ARRAY) to play a sound, the method receives an array of urls of sounds with different formats so that it can be played in different browsers. (Supports: mp3, mp4, ogg and wav) (this can also be set to do automatically after a few seconds every time for every user)

Show help message to the user

Use webchattonic.emitMessage(TEXT) to display a text next to the launcher button of the web chat

Disappear help message

Use webchattonic.cleanMessage() to dissapear the message that we showed with the previous function

Issue notification

Use webchattonic.addNotification(CONFIG) to send a "notification" that is generated by adding the badge, emitting sound, showing a message and cleaning that message after a while according to the config we pass it.

The config is a JSON of this style:

1 2 3 4 5 6 { message: 'Hello, how can I help you?', (STRING or BOOLEAN) sound: true, (ARRAY or BOOLEAN) cleanIn: 3000, (NUMBER (milliseconds)) count: true (BOOLEAN) }

If the message is a string I show that message, if I don't show by default "How can I help you?", unless the parameter has not been specified, that is false

If sound is an array equal to the one we would pass to emitSound() those sounds are reproduced, if I don't reproduce a sound by default, unless the parameter has not been specified, that is false

Yes message was specified, cleanIn is specified and is a number the text message will be cleared in that amount of milliseconds, if it is not kept visible until the chat is opened or another notification with text is created.

If count is true is displayed and/or one is added to the notification counter.

Send message as user

Use webchattonic.sendMessage(TEXT) to send a message as the user, in the web chat window, to notify the bot of doing something in particular

Change the current context

Use webchattonic.updateContext(context) to update the current web chat context, that then triggers (optionally) a change context flow to be handled by the bot, and sets the context to be sent in each subsequent message by the user. See https://mobile-tonic.atlassian.net/wiki/spaces/CTP/pages/379748357 for more information on what it does.

1 2 3 4 5 6 7 8 9 document.addEventListener('readystatechange', function(event) { if (event && event.target && event.target.readyState === 'complete') { setTimeout(function() { if (webchattonic) { webchattonic.updateContext('new context'); } }, 3000) } })

Change the user’s metadata

Use webchattonic.updateMetadata(metadata) to update the user’s metadata information. See https://mobile-tonic.atlassian.net/wiki/spaces/CTP/pages/379748357 for more information on what variables are allowed to be sent.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 document.addEventListener('readystatechange', function(event) { if (event && event.target && event.target.readyState === 'complete') { setTimeout(function() { if (webchattonic) { var metadata = { firstName: 'Name', lastName: 'Lastname' 'profile.id': 'Some external id' } webchattonic.updateMetadata(metadata); } }, 3000) } })

Reset the conversation

Use webchattonic.resetConversation() to reset the current conversation, that will generate a new conversation as a new user. It is important to note that the user will be expired and cannot be recontacted.

1 2 3 4 5 document.addEventListener('logout', function(event) { if (event && event.target && event.target.readyState === 'complete' && webchattonic) { webchattonic.resetConversation(); } })