jungle-bay / telegram-bot-controller-provider
此包已被废弃,不再维护。未建议替代包。
Silex 的 Telegram Bot 控制器提供商
1.1
2018-03-18 07:46 UTC
Requires
- php: >=5.5.9
- jungle-bay/telegram-bot-platform: ^1.0.0
- silex/silex: ^2.0.0
Requires (Dev)
- phpunit/phpunit: ^4.8.36
- symfony/browser-kit: ^3.4.1
This package is not auto-updated.
Last update: 2024-01-08 21:28:24 UTC
README
Telegram Bot Controller Provider for Silex
安装
推荐的安装方式是通过 Composer
composer require jungle-bay/telegram-bot-controller-provider
使用示例
<?php require_once __DIR__ . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, array('vendor', 'autoload.php')); $app = new \Silex\Application(); $app->mount('/bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11', new \Silex\Provider\TelegramBotControllerProvider(array( 'token' => '123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11', // Your token bot. 'storage' => $adapter, // This adapter for Scrapbook library to store user sessions. See the complete adapters: https://github.com/matthiasmullie/scrapbook#adapters 'mappings' => array( 'default' => \Acme\Bot\Commands\DefaultCmd::class, // This command will work by default if no command is found or user session. (optional) 'inline_query' => \Acme\Bot\Commands\FeedbackInlineQueryCmd::class, // This command will work with inline queries. (optional) 'commands' => array( // This is the list of registered commands for the bot. (optional) 'help' => \Acme\Bot\Commands\HelpCmd::class, 'user' => \Acme\Bot\Commands\UserCmd::class ) ) ))); $app->run();
实现命令示例
<?php namespace Acme\Bot\Commands; use TelegramBotAPI\Types\Update; use TelegramBotPlatform\TelegramBotPlatform; use TelegramBotPlatform\Api\TelegramBotCommandInterface; class DefaultCmd implements TelegramBotCommandInterface { /** * {@inheritdoc} */ public function execute(TelegramBotPlatform $tbp, Update $update, $payload = null) { if (null === $update->getMessage()) return false; $tbp->getTelegramBotAPI()->sendMessage(array( 'chat_id' => $update->getMessage()->getChat()->getId(), 'text' => 'Default Cmd ;)' )); return true; } }
警告
不要忘记安装 webhook!示例 webhook URL
https://www.example.com/bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11/
请记住,webhook 仅在
HTTPS
连接上工作,并且当包含 webhook 时,方法getUpdates
将不会工作。
注意
为了方便开发,您可以使用 Telegram Bot CLI。
许可证
此包在 MIT 许可证 下。完整的许可证文件请见:[此处](https://github.com/jungle-bay/telegram-bot-controller-provider/blob/master/license.txt)。