mirror of
https://github.com/danog/tgbot-dialog-id.git
synced 2024-11-26 21:14:51 +01:00
57 lines
1.9 KiB
Markdown
57 lines
1.9 KiB
Markdown
# tgbot-dialog-id
|
|
|
|
[![codecov](https://codecov.io/gh/danog/tgbot-dialog-id/branch/master/graph/badge.svg)](https://codecov.io/gh/danog/tgbot-dialog-id)
|
|
[![Psalm coverage](https://shepherd.dev/github/danog/tgbot-dialog-id/coverage.svg)](https://shepherd.dev/github/danog/tgbot-dialog-id)
|
|
[![Psalm level 1](https://shepherd.dev/github/danog/tgbot-dialog-id/level.svg)](https://shepherd.dev/github/danog/tgbot-dialog-id)
|
|
![License](https://img.shields.io/github/license/danog/tgbot-dialog-id)
|
|
|
|
A library to work with Telegram bot API dialog IDs.
|
|
|
|
Created by Daniil Gentili (https://daniil.it).
|
|
|
|
This library was initially created for [MadelineProto](https://docs.madelineproto.xyz), an async PHP client API for the telegram MTProto protocol.
|
|
|
|
## Installation
|
|
|
|
```bash
|
|
composer require danog/tgbot-dialog-id
|
|
```
|
|
|
|
## Usage
|
|
|
|
```php
|
|
<?php declare(strict_types=1);
|
|
|
|
use danog\DialogId\DialogType;
|
|
|
|
require 'vendor/autoload.php';
|
|
|
|
function expect(bool $expect): void
|
|
{
|
|
if (!$expect) {
|
|
throw new AssertionError("Not verified!");
|
|
}
|
|
}
|
|
|
|
expect(DialogType::from(101374607) === DialogType::USER);
|
|
expect(DialogType::from(-123456789) === DialogType::CHAT);
|
|
expect(DialogType::from(-1001234567890) === DialogType::CHANNEL_OR_SUPERGROUP);
|
|
expect(DialogType::from(-1999898625393) === DialogType::SECRET_CHAT);
|
|
|
|
expect(DialogType::isUser(1099511627775) === true);
|
|
expect(DialogType::isChat(-999_999_999_999) === true);
|
|
expect(DialogType::isSupergroupOrChannel(-1997852516352) === true);
|
|
expect(DialogType::isSecretChat(-2002147483648) === true);
|
|
|
|
expect(DialogType::isUser(101374607) === true);
|
|
expect(DialogType::isChat(-101374607) === true);
|
|
expect(DialogType::isSupergroupOrChannel(-1001234567890) === true);
|
|
expect(DialogType::isSecretChat(-1999898625393) === true);
|
|
|
|
echo "OK!".PHP_EOL;
|
|
```
|
|
|
|
## API Documentation
|
|
|
|
Click [here »](https://github.com/danog/tgbot-dialog-id/blob/master/docs/index.md) to view the API documentation.
|