vjik/telegram-bot-api 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

vjik/telegram-bot-api

最新稳定版本:0.21

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.0 (May 8, 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.

统计信息

  • 总下载量: 12.06k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 122
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固