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

Commit 22d4461

Browse files
authored
Merge pull request #61 from Yoshi2889/sendchataction
Fix send-chat-action example
2 parents 5a7b924 + 82478e6 commit 22d4461

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

examples/send-chat-action.php

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,27 @@
2121
$sendChatAction->chat_id = A_USER_CHAT_ID;
2222
$sendChatAction->action = 'typing';
2323

24-
$tgLog->performApiRequest($sendChatAction);
25-
// Some heavy operation you have to perform, in our case, it will 2 seconds
26-
sleep(2);
27-
28-
$sendMessage->text = 'The second piece of text';
29-
30-
$promise = $tgLog->performApiRequest($sendMessage);
31-
32-
$promise->then(
33-
function ($response) {
34-
echo '2nd message sent' . PHP_EOL;
35-
echo '<pre>';
36-
var_dump($response);
37-
echo '</pre>';
38-
},
39-
function (\Exception $exception) {
40-
// Onoes, an exception occurred...
41-
echo 'Exception ' . get_class($exception) . ' caught, message: ' . $exception->getMessage();
42-
}
43-
);
24+
$promise = $tgLog->performApiRequest($sendChatAction);
25+
26+
$promise->then(function () use ($tgLog, $sendMessage) {
27+
sleep(3);
28+
29+
$sendMessage->text = 'The second piece of text';
30+
31+
$promise = $tgLog->performApiRequest($sendMessage);
32+
33+
$promise->then(
34+
function ($response) {
35+
echo '2nd message sent' . PHP_EOL;
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+
});
4446

4547
$loop->run();

0 commit comments

Comments
 (0)