levkopo / dribots
适用于 VK、Viber、Telegram 等平台的聊天机器人库
1.2
2021-10-03 08:08 UTC
Requires
- php: >=8.0
- monolog/monolog: ^2.2
Requires (Dev)
- phpunit/phpunit: ^9.5
- roave/security-advisories: dev-latest
README
适用于 VK.com、Telegram 等平台的聊天机器人库
安装
要安装 dribots,您需要 composer 和 PHP 8.0 及更高版本(当然,如果您有的话 xD)
composer require levkopo/dribots
安装平台库
此外,要使用 DriBots 在其他平台上,您需要所需的平台库。
对于 Telegram
composer require levkopo/dribots-telegram
对于 VK.com
composer require levkopo/dribots-vk
使用方法
示例:发送消息的聊天机器人重发 VK.com 和 Telegram 上的消息
use DriBots\Bot; use DriBots\Data\Message; use DriBots\DriBotsHandler; use DriBots\Platforms\TelegramPlatform; use DriBots\Platforms\VKPlatform; const TELEGRAM_BOT_TOKEN = "<telegram token>"; const VK_ACCESS_TOKEN = "<vk token>"; const VK_GROUP_ID = <vk group id>; include_once __DIR__."/./vendor/autoload.php"; DriBotsHandler::new(new class extends Bot { public function onNewMessage(Message $message): void { $this->platformProvider->sendMessage($message->fromId, $message->text, $message->attachment?->save($message->fromId.$message->id)); } })->addPlatform(new VKPlatform(VK_ACCESS_TOKEN, VK_GROUP_ID)) ->addPlatform(new TelegramPlatform(TELEGRAM_BOT_TOKEN)) ->handle();