承接 belka-tech/php-vk-teams-bot 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

belka-tech/php-vk-teams-bot

Composer 安装命令:

composer require belka-tech/php-vk-teams-bot

包简介

PHP client for VK Teams Bot API (aka ICQ Bot)

README 文档

README

Latest Version Build License

Introduction

PHP client for VK Teams Bot API. Provides a typed interface for sending messages, managing chats, and receiving events via long polling.

Official documentation: https://teams.vk.com/botapi/

Requirements

  • PHP 8.2+
  • PSR-18 HTTP Client (psr/http-client)
  • PSR-17 HTTP Factories (psr/http-factory)
  • PSR-3 Logger (psr/log) — optional, for LoggingHttpClient

Installation

composer require belka-tech/php-vk-teams-bot

Quick Start

$bot = new \BelkaTech\VkTeamsBot\Bot(
    new \BelkaTech\VkTeamsBot\Http\HttpClient(
        baseUri: 'https://api.icq.net/bot',
        token: 'YOUR_BOT_TOKEN',
        client: new \GuzzleHttp\Client(
            [
                'connect_timeout' => 4,
                'timeout' => 15,
                'http_errors' => false,
            ],
        ),
        requestFactory: new \GuzzleHttp\Psr7\HttpFactory(),
        streamFactory: new \GuzzleHttp\Psr7\HttpFactory(),
    ),
);

// Send a text message
$bot->messages->sendText(
    chatId: 'YOUR_CHAT_ID',
    text: '<b>Hello!</b>',
);

API

Messages ($bot->messages)

Method Description
sendText() Send a text message
sendFile() Send a file
sendVoice() Send a voice message
editText() Edit a message
deleteMessages() Delete messages
answerCallbackQuery() Answer a callback query
pinMessage() Pin a message
unpinMessage() Unpin a message
filesGetInfo() Get file information

Chats ($bot->chats)

Method Description
create() Create a chat
addMembers() Add members
removeMembers() Remove members
sendAction() Send an action (typing, etc.)
getInfo() Get chat information
getAdmins() List administrators
getMembers() List members
blockUser() Block a user
unblockUser() Unblock a user
resolvePending() Approve/reject join requests
setTitle() Set chat title
setAvatar() Set chat avatar
setAbout() Set chat description
setRules() Set chat rules

Events API ($bot->events)

Method Description
get() Fetch events (long polling)

Event Listener

Long polling with event dispatching:

$botEventListener = new \BelkaTech\VkTeamsBot\BotEventListener(
    bot: $bot,
);

// Register event handlers
$botEventListener->onMessage(
    function (
        \BelkaTech\VkTeamsBot\Bot $bot,
        \BelkaTech\VkTeamsBot\Event\EventDto $event,
    ): void {
        $bot->messages->sendText(
            chatId: $event->payload['chat']['chatId'],
            text: 'Pong!',
        );
    },
);

$botEventListener->onCommand(
    '/start',
    function (
        \BelkaTech\VkTeamsBot\Bot $bot,
        \BelkaTech\VkTeamsBot\Event\EventDto $event,
    ): void {
        // handle /start command
    },
);

// Start long polling (must be called after all handlers are registered)
$botEventListener->listen(
    pollTime: 30,
    onException: function (
        \Exception $exception,
        \BelkaTech\VkTeamsBot\Event\EventDto $event
    ): void {
        // Log the error
        $this->logger->error('Some text', [
            'event_id' => $event->eventId,
            'event_type' => $event->type,
            'event_payload' => $event->payload,
            'exception' => $exception,
        ]);
        error_log($exception->getMessage());
        
        // Or catch exception to an error reporting system
        $this->sentry->captureException($exception);
        
        // On exception loop continues,
        // you can re-throw the exception to force stop the loop
        throw $exception;
    },
);

// Stop the listener programmatically (e.g. from a handler)
$botEventListener->stop();
Method Description
onCommand() Register a command handler
onMessage() Handle new messages
onEditedMessage() Handle edited messages
onDeletedMessage() Handle deleted messages
onPinnedMessage() Handle pinned messages
onUnpinnedMessage() Handle unpinned messages
onNewChatMember() Handle new chat members
onLeftChatMember() Handle members leaving
onCallbackQuery() Handle callback queries
listen() Start long polling
stop() Stop the listener

If the pcntl extension is available, SIGTERM and SIGINT signals are handled automatically for graceful shutdown. Without pcntl, use $botEventListener->stop() from a handler to stop the loop.

Keyboard

$keyboard = new \BelkaTech\VkTeamsBot\Keyboard\Keyboard();
$keyboard->addRow([
    new \BelkaTech\VkTeamsBot\Keyboard\Button(
        text: 'OK',
        callbackData: 'confirm',
        style: \BelkaTech\VkTeamsBot\Enum\ButtonStyleEnum::Primary,
    ),
    new \BelkaTech\VkTeamsBot\Keyboard\Button(
        text: 'Cancel',
        callbackData: 'cancel',
        style: \BelkaTech\VkTeamsBot\Enum\ButtonStyleEnum::Attention,
    ),
]);

$bot->messages->sendText(
    chatId: '123456',
    text: 'Confirm?',
    inlineKeyboardMarkup: $keyboard,
);

LoggingHttpClient

Decorator for a PSR-18 client that logs requests and responses:

$loggingClient = new \BelkaTech\VkTeamsBot\Http\LoggingHttpClient(
    $psrHttpClient,
    $psrLogger,
);

Parse Mode

HTML is used by default. You can switch to MarkdownV2:

$bot = new \BelkaTech\VkTeamsBot\Bot(
    httpClient: $httpClient,
    parseMode: \BelkaTech\VkTeamsBot\Enum\ParseModeEnum::MarkdownV2,
);

You can also specify parseMode for an individual message:

$bot->messages->sendText(
    chatId: '123456',
    text: '**bold**',
    parseMode: \BelkaTech\VkTeamsBot\Enum\ParseModeEnum::MarkdownV2,
);

Development

make setup   # build image, start container, install dependencies
make test    # run tests
make phpstan # run static analysis
make shell   # enter the container

Other commands: make up, make down, make build, make install.

Alternatives

License

  • PHP VK Teams Bot package is open-sourced software licensed under the MIT license by BelkaCar.

belka-tech/php-vk-teams-bot 适用场景与选型建议

belka-tech/php-vk-teams-bot 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 77 次下载、GitHub Stars 达 2, 最近一次更新时间为 2026 年 03 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 belka-tech/php-vk-teams-bot 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 belka-tech/php-vk-teams-bot 我们能提供哪些服务?
定制开发 / 二次开发

基于 belka-tech/php-vk-teams-bot 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 77
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 36
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-21