Skip to content

Commit eb1fb3e

Browse files
committed
Local Bot API Server support
Third-party http-client support window.Telegram.WebApp.initData validation
1 parent 903df6b commit eb1fb3e

18 files changed

+637
-214
lines changed

.github/workflows/tests.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ jobs:
5959
name: Remove psalm
6060
run: composer remove vimeo/psalm --dev --no-update
6161

62+
-
63+
name: Remove http client dependencies
64+
run: composer remove psr/http-client psr/http-factory symfony/http-client guzzlehttp/guzzle --dev --no-update
65+
6266
-
6367
name: Install dependencies with composer
6468
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

.php-cs-fixer.dist.php

+2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@
2323
'no_unused_imports' => true,
2424
'single_quote' => true,
2525
'no_extra_blank_lines' => true,
26+
'array_indentation' => true,
2627
'cast_spaces' => true,
2728
'phpdoc_align' => [
2829
'align' => 'left',
2930
],
3031
'binary_operator_spaces' => true,
32+
'single_line_empty_body' => false,
3133
])
3234
;

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ All Notable changes to `PHP Telegram Bot Api` will be documented in this file
1111
- Add `\TelegramBot\Api\BotApi::revokeChatInviteLink` api method
1212
- Add `\TelegramBot\Api\BotApi::approveChatJoinRequest` api method
1313
- Add `\TelegramBot\Api\BotApi::declineChatJoinRequest` api method
14+
- Add support for third party http clients (`psr/http-client` and `symfony/http-client`)
15+
- Add support for local bot API server
16+
- Add method `\TelegramBot\Api\BotApi::validateWebAppData` to validate `window.Telegram.WebApp.initData`
1417

1518
## 2.5.0 - 2023-08-09
1619

README.md

+11-33
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,6 @@ require_once "vendor/autoload.php";
8282

8383
try {
8484
$bot = new \TelegramBot\Api\Client('YOUR_BOT_API_TOKEN');
85-
// or initialize with botan.io tracker api key
86-
// $bot = new \TelegramBot\Api\Client('YOUR_BOT_API_TOKEN', 'YOUR_BOTAN_TRACKER_API_KEY');
87-
8885

8986
//Handle /ping command
9087
$bot->command('ping', function ($message) use ($bot) {
@@ -107,45 +104,26 @@ try {
107104
}
108105
```
109106

110-
### Botan SDK (not supported more)
111-
112-
[Botan](http://botan.io) is a telegram bot analytics system based on [Yandex.Appmetrica](http://appmetrica.yandex.com/).
113-
In this document you can find how to setup Yandex.Appmetrica account, as well as examples of Botan SDK usage.
114-
115-
### Creating an account
116-
* Register at http://appmetrica.yandex.com/
117-
* After registration you will be prompted to create Application. Please use @YourBotName as a name.
118-
* Save an API key from settings page, you will use it as a token for Botan API calls.
119-
* Download lib for your language, and use it as described below. Don`t forget to insert your token!
120-
121-
Since we are only getting started, you may discover that some existing reports in AppMetriсa aren't properly working for Telegram bots, like Geography, Gender, Age, Library, Devices, Traffic sources and Network sections. We will polish that later.
122-
123-
## SDK usage
124-
125-
#### Standalone
107+
#### Local Bot API Server
126108

127-
```php
128-
$tracker = new \TelegramBot\Api\Botan('YOUR_BOTAN_TRACKER_API_KEY');
129-
130-
$tracker->track($message, $eventName);
131-
```
109+
For using custom [local bot API server](https://core.telegram.org/bots/api#using-a-local-bot-api-server)
132110

133-
#### API Wrapper
134111
```php
135-
$bot = new \TelegramBot\Api\BotApi('YOUR_BOT_API_TOKEN', 'YOUR_BOTAN_TRACKER_API_KEY');
136-
137-
$bot->track($message, $eventName);
112+
use TelegramBot\Api\Client;
113+
$token = 'YOUR_BOT_API_TOKEN';
114+
$bot = new Client($token, null, null, 'http://localhost:8081');
138115
```
139116

140-
You can use method 'getUpdates()'and all incoming messages will be automatically tracked as `Message`-event.
117+
#### Third-party Http Client
141118

142-
#### Client
143119
```php
144-
$bot = new \TelegramBot\Api\Client('YOUR_BOT_API_TOKEN', 'YOUR_BOTAN_TRACKER_API_KEY');
120+
use Symfony\Component\HttpClient\HttpClient;
121+
use TelegramBot\Api\BotApi;
122+
use TelegramBot\Api\Http\SymfonyHttpClient;
123+
$token = 'YOUR_BOT_API_TOKEN';
124+
$bot = new Client($token, null, new SymfonyHttpClient(HttpClient::create()););
145125
```
146126

147-
_All registered commands are automatically tracked as command name_
148-
149127
## Change log
150128

151129
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

composer.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,18 @@
2424
},
2525
"require-dev": {
2626
"symfony/phpunit-bridge" : "*",
27-
"friendsofphp/php-cs-fixer": "^3.16",
28-
"vimeo/psalm": "^5.9"
27+
"friendsofphp/php-cs-fixer": "~3.28.0",
28+
"vimeo/psalm": "^5.9",
29+
"psr/http-client": "^1.0",
30+
"psr/http-factory": "^1.0",
31+
"symfony/http-client": "^4.3 | ^5.0 | ^6.0",
32+
"guzzlehttp/guzzle": "^7.0"
33+
},
34+
"suggest": {
35+
"psr/http-client": "To use psr/http-client",
36+
"psr/http-factory": "To use psr/http-client",
37+
"guzzlehttp/guzzle": "To use psr/http-client",
38+
"symfony/http-client": "To use symfony/http-client"
2939
},
3040
"autoload": {
3141
"psr-4": {

psalm.xml

+4-5
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919
<MissingConstructor errorLevel="suppress" />
2020
<PropertyNotSetInConstructor errorLevel="suppress" />
2121
<RedundantCastGivenDocblockType errorLevel="suppress" />
22-
<DeprecatedClass>
23-
<errorLevel type="suppress">
24-
<referencedClass name="TelegramBot\Api\Botan" />
25-
</errorLevel>
26-
</DeprecatedClass>
22+
<DeprecatedConstant errorLevel="suppress" />
23+
<DeprecatedMethod errorLevel="suppress" />
24+
<DeprecatedClass errorLevel="suppress" />
25+
<DeprecatedProperty errorLevel="suppress" />
2726
</issueHandlers>
2827
</psalm>

0 commit comments

Comments
 (0)