-
Notifications
You must be signed in to change notification settings - Fork 175
/
Copy pathsend-chat-action.php
48 lines (36 loc) · 1.3 KB
/
send-chat-action.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
declare(strict_types = 1);
include __DIR__.'/basics.php';
use React\EventLoop\Factory;
use unreal4u\TelegramAPI\HttpClientRequestHandler;
use unreal4u\TelegramAPI\Telegram\Methods\SendChatAction;
use unreal4u\TelegramAPI\Telegram\Methods\SendMessage;
use unreal4u\TelegramAPI\TgLog;
$loop = Factory::create();
$tgLog = new TgLog(BOT_TOKEN, new HttpClientRequestHandler($loop));
$sendMessage = new SendMessage();
$sendMessage->chat_id = A_USER_CHAT_ID;
$sendMessage->text = 'First message';
$tgLog->performApiRequest($sendMessage);
$sendChatAction = new SendChatAction();
$sendChatAction->chat_id = A_USER_CHAT_ID;
$sendChatAction->action = 'typing';
$promise = $tgLog->performApiRequest($sendChatAction);
$promise->then(function () use ($tgLog, $sendMessage) {
sleep(3);
$sendMessage->text = 'The second piece of text';
$promise = $tgLog->performApiRequest($sendMessage);
$promise->then(
function ($response) {
echo '2nd message sent' . PHP_EOL;
echo '<pre>';
var_dump($response);
echo '</pre>';
},
function (\Exception $exception) {
// Onoes, an exception occurred...
echo 'Exception ' . get_class($exception) . ' caught, message: ' . $exception->getMessage();
}
);
});
$loop->run();