πŸ” How to pass encrypted data through the integration script?

Before you start, make sure you’ve followed the encryption setup process.

πŸ–οΈ

Need help with encryption?

Follow this step-by-step guide to encrypt and decrypt data in your widget script.

🧩 Step 0 β€” Add encrypted data to your script

Once your encryption keys are generated, update your widget script to include the encrypted variable, like this:

<script>
            var widget = document.createElement("destygo-webchat");
            widget.setAttribute('id', "destygo_widget");
            widget.setAttribute('class', "destygo_widget");
            widget.setAttribute('encrypted_user_id', 'xJICFuyE77I/VoTi2b2iuWRZvWqN');
            widget.setAttribute('token', "51ffba0c-2d25-052e-f919-27d9b2c216d9");
            document.body.appendChild(widget);
</script>

We add the encrypted_user_id variable with its encrypted string value as a key-value pair in the widget script. You can also pass a variable that contains this encrypted value.

🧰 Step 1 β€” Create an API and connect it to your use case

  1. Go to INTEGRATE β†’ API in the ViaSay platform sidebar.
  2. Click Create API and give it a clear, descriptive name.

🚨

Tip: Use naming conventions to stay organized.

For example:

[AUX] for auxiliary APIs

[KB] for knowledge base-related APIs


  1. In your Bot Action, add the API and define:
    • an input variable called encrypted_user_id
    • an output variable called decrypted_user_id
  1. Open the API details and set it as an external API to complete this step

πŸ§ͺ Step 2 β€” Create the extractions

  1. Go to the Extraction tab in your API configuration.
  2. Create a new extraction for the variable decrypted_user_id

Here’s an example of the extraction code you can use:

{% if encrypted_user_id is defined %}
    `{{encrypted_user_id|decrypt("Odjts2S6KkfjnMPl3e0zPyjb3EAkKWf9", "U0kFxO/5SJKiEAqWvZwGsW15ZRKY+Qxq", 'NACL') | safe}}`
    {% endif %}
    
    
      # Details on decrypt(key, iv, 'NACL') -> 
    # The key and iv parameters are specific values generated for each decryption key created
    # They were generated in the previous steps and passed in our JSON for future reference

In our example, we're decrypting the user name "Chuck", which was passed as an encrypted value in the widget variables.

  1. Once decrypted, the value stored in decrypted_user_id can be reused to replace other user input variables in your bot flow.
  1. Next, add a condition in your bot flow to check if the decryption was successful.

βœ… Step 3 β€” Let’s test your solution!

Now that everything is set up:

  1. Load your webpage that contains the widget script with the encrypted data.
  2. Trigger the bot and check if the decrypted value (e.g. the user's name) is correctly recognized and used in the conversation.
  3. Confirm that the bot behaves as expected based on the decrypted variable.

πŸŽ‰ Congratulations!

You’ve successfully learned how to encrypt and decrypt variables in your chatbot, and how to pass encrypted data through the widget script securely.

Your bot is now smarter, safer, and ready to deliver a more personalized experience!