This article explains how to set up and use the integration between your bot and Bitrix24, and what it can do.
Connecting

1. Log in or sign up to Bitrix24 and copy the link to your Bitrix24 account, for example: https://*******.bitrix24.ru/

2. Go to the integration settings in your puzzlebot account: Bot — Settings — Integrations — Bitrix24 — Set up integration.

3. Paste the copied link to your Bitrix24 account into the input field in step one and click "Save".


4. Use the button in step two or the link https://www.bitrix24.ru/apps/app/puzzlebot.puzzlebot/ to go to your Bitrix24 account and install the puzzlebot app.

5. When the installation finishes, the app window shows the result of linking the accounts.

6. Go back to your puzzlebot account and click "Continue".

7. Specify the fields and variables for storing the user's Telegram User ID and Name, or leave everything as is, and click "Connect integration".
Settings
Let's go through the integration settings tab by tab.
Important! All actions with contacts, leads and deals are based on the user's Telegram User ID. If this field is changed in Bitrix24, the action will not be performed.
Contacts
On this tab you can:
Set up synchronization between Bitrix24 contacts and your bot's users.
Add bot users to Bitrix24 clients as a one-time operation.
Add Bitrix24 clients to bot users as a one-time operation.

Before any of the actions above, link puzzlebot variables to contact fields in Bitrix24.
You can enter names of fields that don't exist yet, and they will be created automatically.
Important! While synchronization is active, linked variables and fields keep each other up to date wherever the change is made: if you change a value in a Bitrix24 field, the value of the puzzlebot variable changes too, and vice versa. Links marked with arrows are the exception.

To activate synchronization, click the corresponding button. Synchronization stays active until you cancel it or change the link to your Bitrix24 account.
Deals and Leads

Final stages / statuses — this setting defines from which stage or status the system may ignore deals and leads.
Example: a check for an existing deal returns a negative answer if the deal has moved to a final stage.
Several Deals / Leads from one user — allows creating 2 or more Deals / Leads from one user.
Ignore Deals / Leads in a final stage / status — works together with the final stages setting and turns ignoring on or off.

Stage / status change notification — lets you set up sending a command when a Deal / Lead moves from one stage / status to another.
Important! When the Ignore Deals / Leads in a final stage / status function is enabled, no notification is sent for final stages / statuses.
Actions
Here are the actions available for working with Bitrix24.

Deals and Leads
The following types are available:
Create lead / deal
Change lead / deal field
Change lead / deal status
Delete lead / deal
Most settings are self-explanatory, so let's look at the special ones:

Write to field — writes the value specified on the puzzlebot :// side to the specified field of the lead or deal. On the puzzlebot :// side, the input line can contain text, a number, a formula or a variable.
Important! You can't write to lead or deal fields that don't exist.

Link to user — defines what is specified in the lead / deal information: a contact or the user's Telegram User ID.
Important! If you choose "By contact", the contact must already exist in Bitrix24. With active synchronization this is done automatically.

Active lead / deal — defines which lead or deal to work with. Relevant when the "Several leads / deals from one user" function is enabled in the settings.
Contact
The following types are available:
Create contact
Delete contact
Checks
Here are the checks available for working with Bitrix24.

Deals and Leads
The following types are available:
Lead / deal exists
Lead / deal status
Lead / deal field value
Contacts
The following types are available:
Contact exists
Contact field value