Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Commit d75bd72

Browse files
committed
All examples should be working now
1 parent 22d4461 commit d75bd72

17 files changed

+129
-104
lines changed

examples/get-webhookinfo.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
include __DIR__ . '/basics.php';
6+
7+
use React\EventLoop\Factory;
8+
use unreal4u\TelegramAPI\HttpClientRequestHandler;
9+
use unreal4u\TelegramAPI\Telegram\Methods\GetWebhookInfo;
10+
use unreal4u\TelegramAPI\Telegram\Types\WebhookInfo;
11+
use unreal4u\TelegramAPI\TgLog;
12+
13+
$loop = Factory::create();
14+
$tgLog = new TgLog(BOT_TOKEN, new HttpClientRequestHandler($loop));
15+
16+
$webHookInfo = new GetWebhookInfo();
17+
$promise = $tgLog->performApiRequest($webHookInfo);
18+
19+
$promise->then(
20+
function (WebhookInfo $info) {
21+
echo '<pre>';
22+
var_dump($info);
23+
echo '</pre>';
24+
},
25+
function (\Exception $e) {
26+
var_dump($e);
27+
}
28+
);
29+
$loop->run();

examples/send-audio.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
declare(strict_types = 1);
44

5-
include 'basics.php';
5+
include __DIR__.'/basics.php';
66

7+
use React\EventLoop\Factory;
8+
use unreal4u\TelegramAPI\HttpClientRequestHandler;
79
use unreal4u\TelegramAPI\Telegram\Methods\SendAudio;
810
use unreal4u\TelegramAPI\Telegram\Types\Custom\InputFile;
911
use unreal4u\TelegramAPI\TgLog;
1012

11-
$loop = \React\EventLoop\Factory::create();
12-
$handler = new \unreal4u\TelegramAPI\HttpClientRequestHandler($loop);
13-
$tgLog = new TgLog(BOT_TOKEN, $handler);
13+
$loop = Factory::create();
14+
$tgLog = new TgLog(BOT_TOKEN, new HttpClientRequestHandler($loop));
1415

1516
$sendAudio = new SendAudio();
1617
$sendAudio->chat_id = A_USER_CHAT_ID;

examples/send-chat-action.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
declare(strict_types = 1);
44

5-
include 'basics.php';
5+
include __DIR__.'/basics.php';
66

7+
use React\EventLoop\Factory;
8+
use unreal4u\TelegramAPI\HttpClientRequestHandler;
79
use unreal4u\TelegramAPI\Telegram\Methods\SendChatAction;
810
use unreal4u\TelegramAPI\Telegram\Methods\SendMessage;
911
use unreal4u\TelegramAPI\TgLog;
1012

11-
$loop = \React\EventLoop\Factory::create();
12-
$handler = new \unreal4u\TelegramAPI\HttpClientRequestHandler($loop);
13-
$tgLog = new TgLog(BOT_TOKEN, $handler);
13+
$loop = Factory::create();
14+
$tgLog = new TgLog(BOT_TOKEN, new HttpClientRequestHandler($loop));
1415

1516
$sendMessage = new SendMessage();
1617
$sendMessage->chat_id = A_USER_CHAT_ID;

examples/send-document.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
declare(strict_types = 1);
44

5-
include 'basics.php';
5+
include __DIR__.'/basics.php';
66

7+
use React\EventLoop\Factory;
8+
use unreal4u\TelegramAPI\HttpClientRequestHandler;
79
use unreal4u\TelegramAPI\Telegram\Methods\SendDocument;
810
use unreal4u\TelegramAPI\Telegram\Types\Custom\InputFile;
911
use unreal4u\TelegramAPI\TgLog;
1012

11-
$loop = \React\EventLoop\Factory::create();
12-
$handler = new \unreal4u\TelegramAPI\HttpClientRequestHandler($loop);
13-
$tgLog = new TgLog(BOT_TOKEN, $handler);
13+
$loop = Factory::create();
14+
$tgLog = new TgLog(BOT_TOKEN, new HttpClientRequestHandler($loop));
1415

