Before adding actions, plug [**Google Sheets**](<../../integrations/other-integrations/Google Sheets.md>), add a table, select a sheet and set up columns.

In the current version of ChatRex, four Google Sheets actions are available:

1. **Add a line**.
2. **Update the line**.
3. **Find the lines**.
4. **Receive a line by key**.

## Add a line

Add a new line to the end of the selected page.

Adjustment:

1. Select the connected **Table**.
2. Check the selected **Sheet from the table**.
3. In the data block, select **Field**.
4. Specify **Value** - fixed text or data from a variable bot.
5. Press **Add the field** to write the remaining values.
6. If necessary, enable automatic date and time recording.

You cannot save the action without a filled field and value. One column should not be added to the form twice.

Example: After a lead qualification, the bot writes the name, phone, service, and dialog summary into a new line.

## Update the line

Searches for a row by key column and updates specified fields. This action replaces the previous separate versions of **Update** and **Upsert**.

Adjustment:

1. Select a table.
2. Check **Key field** - it is taken from the setting of the columns and does not change in the action card.
3. Send **The value of the key**, such as phone number or order number.
4. Add fields and new values.
5. Select behavior if a line is not found:
   - do nothing;
   - create a new line.

The key column cannot be updated among conventional fields. If you need to change the key itself, use a different process or create a new string.

Example: Find a customer by phone and record a new status. If you don't have a client yet, create a string with that phone and the rest of the data.

## Find the lines

Searches for several lines on the specified column and returns the result to the bot list.

Adjustment:

- **Search field**
- **Value** - text or variable
- coincidence
  - **Contains** - Suitable for part of the title or description
  - **Exact** - the value must be the same.
- maximum number of lines;
- fields to be returned to the bot.

By default, the number of results is limited. Do not return all columns unnecessarily: select only the data you need to answer or take the next action.

Example: find up to five services whose name contains a user request and return the name, price and description.

## Get a line by key

Returns one line with a unique key.

Adjustment:

1. Select a table.
2. Specify the value of the configured key field.
3. Select columns for return.

If the string is not found, the action returns the result without data. In the prompt, provide a separate response: ask the user to check the value, perform a normal search, or offer to contact an employee.

Example: find the order by number and return to the client its status, amount and date of renewal.

## Data types

ChatRex uses types defined according to columns:

- The phone is brought to a single format;
- the number is processed as a numerical value;
- the date and date shall be transmitted over time in an agreed format;
- Text and email are recorded in the corresponding columns.

Check the variable format before calling an action. This is especially important for the phone, date, amount and key values.

## Example of instructions for a bot

> When the user left the name and phone and confirmed the submission of the application, call the action “Add a request to Google Sheets”. Transmit the name in the `client_name` field, the phone in `client_phone`, the selected service in `service`. After successful recording, inform that the application has been accepted. Do not repeat the action within one appeal.

For update:

> If a user with a known phone reported new data, call “Update Customer in Google Sheets”. Find the line on the phone and change only the received fields. If the string is not found, create a new one only after the user confirms.

## Verification

Before launching, check:

- adding a new line;
- updating the existing line by key;
- behavior with the missing key;
- search with exact and partial coincidence;
- lack of results;
- call again so that the bot does not create doubles.

!!!warning
Actions change the real Google table. First check on a separate test sheet.
!!!
