shaygan / telegram-bot-api-bundle
对 telegram-bot-api 的简单封装。
dev-master
2020-09-23 20:25 UTC
Requires
- longman/telegram-bot: *
- symfony/framework-bundle: >=2.2
- telegram-bot/api: >=2.2.4
This package is auto-updated.
Last update: 2024-09-24 04:49:27 UTC
README
这是一个用于 Telegram Bot API 的 symfony 封装包,包含一些小功能。
安装
通过 Composer
$ composer require shaygan/telegram-bot-api-bundle @dev
编辑你的 app/AppKernel.php 文件,在 registerBundles() 方法中注册该包,如上所示
class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... // register the bundle here new \Shaygan\TelegramBotApiBundle\ShayganTelegramBotApiBundle() ); } }
配置包
此包旨在即插即用。为了使此包运行,您需要配置的只有您的机器人 token。
# app/config/config.yml shaygan_telegram_bot_api: token: xxxxx:yyyyyyyyyyyyyyyyyyyy
如果您想使用 webhook,请将包的路由配置添加到 app/config/routing.yml
shaygan_telegram_bot_api: resource: @ShayganTelegramBotApiBundle/Resources/config/routing.yml
并添加你的域名、url 前缀(如果需要)以及更新接收者服务名称(包含一个示例更新接收者)到配置文件
# app/config/config.yml shaygan_telegram_bot_api: #... webhook: domain: example.com path_prefix: ~ # you can add prefix, if your web site is not on the root update_receiver: shaygan.my_update_receiver # sample update receiver
注意:Telegram 不支持 http,你的网站应该有有效的 SSL(HTTPS)。
用法
在任何可以访问服务容器的位置
<?php // get the telegram api as a service $api = $this->container->get('shaygan.telegram_bot_api'); // test the API by calling getMe method $user = $api->getMe(); ?>
接下来...
请参考 Telegram Bot API 官方文档 获取有关可用方法和其他信息的详细信息
故障排除
如果您已正确配置所有设置,但在 getMe 方法上仍然出现错误(Http 错误 500),可能是因为 SSL 验证。请确保您有用于与 cURL 一起使用的最新 CA 根证书包。
您可以通过以下方式配置您的 CA 根证书包
- 从 cURL 网站下载最新的 cacert.pem 文件,并
- 在您的 php.ini 文件中设置其路径,例如在 Windows 上
curl.cainfo=c:\php\cacert.pem
许可证
MIT 许可证 (MIT)。请参阅 许可证文件 获取更多信息。