Assign variables

This component is similar to the Assign variable component. If you haven't read about Write Variable yet, you need to read this article first.

The component:

  1. Writes values to variables without waiting for a message from the bot user.
  2. Allows you to create multiple variables in one component at once.
  3. Writes variables with a specific data type.
  4. Assembles several variables into an object.
  5. Adds the created object to the beginning, end, or to a known position in the lists.

The main difference from the Write Variable component is that it allows you to create several variables in one component at once.

This component also allows you to immediately collect these variables into one object and save it as a single, separate variable.

This component does not allow you to add individual variables to lists through list management, but if the variables have been collected into an object, you can write this object to the list.

Assemble into an object

If you enable this property, you can specify Object name. In this case, Botmother will collect all the variables that you create in the component and write them into one object, and you will get nested variables.

This is convenient if you need to group variables together by some attribute.

For example, save a user profile and view it in variables.

You can assemble Request body to a third-party service. If you are familiar with API requests, the example below should be clear to you.

An object named body and nested variables token and prompt will be written to the variables.

In JSON, the result of this component will look like this:

      "body":  {
           "token": "12345:12fd3b6a2c1234c7a9876b2",
           "prompt": "What was written in the user_prompt variable"

Now you can use this object in the Request component using the stringify helper:

Of course, you can write the template to Request Body manually:

      "token": "12345:63fd3b6a2c8097c7a45891b2",
      "prompt": "{{user_prompt}}"

But if there is a line break in user_prompt or another character invalid for a string in JSON, the request will probably fail with an error, because the receiving server will not be able to understand JSON, because it will be with an error.

In the case of an Object Assembly, you can be sure that a valid JSON will be formed in the body, and not worry about line breaks or other invalid characters that could be in the user_prompt variable.

Rewrite object

This property is enabled by default.

When it is enabled, Botmother creates a new object when assembling the object and overwrites any variable value that is located by the Name of the object.

If you turn it off, Botmother will check if there is already some other object by the Name of the object, and if so, it will merge these objects together. Variables from the newly assembled object will be written on top of the object that is already in the variables. At the same time, properties that are not in the new object will remain in the old object and will not be deleted.

List Control

In the Write Variables component, List Control generally works similar to List Management in the Write Variables component.

A significant difference is that in the Write Variables component, List management is available only if the Assemble to Assemble into an object.

At the same time, if you enable List Management, the name of the variable in which Botmother will search for the list will be taken from the Object Name property, and not the name of a separate variable, as it is done in the Write Variable component.

Otherwise, the principle of creating or changing lists is exactly the same as in the Write Variable component component.

To the beginning ↑