定制 vjik/telegram-bot-api 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

vjik/telegram-bot-api

Composer 安装命令:

composer require vjik/telegram-bot-api

包简介

PHP library for working with Telegram API

README 文档

README

PHPTG

Telegram Bot API for PHP


Latest Stable Version Total Downloads Build status Coverage Status Mutation score Static analysis

The package provides a simple and convenient way to interact with the Telegram Bot API.

✔️ Telegram Bot API 10.2 (July 14, 2026) is fully supported.

♻️ Zero dependencies — no third-party libraries, only native PHP.

Important

This project is developed and maintained by Sergei Predvoditelev. Community support helps keep the project actively developed and well maintained. You can support the project using the following services:

Thank you for your support ❤️

Requirements

  • PHP (64-bit) 8.2 - 8.5.

Installation

The package can be installed with Composer:

composer require phptg/bot-api

General usage

To make requests to the Telegram Bot API, you need to create an instance of the TelegramBotApi class.

use Phptg\BotApi\TelegramBotApi;

// API
$api = new TelegramBotApi(
    // Telegram bot authentication token
    '110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw',
);

Now you can use the $api instance to interact with the Telegram Bot API. Method names are the same as in the Telegram Bot API documentation. For example:

use Phptg\BotApi\Type\InputFile

// Specify a URL for outgoing webhook
$api->setWebhook('https://example.com/webhook');

// Send text message
$api->sendMessage(
    chatId: 22351, 
    text: 'Hello, world!',
);

// Send local photo
$api->sendPhoto(
    chatId: 22351, 
    photo: new InputFile('/path/to/photo.jpg'),
);

The result will be either a FailResult instance (occurring on an error) or an object of the corresponding type (occurring on success). For example:

// Result is an array of `Phptg\BotApi\Update\Update` objects
$updates = $api->getUpdates();

Documentation

TelegramBotApi

TelegramBotApi constructor parameters:

  • $token (required) — Telegram bot authentication token;
  • $baseUrl — the base URL for Telegram Bot API requests (default https://api.telegram.org).
  • $transport — the transport to make requests to Telegram Bot API (cURL or native transport will be used by default).
  • $logger — the PSR-3 compatible logger to log requests to Telegram Bot API and response handling errors. See logging for more information.

Method names are the same as in the Telegram Bot API documentation.

Files

File URL

Use TelegramBotApi::makeFileUrl() method to make a URL for downloading a file from the Telegram server. For example:

/**
 * @var \Phptg\BotApi\TelegramBotApi $api
 * @var \Phptg\BotApi\Type\File $file 
 */
 
// By `File` instance
$url = $api->makeFileUrl($file);

// By file path is taken from the Telegram response
$url = $api->makeFileUrl('photos/file_2');

File downloading

Use TelegramBotApi::downloadFile() method to download a file from the Telegram server. The method returns a DownloadedFile instance with getStream(), getBody() and saveTo() methods. For example:

/**
 * @var \Phptg\BotApi\TelegramBotApi $api
 * @var \Phptg\BotApi\Type\File $file
 */

// Get file content as string
$content = $api->downloadFile($file)->getBody();

// Get file content as stream
$stream = $api->downloadFile('photos/file_2')->getStream();

// Download and save file
$api->downloadFile($file)->saveTo('/local/path/to/file.jpg');

Guides

If you have any questions or problems with this package, use author telegram chat for communication.

License

The phptg/bot-api is free software. It is released under the terms of the BSD License. Please see LICENSE for more information.

Credits

The package is inspired by Botasis code originally created by Viktor Babanov.

vjik/telegram-bot-api 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 12.24k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 127
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 127
  • Watchers: 2
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2024-05-30