承接 nicoosh/telegram-bot-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nicoosh/telegram-bot-bundle

Composer 安装命令:

composer require nicoosh/telegram-bot-bundle

包简介

This bundle provides a wrapper for using longman/telegram-bot inside Symfony.

README 文档

README

Latest Stable Version License Total Downloads

This bundle provides a wrapper for using PHP Telegram Bot inside Symfony. Additional documentation can be found in the official repository.

Installation

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

symfony composer require m4n50n/telegram-bot-bundle

Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in config/bundles.php file of your project:

// config/bundles.php

return [
    // ...
    M4n50n\TelegramBotBundle\TelegramBotBundle::class => ['all' => true],
];

Configure the Bundle

# config/packages/telegram_bot.yaml

telegram_bot:
  bots:
    first_bot:
      # Required #
      key: "%env(BOT_KEY)%"
      username: "%env(BOT_USERNAME)%"
      webhook:
        url: "%env(BOT_HOOK_URL)%"
        max_connections: "%env(BOT_MAX_CONNECTIONS)%"
      commands:
        paths:
          - "%env(BOT_COMMANDS_PATH)%"

      # Optional #
      admins:
        - 123456789 # Admin user id in Telegram
      mysql:
        enabled: true # false by default
        host: "%env(BOT_MYSQL_HOST)%"
        user: "%env(BOT_MYSQL_USER)%"
        password: "%env(BOT_MYSQL_ROOT_PASSWORD)%"
        database: "%env(BOT_MYSQL_DB)%"
      log:
        enabled: true # false by default
        debug: "%env(LOG_DEBUG_FILE_PATH)%"
        error: "%env(LOG_ERROR_FILE_PATH)%"
        update: "%env(LOG_UPDATE_FILE_PATH)%"
      paths:
        download: "%env(DOWNLOADS_PATH)%"
        upload: "%env(UPLOADS_PATH)%"
      limiter:
        enabled: true # false by default

    second_bot:
      # ...

If you want the configuration / environment files to be created automatically inside your /config folder, you can include my private Symfony Flex recipes repository in your composer.json by adding the following configuration:

"extra": {
  "symfony": {
      "endpoint": [
          "https://api.github.com/repos/m4n50n/symfony_flex_recipes/contents/index.json",
          "flex://defaults"
      ]
  }
}

Usage

Whenever you need to get a bot instance, use dependency injection for your service. The bot configuration is automatically loaded by providing the bot name, which should match the key in the configuration yaml file. For example:

telegram_bot:
  bots:
    first_bot: # $botName
use M4n50n\TelegramBotBundle\Factory\TelegramBotFactory;

final class TelegramBotService
{
    public function __construct(private TelegramBotFactory $botFactory)
    {
    }

    public function initialize(string $botName)
    {
        // ...
        return $this->botFactory->get($botName);        
    }
}

Methods

This wrapper defines the basic bot configuration methods.

  • webhookHandler() Method that will receive and handle incoming updates via an outgoing webhook.
  • setWebhook() to register the webhook with Telegram. The endpoint to be configured as a webhook must be on a server with HTTPS support.
  • unsetWebhook() to unregister the webhook.

If you create controllers for these methods, you will only have to do:

namespace App\Controller;

// ...

final class PHPCodeTesterBotController extends AbstractController
{
  private readonly TelegramBot $bot;

  public function __construct(private TelegramBotService $telegramBotService)
  {
    $this->bot = $telegramBotService->initialize("bot_name");
  }

  #[Route('/endpoint', name: 'app_webhook_endpoint')]
  public function webhookEndpoint(): Response
  {
    // ...
    $webhookHandler = $this->bot->webhookHandler();
    // ... or
    $setWebhook = $this->bot->setWebhook();
    // ... or
    $unsetWebhook = $this->bot->unsetWebhook();
    // ...
  }
}

Contributing

See CONTRIBUTING for more information.

Security

See SECURITY for more information.

License

Please see the LICENSE included in this repository for a full copy of the MIT license, which this project is licensed under.

nicoosh/telegram-bot-bundle 适用场景与选型建议

nicoosh/telegram-bot-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 42 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 07 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「api」 「bundle」 「wrapper」 「bot」 「telegram」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 nicoosh/telegram-bot-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 nicoosh/telegram-bot-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 nicoosh/telegram-bot-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 42
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-07-22