1516
$sendDocument = new SendDocument();
1617
$sendDocument->chat_id = A_USER_CHAT_ID;

examples/send-invoice.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
declare(strict_types = 1);
44

5-
include 'basics.php';
5+
include __DIR__.'/basics.php';
66

7+
use React\EventLoop\Factory;
8+
use unreal4u\TelegramAPI\HttpClientRequestHandler;
79
use unreal4u\TelegramAPI\Telegram\Methods\SendInvoice;
810
use unreal4u\TelegramAPI\Telegram\Types\LabeledPrice;
911
use unreal4u\TelegramAPI\TgLog;
1012

11-
$loop = \React\EventLoop\Factory::create();
12-
$handler = new \unreal4u\TelegramAPI\HttpClientRequestHandler($loop);
13-
$tgLog = new TgLog(BOT_TOKEN, $handler);
13+
$loop = Factory::create();
14+
$tgLog = new TgLog(BOT_TOKEN, new HttpClientRequestHandler($loop));
1415

1516
$sendInvoice = new SendInvoice();
1617
$sendInvoice->chat_id = A_USER_CHAT_ID;

examples/send-location.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
declare(strict_types = 1);
44

5-
include 'basics.php';
5+
include __DIR__.'/basics.php';
66

7+
use React\EventLoop\Factory;
8+
use unreal4u\TelegramAPI\HttpClientRequestHandler;
79
use unreal4u\TelegramAPI\Telegram\Methods\SendLocation;
810
use unreal4u\TelegramAPI\TgLog;
911

10-
$loop = \React\EventLoop\Factory::create();
11-
$handler = new \unreal4u\TelegramAPI\HttpClientRequestHandler($loop);
12-
$tgLog = new TgLog(BOT_TOKEN, $handler);
12+
$loop = Factory::create();
13+
$tgLog = new TgLog(BOT_TOKEN, new HttpClientRequestHandler($loop));
1314

1415
$location = new SendLocation();
1516
$location->chat_id = A_USER_CHAT_ID;

examples/send-message-and-edit.php

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
declare(strict_types = 1);
44

5-
include 'basics.php';
5+
include __DIR__.'/basics.php';
66

7+
use React\EventLoop\Factory;
8+
use unreal4u\TelegramAPI\HttpClientRequestHandler;
79
use Monolog\Handler\StreamHandler;
810
use Monolog\Logger;
911
use unreal4u\TelegramAPI\Telegram\Methods\EditMessageText;
@@ -14,34 +16,36 @@
1416
$logger = new Logger('CUSTOM-EXAMPLE');
1517
$logger->pushHandler(new StreamHandler('logs/custom-example.log'));
1618

17-
$loop = \React\EventLoop\Factory::create();
18-
$handler = new \unreal4u\TelegramAPI\HttpClientRequestHandler($loop);
19-
$tgLog = new TgLog(BOT_TOKEN, $handler, $logger);
19+
$loop = Factory::create();
20+
$tgLog = new TgLog(BOT_TOKEN, new HttpClientRequestHandler($loop), $logger);
2021
$sendMessage = new SendMessage();
2122
$sendMessage->chat_id = A_USER_CHAT_ID;
2223
$sendMessage->text = 'Hello world, this is a test';
23-
$promise = $tgLog->performApiRequest($sendMessage);
24+
$firstMessagePromise = $tgLog->performApiRequest($sendMessage);
25+
$loop->run();
2426

