### Private Integration Setup - Fetch Leads Source: https://context7.com/context7/developers_kommo_com-docs-kommo-for-developers/llms.txt Demonstrates how to set up a private integration using a long-lived token and fetch lead data from the Kommo API. ```APIDOC ## GET /api/v4/leads ### Description Fetches a list of leads from the Kommo CRM account. ### Method GET ### Endpoint /api/v4/leads ### Parameters #### Query Parameters - **access_token** (string) - Required - The long-lived access token for authentication. ### Request Example ```javascript const KOMMO_DOMAIN = 'yoursubdomain.kommo.com'; const ACCESS_TOKEN = 'your_long_lived_token_here'; fetch(`https://${KOMMO_DOMAIN}/api/v4/leads`, { method: 'GET', headers: { 'Authorization': `Bearer ${ACCESS_TOKEN}`, 'Content-Type': 'application/json' } }) .then(response => response.json()) .then(data => console.log(data._embedded.leads)) .catch(error => console.error('Error:', error)); ``` ### Response #### Success Response (200) - **_embedded** (object) - Contains the list of leads. - **leads** (array) - An array of lead objects. - **id** (integer) - The unique identifier for the lead. - **name** (string) - The name of the lead. - **price** (integer) - The price associated with the lead. #### Response Example ```json { "_embedded": { "leads": [ { "id": 12345, "name": "John Doe", "price": 1000, "_links": { "self": { "href": "https://yoursubdomain.kommo.com/api/v4/leads/12345" } } } ] }, "_links": { "self": { "href": "https://yoursubdomain.kommo.com/api/v4/leads" } } } ``` ``` -------------------------------- ### SalesBot Scenario Definition Source: https://context7.com/context7/developers_kommo_com-docs-kommo-for-developers/llms.txt An example structure for defining a SalesBot scenario, including triggers, messages, user input handling, and the invocation of custom actions. ```APIDOC ## SalesBot Scenario Definition ### Description This outlines a typical Kommo SalesBot scenario configuration. It defines how the bot interacts with users, when it's triggered, how it collects information, and how it calls custom actions to perform specific tasks like checking order status. ### Method Not Applicable (Configuration Object) ### Endpoint Not Applicable ### Parameters #### Request Body - **name** (string) - Required - The name of the SalesBot scenario. - **trigger** (object) - Required - Defines what initiates this scenario. - **type** (string) - Required - The type of trigger (e.g., 'message_contains'). - **keywords** (array) - Required if type is 'message_contains' - An array of keywords that trigger the bot. - **steps** (array) - Required - An array of objects defining the conversation flow. - **type** (string) - Required - The type of step (e.g., 'message', 'wait_for_input', 'custom_action'). - **text** (string) - Required for 'message' type - The message text to send to the user. - **variable** (string) - Required for 'wait_for_input' type - The name of the variable to store user input in. - **action_id** (string) - Required for 'custom_action' type - The ID of the custom action to execute. - **parameters** (object) - Required for 'custom_action' type - An object mapping parameter names to their values (can use variables like {{variable_name}}). ### Request Example ```json { "name": "Order Support Bot", "trigger": { "type": "message_contains", "keywords": ["order", "delivery", "tracking"] }, "steps": [ { "type": "message", "text": "I can help you check your order status. Please provide your order number." }, { "type": "wait_for_input", "variable": "order_id" }, { "type": "custom_action", "action_id": "check_order_status", "parameters": { "order_id": "{{order_id}}" } } ] } ``` ### Response #### Success Response No direct response to this definition, but successful definition allows the scenario to be activated. #### Response Example N/A ``` -------------------------------- ### Kommo Widget Development Example - JavaScript Source: https://context7.com/context7/developers_kommo_com-docs-kommo-for-developers/llms.txt This snippet demonstrates the structure and functionality of a Kommo widget. It includes a manifest file (`manifest.json`) for configuration and a JavaScript file (`script.js`) for widget logic. The JavaScript code showcases initialization, binding actions to different CRM locations (like lead cards), handling settings, and interacting with Kommo's API to fetch data and display notifications. ```javascript // Widget manifest.json { "name": "widget.example", "version": "1.0.0", "title": "Example Integration", "description": "Sample widget demonstrating SDK capabilities", "settings": { "client_id": "your-client-id", "client_secret": "your-client-secret" }, "locations": [ "leads/list", "leads/card", "contacts/card", "settings" ] } // script.js - Widget implementation (function() { var widget = { callbacks: { // Widget initialization init: function() { console.log('Widget initialized'); // Get current user info var currentUser = AMOCRM.constant('user'); console.log('Current user:', currentUser); return true; }, // Bind actions to widget locations bind_actions: function() { // Add custom button to lead card this.add_action('leads/card', function() { var leadId = AMOCRM.data.current_card.id; console.log('Lead card opened:', leadId); // Create custom button var $button = $('