ngocnm / novagram
一个面向对象的PHP库,用于Telegram机器人
2.1
2023-12-20 16:38 UTC
Requires
- php: >=7.4
- ext-curl: *
- ext-json: *
- monolog/monolog: ^3.5
- skrtdev/async: ^1.0
- symfony/polyfill-php80: ^1.22
Suggests
- ext-mbstring: Needed to use the built-in Telegram Entites Parser
- ext-pcntl: Needed to process updates with multi-processing
- ext-pdo: Needed to use the built-in Database
This package is auto-updated.
Last update: 2024-09-20 18:33:56 UTC
README
NovaGram
一个优雅的、面向对象的、可靠的PHP Telegram机器人库
完整文档 • 公共支持群组
示例 • 功能 • 安装
🌟 v1.9 已发布:查看变更日志 这里
⚙️ 示例
一个简单机器人的示例代码。
支持 getUpdates 和 Webhooks
use skrtdev\NovaGram\Bot; use skrtdev\Telegram\Message; $Bot = new Bot('YOUR_TOKEN'); $Bot->onCommand('start', function (Message $message) { $message->reply('Hey! Nice to meet you. Use /info to know more about me.'); }); $Bot->onCommand('info', function (Message $message) { $message->reply('Well, I\'m just an example, but you can learn more about NovaGram at novagram.gaetano.eu.org'); });
📎 功能
- 完整:实现了 Bot Api 5.0 中的所有方法和类型(也支持 本地 Bot Api)
- 快速:支持 JSON 负载,并支持 异步处理更新
- 可扩展:使用 原型,您可以添加自己的 自定义功能
- 简单:与原始 Bot Api 完全一样,许多方法以非常优雅的方式简化
- 即用型:您现在就可以 开始创建您令人惊叹的机器人,多亏了许多内置功能,例如 会话、实体解析器 和 getDC
- 安全:当使用 Webhooks 时,有一个 内置的 Telegram IP 检查,也可以与 Cloudflare 一起使用!
为什么还需要另一个PHP库?
我决定自己为Telegram机器人API构建PHP库,因为我找到的所有库在网络上 使得即使是做最简单的事情都很困难,比如 sendMessage。
NovaGram 是为了提供轻量级的替代品来制作机器人而构建的,因此对于初学者来说很简单,但对于已经知道如何实现它的人来说则非常强大。
⬇️ 安装
通过 Composer 安装
使用 Composer 安装 NovaGram
composer require skrtdev/novagram ^1.9
安装后,使用以下方式包含 NovaGram
require 'vendor/autoload.php';
通过 Phar 安装
将 phar
文件包含到您的机器人文件中
if (!file_exists('novagram.phar')) { copy('https://gaetano.eu.org/novagram/phar.phar', 'novagram.phar'); } require_once 'novagram.phar';
更多信息请参见 文档