ericomgroup/telegram-bot-api-bundle

该包已被弃用且不再维护。作者建议使用 borsaco/telegram-bot-api-bundle 包。

一个简单的telegram-bot-api包装器。

安装: 768

依赖者: 0

建议者: 0

安全: 0

星标: 4

分支: 1

类型:symfony-bundle

该包尚未发布版本,信息较少。


README

Packagist license

Telegram Bot API 提供的 symfony 包装器包。

安装

通过 Composer

composer require ericomgroup/telegram-bot-api-bundle

配置包

此包设计为开箱即用。为了使此包正常运行,您需要配置的只有您的机器人 token

# config/packages/telegram.yaml

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:
        # Telegram user_id of developers accounts
        developers_id: [1234567, 87654321]
        # If this mode is enabled, the robot only responds to the developers
        maintenance:
            enable: true
            text: "The robot is being repaired! Please come back later."

    # Bots:
    bots:
        # The bot name
        first:
            # Your bot token: (required)
            token: 123456789:ABCD1234****4321CBA
        second:
            # Your bot token: (required)
            token: 123456789:ABCD1234****4321CBA
    
    # The default bot returned when you call getBot()
    default: 'second' 

用法

您可以在控制器中使用

    use EricomGroup\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()->getWebhookUpdates();

接下来...

有关可用方法和其他信息,请参阅 Telegram Bot API 官方文档

故障排除

如果您已正确完成所有配置,但在 getMe() 方法上仍然出现错误(HTTP 错误 500),则可能是由于 SSL 验证。请确保您有用于与 cURL 一起使用的最新 CA 根证书捆绑包。

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

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

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

您可以使用此方便的在线工具测试您的 SSL 设置:SSL Labs

许可证

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