Instagram Bot Development with Bitrix24 Integration
Manual handling of Instagram Direct messages can take up to 3 hours a day. Each message requires reading, responding, and manually entering into CRM. As lead flow grows, managers simply can't keep up, and some leads are lost. We automate this process: the bot responds according to scenarios, qualifies leads, and passes them to Bitrix24. The manager works with the client from CRM without switching windows. Our team has 10+ years in Bitrix24 development and external API integrations, with dozens of integrations for e-commerce, services, and manufacturing. Automation cuts response time from 30 minutes to 5 seconds (10x faster than manual), and the bot handles up to 80% of routine questions. Every lead enters the CRM automatically, eliminating losses. Typical cost for such integration ranges from $2,000 to $5,000, and clients see an average of 30% reduction in support costs, saving $10,000 per year.
| Parameter | Manual Processing | Automation |
|---|---|---|
| Response time | ~30 minutes | 5 seconds |
| Percentage of requests handled | 50% (managers overwhelmed) | 80%+ |
| CRM entry | Manual (errors, delays) | Automatic, real-time |
| Cost per lead | High (manager salary) | Low (server subscription) |
Technical Requirements and Limitations of Instagram Messaging API
Instagram Messaging API works through the Meta platform. To get started you need:
- Instagram Business or Creator account linked to a Facebook page.
- Facebook Developer App with Messenger + Instagram products.
- Permissions:
instagram_basic,instagram_manage_messages,pages_manage_metadata. - HTTPS server for webhook.
Official Meta for Developers documentation highlights key limitations:
- Bot messages are only accepted within 24 hours of the user's last message.
- The bot cannot initiate a conversation.
-
instagram_manage_messagesrequires Meta app review. - Bulk messaging is prohibited.
Webhook setup details
When receiving a webhook event, the server must respond 200 OK. The request contains a JSON with fields sender.id (IGSID) and message.text.
{ "entry": [{ "id": "IG_ACCOUNT_ID", "messaging": [{ "sender": { "id": "IG_USER_IGSID" }, "recipient": { "id": "IG_ACCOUNT_ID" }, "timestamp": 1710000000000, "message": { "mid": "aWdfZAG9...", "text": "How much is delivery?" } }] }] } IGSID is a unique user ID within your app. The profile is retrieved via Graph API: https://graph.instagram.com/{igsid}?fields=name,username&access_token=.... It returns name and @handle, but not email or phone.
Message Processing Flow
Receiving Messages via Webhook
Code for receiving and processing webhook (same as above).
Retrieving the Instagram User Profile
$profile = json_decode(file_get_contents( "https://graph.instagram.com/{$igsid}?fields=name,username&access_token=" . IG_ACCESS_TOKEN ), true); // Returns: name (display name), username (@handle) This approach is lightweight but does not provide email or phone. We obtain that data through a qualification scenario.
Interaction Scenarios: Automatic Replies and Ice Breakers
Auto-Reply to Story Mentions
When your account is mentioned in Stories, a webhook event messaging_referral with type=STORY_MENTION arrives. The bot can automatically thank:
if ($event['type'] === 'STORY_MENTION') { sendIgMessage($igsid, "Thanks for mentioning us in your Story! 🙌 Want to learn about current promotions?"); logLeadSource($igsid, 'story_mention'); } Story mentions are warm leads: the user has already interacted with the brand.
Ice Breakers: Questions on First Dialog Open
Via the app API you can set prompts that the user sees when first opening a dialog with the business account:
callMetaApi('me/messenger_profile', 'POST', [ 'platform' => 'instagram', 'ice_breakers' => [ ['call_to_actions' => [ ['type' => 'postback', 'title' => 'Learn about delivery', 'payload' => 'DELIVERY_INFO'], ['type' => 'postback', 'title' => 'Submit a request', 'payload' => 'LEAVE_REQUEST'], ['type' => 'postback', 'title' => 'View catalog', 'payload' => 'CATALOG'], ]], ], ]); Ice breakers reduce first response time and increase conversion.
Integration with Bitrix24
Lead Qualification Scenario
- Incoming message.
- If no state exists — greeting + quick replies.
- On selecting "I want to order" — request phone/email.
- Create a lead in Bitrix24 and notify the manager.
- Reply: "A manager will contact you within an hour."
Dialog states are stored in Redis with key ig_dialog:{igsid}. TTL is 24 hours (Instagram activity window).
Bitrix24 REST API: Creating Leads and Activities
The integration is implemented using Bitrix24's REST API:
function createInstagramLead(string $igsid, string $username, array $data): int { return $b24->callMethod('crm.lead.add', [ 'fields' => [ 'TITLE' => "Instagram: @{$username}", 'SOURCE_ID' => 'WEBFORM', 'SOURCE_DESCRIPTION' => 'Instagram Direct', 'PHONE' => !empty($data['phone']) ? [['VALUE' => $data['phone'], 'VALUE_TYPE' => 'WORK']] : [], 'EMAIL' => !empty($data['email']) ? [['VALUE' => $data['email'], 'VALUE_TYPE' => 'WORK']] : [], 'COMMENTS' => "Instagram: @{$username}\nIGSID: {$igsid}", 'UF_CRM_IG_IGSID' => $igsid, ], ])['result']; } // Conversation history as an activity $b24->callMethod('crm.activity.add', [ 'fields' => [ 'OWNER_TYPE_ID' => 1, 'OWNER_ID' => $leadId, 'TYPE_ID' => 4, 'SUBJECT' => "Instagram Direct: @{$username}", 'DESCRIPTION' => implode("\n", $dialogMessages), ], ]); The lead is assigned source "Instagram Direct", allowing channel effectiveness tracking.
Benefits of Automating Instagram Direct
On one project for an e-commerce client, we reduced average response time from 30 minutes to 5 seconds and automated 80% of incoming questions. Automation unloads managers and ensures every lead enters the CRM without manual entry, eliminating loss. Managers continue the dialog from Bitrix24, seeing the full chat history. The cost per lead decreases, and conversion to deal increases.
How We Speed Up Meta Review
Experienced developers prepare documentation and a test account in advance: we provide scenario screenshots and bot operation videos. This cuts verification to 3–5 business days. We ensure your bot complies with platform policies — review passes on the first attempt.
Timeline and Cost
| Stage | Duration |
|---|---|
| Meta App setup, IG Business, webhook | 1–2 days |
| Bot scenario, states, ice breakers | 3–4 days |
| Bitrix24 integration: leads, activities, notifications | 2–3 days |
| Story mention auto-reply | 1 day |
| Meta review (instagram_manage_messages) | 3–7 business days |
| Testing | 1–2 days |
Total: 2–3 weeks including Meta review. Typical investment: $2,000–$5,000, with average annual savings of $10,000.
What's Included in the Work
- Architecture design and dialog flow.
- Webhook server deployment and HTTPS setup.
- Implementation of all scenarios (ice breakers, qualification, story mentions).
- Bitrix24 integration via REST API (leads, activities, notifications).
- API documentation and manager instructions.
- Assistance with Meta review.
- Testing and debugging in sandbox.
- Code warranty and post-launch support.







