Skip to main content

Python SDK for Bitrix24 bots via VibeCode API — async framework like aiogram

Project description

vibecode-b24-bot

Python SDK for Bitrix24 bots via VibeCode API.

Async bot framework like aiogram, but for Bitrix24. Plus CRM/tasks/entities client.

Install

pip install vibecode-b24-bot

Getting your API key

  1. Go to your Bitrix24 portal (e.g. https://your-company.bitrix24.ru)
  2. Open VibeCode section: https://your-company.bitrix24.ru/vibe/
  3. Navigate to API-ключи (API keys)
  4. Click Создать API-ключ (Create API key)
  5. Select required permissions (at minimum: imbot for bots, crm for CRM, tasks for tasks)
  6. Copy the key — it looks like vibe_api_xxxxxxxxxxxxx

Note: Your portal needs an active subscription or demo mode for REST API to work. Enable demo for free on the portal's main page.

Quick start

1. Create your bot

# bot.py
import os
from vibecode_b24_bot import Bot, bb

bot = Bot(
    api_key=os.environ["VIBE_API_KEY"],
    bot_code="my_bot",
    bot_name="My Bot",
)

@bot.on_message
async def handle(msg):
    await msg.typing("thinking")
    await msg.answer(f"You said: {bb.bold(msg.text)}")

@bot.on_command("help")
async def help_cmd(msg, cmd):
    await msg.answer("I'm a bot!")

bot.run()

2. Run it

export VIBE_API_KEY=vibe_api_your_key_here
python bot.py

The bot will:

  • Register itself in your Bitrix24 portal
  • Start polling for messages
  • Appear in the messenger as "My Bot"

Open your Bitrix24 messenger, find the bot, and send a message!

3. Run with Docker

# Copy your bot file
cp examples/echo_bot.py bot.py

# Run with docker-compose
VIBE_API_KEY=vibe_api_xxx docker-compose up -d

# Or with plain docker
docker build -t my-b24-bot .
docker run -d --restart unless-stopped \
  -e VIBE_API_KEY=vibe_api_xxx \
  my-b24-bot

Features

  • Bot framework with decorators (@bot.on_message, @bot.on_command)
  • Async polling with auto offset tracking, deduplication, exponential backoff
  • 35 entities — deals, contacts, tasks, users, calendar, disk, etc.
  • Batch API — 50 calls in 1 request
  • BB-code formattingbb.bold(), bb.italic(), bb.code(), bb.link()
  • Typing indicators — 11 statuses (thinking, searching, generating...)
  • Chat management — create chats, manage users, slash-commands
  • File upload/download
  • Zero config — just API key and bot.run()

Bot types

# Standard bot — responds to @mention and direct messages
Bot(api_key=key, bot_type="bot")

# Personal AI assistant — sees ALL messages in chats it's in
Bot(api_key=key, bot_type="personal")

# Supervisor/observer — for monitoring, analytics, moderation
Bot(api_key=key, bot_type="supervisor")

Formatting (BB-codes)

Bitrix24 chat uses BB-codes, not Markdown:

from vibecode_b24_bot import bb

bb.bold("important")          # [b]important[/b]
bb.italic("note")             # [i]note[/i]
bb.code("x = 1")             # [code]x = 1[/code]
bb.link("https://...", "Go")  # [url=https://...]Go[/url]
bb.strike("old")              # [s]old[/s]
bb.quote("cited text")        # [quote]cited text[/quote]
bb.list(["a", "b", "c"])     # [list][*]a[*]b[*]c[/list]
bb.mention(user_id=42)        # [user=42][/user]

Message object

@bot.on_message
async def handle(msg):
    msg.text          # message text
    msg.dialog_id     # chat/dialog ID
    msg.from_user     # User object (id, name, email)
    msg.message_id    # message ID
    msg.chat          # Chat object (id, name, type)

    await msg.answer("reply")         # send reply
    await msg.typing("thinking")      # show typing indicator
    await msg.react("like")           # add reaction

Typing statuses

await msg.typing("thinking")     # Agent is thinking...
await msg.typing("searching")    # Agent is searching...
await msg.typing("generating")   # Agent is preparing answer...
await msg.typing("analyzing")    # Agent is analyzing...
await msg.typing("processing")   # Agent is processing data...
await msg.typing("translating")  # Agent is translating...
await msg.typing("reading")      # Agent is reading documents...
await msg.typing("composing")    # Agent is composing answer...

Low-level client (CRM, tasks, entities)

import asyncio, os
from vibecode_b24_bot import VibeCode

async def main():
    async with VibeCode(api_key=os.environ["VIBE_API_KEY"]) as client:
        # Entity CRUD (35 entities: deals, contacts, tasks, users, etc.)
        await client.list_entity("deals", limit=50)
        await client.get_entity("deals", 123)
        await client.create_entity("deals", title="New deal", amount=50000)
        await client.update_entity("deals", 123, stageId="WON")
        await client.delete_entity("deals", 123)
        await client.search_entity("deals", filter={"stageId": "NEW"})

        # Batch — 50 calls in 1 request (1 rate-limit unit)
        await client.batch([
            {"method": "crm.status.list"},
            {"method": "crm.deal.fields"},
        ])

        # Direct Bitrix24 method call
        await client.call("app.info")

        # Portal info
        await client.me()

asyncio.run(main())

AI assistant example

Connect any OpenAI-compatible LLM (Ollama, vLLM, OpenRouter, etc.):

export VIBE_API_KEY=vibe_api_xxx
export LLM_BASE_URL=http://localhost:11434/v1
export LLM_MODEL=llama3
python examples/ai_assistant.py

See examples/ for full code.

Environment variables

Variable Required Description
VIBE_API_KEY Yes VibeCode API key from your Bitrix24 portal
LLM_BASE_URL No OpenAI-compatible API URL (for AI assistant)
LLM_API_KEY No LLM API key
LLM_MODEL No LLM model name

Examples

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vibecode_b24_bot-0.2.0.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vibecode_b24_bot-0.2.0-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file vibecode_b24_bot-0.2.0.tar.gz.

File metadata

  • Download URL: vibecode_b24_bot-0.2.0.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.8

File hashes

Hashes for vibecode_b24_bot-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9c66c83c9c84b4f62cba73f9593d9d7fc4f93be76da6a431af0a1b4961b3b694
MD5 3c8c8f1c77cc856afeb68b481d280594
BLAKE2b-256 4c22e08b320ed678e6ed95d33cc4ffac1a12628e0f815974903de193c8c76558

See more details on using hashes here.

File details

Details for the file vibecode_b24_bot-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for vibecode_b24_bot-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6a813ab9d6e132a3e2bbf77e15a04bc4d6febe1897f36f54484982b33fcd50bd
MD5 d42844905ae57fbd74e0404784fa74f3
BLAKE2b-256 dd5279a8366eabe96bf9d46eb3453350225bf48b9a0e73b6fdcc822cf84c8138

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page