An open API service indexing awesome lists of open source software.

https://github.com/gingteam/telegram

Telegram's collection of data types and methods
https://github.com/gingteam/telegram

php symfony-serializer telegram

Last synced: about 2 months ago
JSON representation

Telegram's collection of data types and methods

Awesome Lists containing this project

README

          

This package provides Telegram data types and methods

![](https://shepherd.dev/github/gingteam/telegram/coverage.svg)
![](https://shepherd.dev/github/gingteam/telegram/level.svg)
[![Test](https://github.com/gingteam/telegram/actions/workflows/test.yml/badge.svg)](https://github.com/gingteam/telegram/actions/workflows/test.yml)

## Example

You can implement your own object class:

```php
client = $client ?: HttpClient::create();
}

public function sendRequest(string $name, array $data = [])
{
$data = $this->getSerializer()->normalize((object) $data);

$endpoint = sprintf('%s/bot%s/%s', self::BOT_API_URL, $this->token, $name);

$response = $this->client->request('POST', $endpoint, [
'json' => $data,
])->toArray(false);

/** @var Response */
$response = $this->getSerializer()->denormalize($response, Response::class);

if ($response->getErrorCode()) {
throw new RuntimeException($response->getDescription());
}

return $response->getResult();
}
}

$telegram = new SimpleTelegram('{token}');

foreach ($telegram->getUpdates() as $update) {
echo $update?->getMessage()?->getFrom()?->getUsername()."\n";
}
```