How to calculate the data size of customAttributes

A customer of mine wants to build a web message in a script that they embed in their website by defining customAttributes in the following format. The variables (url/title/bot/areaName/shopName) are assigned the text information required when sending a web message.

Genesys("command", "Database.set", {
  messaging: {
    customAttributes: {
      URL: url,
      Title: title,
      Bot: bot,
      AreaName: areaName,
      ShopName: shopName
    }
  }
});

From the information below, I understand that customAttributes have a 2KB transmission limit.
https://developer.genesys.cloud/commdigital/digital/webmessaging/messengersdk/pluginExamples#define-and-send-custom-attributes

Isn't there a way to calculate the size of data sent as customAttributes? No error is displayed on the screen even if the 2KB limit is exceeded, so I don't know that the transmission failed. So I want to check if it exceeds 2KB before sending.

Hi tak_ueno,

As part of the inbound message logic there is a text encoder used to determine if the 2kb limit is exceeded. If it is, you will not see the message as sent or appearing in Messenger. As a rule of thumb, 2,000 characters will roughly equal 2kb, though there could be some slight variation.

Hi chad.hansen,

Thank you for your reply.
Does that mean there is no way to know the detailed data size of customAttributes in advance?

That's correct, we don't provide any native way for that.

Thank you for your reply again.
Is there a way to catch the error in my code if the message could not be sent due to the 2KB limit of customAttributes?
The following page describes how to debug by logging, but I don't know how to determine an error immediately after a transmission failure.
https://developer.genesys.cloud/commdigital/digital/webmessaging/messengersdk/genesysgf

Hi tak_ueno,

We've made a few minor changes in this area. In cases where customAttributes are 2048 bytes or less, the message will send through successfully. If denied due to exceeding 2048 bytes, there will be a websocket error. This should help solve your issue!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.