danog/tg-dialog-id
Composer 安装命令:
composer require danog/tg-dialog-id
包简介
A library to work with Telegram bot API dialog IDs
README 文档
README
A library to work with Telegram bot API dialog IDs.
Created by Daniil Gentili (https://daniil.it).
This library was initially created for MadelineProto, an async PHP client API for the telegram MTProto protocol.
Installation
composer require danog/tg-dialog-id
Usage
<?php declare(strict_types=1); use danog\DialogId\DialogId; require 'vendor/autoload.php'; function expect(bool $expect): void { if (!$expect) { throw new AssertionError("Not verified!"); } } $link = "https://t.me/c/1234567890/8892"; if (preg_match("|t.me/c/(\d+)/(\d+)|", $link, $matches)) { // Returns -1001234567890 echo DialogId::fromSupergroupOrChannelId((int) $matches[1]).PHP_EOL; } // Converts an MTProto supergroup/channel ID => bot API dialog ID expect(DialogId::fromSupergroupOrChannelId(1234567890) === -1001234567890); // Converts an MTProto chat ID => bot API dialog ID expect(DialogId::fromChatId(123456789) === -123456789); // Converts an MTProto user ID => bot API dialog ID expect(DialogId::fromUserId(123456789) === 123456789); // Converts an MTProto secret chat ID => bot API dialog ID expect(DialogId::fromSecretChatId(123456789) === -1999876543211); // Converts a bot API dialog ID => MTProto supergroup/channel ID expect(DialogId::toSupergroupOrChannelId(-1001234567890) === 1234567890); // Converts a bot API dialog ID => MTProto chat ID expect(DialogId::toChatId(-123456789) === 123456789); // Converts a bot API dialog ID => MTProto user ID expect(DialogId::toUserId(123456789) === 123456789); // Converts a bot API dialog ID => MTProto secret chat ID expect(DialogId::toSecretChatId(-1999876543211) === 123456789); expect(DialogId::getType(101374607) === DialogId::USER); expect(DialogId::getType(-123456789) === DialogId::CHAT); expect(DialogId::getType(-1001234567890) === DialogId::CHANNEL_OR_SUPERGROUP); expect(DialogId::getType(-1999898625393) === DialogId::SECRET_CHAT); expect(DialogId::isUser(1099511627775) === true); expect(DialogId::isChat(-999_999_999_999) === true); expect(DialogId::isSupergroupOrChannel(-1997852516352) === true); expect(DialogId::isSecretChat(-2002147483648) === true); expect(DialogId::isUser(101374607) === true); expect(DialogId::isChat(-101374607) === true); expect(DialogId::isSupergroupOrChannel(-1001234567890) === true); expect(DialogId::isSecretChat(-1999898625393) === true); // Converts a bot API dialog ID => MTProto ID automatically depending on type expect(DialogId::toMTProtoId(-1001234567890) === 1234567890); expect(DialogId::toMTProtoId(-123456789) === 123456789); expect(DialogId::toMTProtoId(123456789) === 123456789); expect(DialogId::toMTProtoId(-1999876543211) === 123456789); echo "OK!".PHP_EOL;
API Documentation
Click here » to view the API documentation.
danog/tg-dialog-id 适用场景与选型建议
danog/tg-dialog-id 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 225.79k 次下载、GitHub Stars 达 11, 最近一次更新时间为 2024 年 05 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 danog/tg-dialog-id 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 danog/tg-dialog-id 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 225.79k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 26
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2024-05-10