How is it possible to add a custom attribute to the web widget?

Hello Tildesk,
is it possible to add a custom attributes during a conversation or before it starts ?

Hi Daniel, of course!!
You can do both.

  1. Set custom attributes as settings property (before conversation starts)
    Set a custom attributes require only to add a key/value object as value of customAttributes tiledesk property in tiledeskSettings object or tiledesk_customAttributes url parameter. Use double quotes for each key and value.
    As an example view this code on the docs: https://developer.tiledesk.com/widget/attributes#example-3.-widget-with-custom-attributes

  2. Set customAttributes programmatically (during converstion)
    in this case, you can subscribe to a tiledesk event named ā€˜onBeforeMessageSentā€™ to add programmatically a custom attributes. Then you can add your custom attributes as attributes.payload property value. Code below show you an example

window.tiledesk.on('onBeforeMessageSend', function (event_data) {
          console.log('event OnBeforeSendMessage', event_data)
          var message = event_data.detail.message
          message.attributes.payload = {
            "user_country": "Italy", 
            "user_code": "E001",
          }
});
1 Like