2527
sleep(3);
26-
$promise->then(function (Message $message) use ($tgLog) {
27-
$editMessageText = new EditMessageText();
28-
$editMessageText->message_id = $message->message_id;
29-
$editMessageText->chat_id = $message->chat->id;
30-
$editMessageText->text = 'Sorry, this is the correction of an hello world';
31-
32-
$promise = $tgLog->performApiRequest($editMessageText);
33-
34-
$promise->then(
35-
function ($response) {
36-
echo '<pre>';
37-
var_dump($response);
38-
echo '</pre>';
39-
},
40-
function (\Exception $exception) {
41-
// Onoes, an exception occurred...
42-
echo 'Exception ' . get_class($exception) . ' caught, message: ' . $exception->getMessage();
43-
}
44-
);
45-
});
28+
$firstMessagePromise->then(
29+
function (Message $message) use ($tgLog) {
30+
$editMessageText = new EditMessageText();
31+
$editMessageText->message_id = $message->message_id;
32+
$editMessageText->chat_id = $message->chat->id;
33+
$editMessageText->text = 'Sorry, this is the correction of an hello world';
34+
35+
$messageCorrectionPromise = $tgLog->performApiRequest($editMessageText);
36+
37+
$messageCorrectionPromise->then(
38+
function ($response) {
39+
echo '<pre>';
40+
var_dump($response);
41+
echo '</pre>';
42+
},
43+
function (\Exception $exception) {
44+
// Onoes, an exception occurred...
45+
echo 'Exception ' . get_class($exception) . ' caught, message: ' . $exception->getMessage();
46+
}
47+
);
48+
}
49+
);
4650

4751
$loop->run();

examples/send-message-with-inlinekeyboard.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
declare(strict_types = 1);
44

5-
include 'basics.php';
5+
include __DIR__.'/basics.php';
66

7+
use React\EventLoop\Factory;
8+
use unreal4u\TelegramAPI\HttpClientRequestHandler;
79
use unreal4u\TelegramAPI\Telegram\Methods\SendMessage;
810
use unreal4u\TelegramAPI\Telegram\Types\Inline\Keyboard\Markup;
911
use unreal4u\TelegramAPI\TgLog;
1012

11-
$loop = \React\EventLoop\Factory::create();
12-
$handler = new \unreal4u\TelegramAPI\HttpClientRequestHandler($loop);
13-
$tgLog = new TgLog(BOT_TOKEN, $handler);
13+
$loop = Factory::create();
14+
$tgLog = new TgLog(BOT_TOKEN, new HttpClientRequestHandler($loop));
1415

1516
$sendMessage = new SendMessage();
1617
$sendMessage->chat_id = A_USER_CHAT_ID;

examples/send-message-with-keyboard-options.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
declare(strict_types = 1);
44

5-
include 'basics.php';
5+
include __DIR__.'/basics.php';
66

7+
use React\EventLoop\Factory;
8+
use unreal4u\TelegramAPI\HttpClientRequestHandler;
79
use unreal4u\TelegramAPI\Telegram\Methods\SendMessage;
810
use unreal4u\TelegramAPI\Telegram\Types\KeyboardButton;
911
use unreal4u\TelegramAPI\Telegram\Types\ReplyKeyboardMarkup;
1012
use unreal4u\TelegramAPI\TgLog;
1113

12-
$loop = \React\EventLoop\Factory::create();
13-
$handler = new \unreal4u\TelegramAPI\HttpClientRequestHandler($loop);
14-
$tgLog = new TgLog(BOT_TOKEN, $handler);
14+
$loop = Factory::create();
15+
$tgLog = new TgLog(BOT_TOKEN, new HttpClientRequestHandler($loop));
1516

1617
$sendMessage = new SendMessage();
1718
$sendMessage->chat_id = A_USER_CHAT_ID;

examples/send-message.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
declare(strict_types = 1);
44

5-
include 'basics.php';
5+
include __DIR__.'/basics.php';
66

7+
use React\EventLoop\Factory;
8+
use unreal4u\TelegramAPI\HttpClientRequestHandler;
79
use unreal4u\TelegramAPI\Telegram\Methods\SendMessage;
810
use unreal4u\TelegramAPI\TgLog;
911

10-
$loop = \React\EventLoop\Factory::create();
11-
$handler = new \unreal4u\TelegramAPI\HttpClientRequestHandler($loop);
12-
$tgLog = new TgLog(BOT_TOKEN, $handler);
12+
$loop = Factory::create();
13+
$tgLog = new TgLog(BOT_TOKEN, new HttpClientRequestHandler($loop));
1314

1415
$sendMessage = new SendMessage();
1516
$sendMessage->chat_id = A_USER_CHAT_ID;

0 commit comments

Comments
 (0)