💻 Examples of Jinja Codes to Use in the Data Manipulation Step
In this section, you'll find useful code snippets for handling data during the manipulation step. Whether you're filtering, transforming, or restructuring data, these examples will help you efficiently manipulate data in your chatbot workflow to meet your specific needs.
Scenario 1: You have one widget per brand, and you want to display the brand name dynamically.
Example:
Inputs: user_channel_uuid
{# Step 1: Create a dictionary with user_channel_uuid as the key and brand name as the value #}
{% set customer_channels = {
"b0cd1aea-9261-451a-b9dc-03af43b7rez3": "Brand name 1",
"b100fdg8f-cf91-4739-9f3a-f7f99cezea3": "Brand name 2",
"0da48933-gddg-4f9e-aa2b-7639528512a2": "Brand name 3",
"28az234e-bacf-4995-8639-f8f4dbd139f2": "Brand name 4"
} %}
{# Step 2: Use the dictionary to get the brand name, return 'unknown brand' if no match is found #}
{% set brand_name = customer_channels[user_channel_uuid] or "unknown brand" %}
{# Step 3: Set the output to brand_name #}
Output: brand_name
Scenario 2: Set Up a Counter
You can use this method when you need to track the number of times a user goes through a step, for example, to avoid repeating the same action too many times or to limit retries.
Example:
Input: count
{# If the counter is already defined, increment it by 1 #}
{% if count is defined %}
{% set count = count|int + 1 %}
{% else %}
{# If not defined, initialize the counter at 0 #}
{% set count = 0 %}
{% endif %}
Output: count