kprokgb/longman-telegram-bot-api-bundle

longman Telegram机器人简单封装。

安装: 23

依赖者: 0

建议者: 0

安全: 0

星级: 0

关注者: 0

分支: 17

类型:symfony-bundle

dev-master 2020-04-27 19:04 UTC

This package is auto-updated.

Last update: 2024-09-29 05:29:08 UTC


README

这是一个分支,原始包位于 borsaco/TelegramBotApiBundle

PHP Telegram Bot的symfony封装包PHP Telegram Bot

安装

通过Composer

composer require kprokgb/longman-telegram-bot-api-bundle

配置包

此包旨在即插即用。为了使此包运行,您需要配置的唯一东西是您的bot token

# config/packages/telegram.yaml

longman_telegram_bot_api:
    # Proxy (optional) :
    #proxy: 'socks5h://127.0.0.1:5090' # this is example you have to change this
    #async_requests: false

    # Development section:
    development:
        # implement in next version
        # Telegram user_id of developers accounts
        developers_id: [1234567, 87654321]
        # If this mode is enabled, the robot only responds to the developers
        maintenance:
            enable: false
            text: "The robot is being repaired! Please come back later."
  
    # Bots:
    bots:
        # The bot name
        first:
            # Your bot token: (required)
            token: 123456789:ABCD1234****4321CBA
            without_db: false
            hook_url:
        second:
            # Your bot token: (required)
            token: 123456789:ABCD1234****4321CBA
            without_db: false
            hook_url:
    
    # The default bot returned when you call getBot()
    default: 'first' 

用法

您可以使用以下方式在控制器中访问bot

    use Borsaco\TelegramBotApiBundle\Service\Bot;

    ...

    public function index(Bot $bot)
    {
        $firstBot = $bot->getBot('first');
        $firstBot->getMe();
    }

为了通过Webhook接收更新,您首先需要将您的Webhook URL告诉Telegram。您可以使用setWebhook方法指定一个URL,并通过出站Webhook接收传入的更新。

一旦使用setWebhook方法设置了Webhook,您就可以使用以下函数检索发送到您的Webhook URL的更新。该函数返回一个包含Update对象的数组。

    $updateArray = $firstBot()->getWebhookUpdate();

接下来...

请参阅Telegram机器人API官方文档获取有关可用方法和其他信息的详细信息。

故障排除

如果您已经正确配置了所有设置,但在getMe()方法上仍然得到错误(HTTP错误500),可能是因为SSL验证。请确保您有最新的CA根证书捆绑包用于cURL。

您可以通过以下方式配置您的CA根证书捆绑包

  1. 从cURL网站下载最新的cacert.pem文件,并在
  2. 您的php.ini文件中设置其路径,例如在Windows上

curl.cainfo=c:\php\cacert.pem

您可以使用这个便捷的在线工具测试您的SSL设置:SSL Labs

许可证

BSD许可证。有关更多信息,请参阅许可证文件