Skip to content

Commit 3c1e22e

Browse files
committed
Fix and improve getUpdates output.
1 parent 76a09d4 commit 3c1e22e

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
1414
### Removed
1515
- Botan.io has been removed (see php-telegram-bot/core#924). (#50)
1616
### Fixed
17+
- Fix and improve getUpdates output.
1718
### Security
1819
- Security disclosure managed by [Tidelift]. (#49)
1920

src/BotManager.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use Exception;
1414
use Longman\IPTools\Ip;
15+
use Longman\TelegramBot\Entities\CallbackQuery;
1516
use Longman\TelegramBot\Entities\ChosenInlineResult;
1617
use Longman\TelegramBot\Entities\InlineQuery;
1718
use Longman\TelegramBot\Entities\Message;
@@ -510,22 +511,27 @@ protected function defaultGetUpdatesCallback($get_updates_response): string
510511
);
511512

512513
foreach ($results as $result) {
513-
$chat_id = 0;
514-
$text = '<n/a>';
515-
516514
$update_content = $result->getUpdateContent();
515+
516+
$chat_id = 'n/a';
517+
$text = $result->getUpdateType();
518+
517519
if ($update_content instanceof Message) {
520+
/** @var Message $update_content */
518521
$chat_id = $update_content->getChat()->getId();
519-
$text = sprintf('<%s>', $update_content->getType());
520-
} elseif ($update_content instanceof InlineQuery
521-
|| $update_content instanceof ChosenInlineResult
522-
) {
522+
$text .= ";{$update_content->getType()}";
523+
} elseif ($update_content instanceof InlineQuery || $update_content instanceof ChosenInlineResult) {
524+
/** @var InlineQuery|ChosenInlineResult $update_content */
523525
$chat_id = $update_content->getFrom()->getId();
524-
$text = sprintf('<query> %s', $update_content->getQuery());
526+
$text .= ";{$update_content->getQuery()}";
527+
} elseif ($update_content instanceof CallbackQuery) {
528+
/** @var CallbackQuery $update_content */
529+
$chat_id = $update_content->getMessage()->getChat()->getId();
530+
$text .= ";{$update_content->getData()}";
525531
}
526532

527533
$output .= sprintf(
528-
'%d: %s' . PHP_EOL,
534+
'%d: <%s>' . PHP_EOL,
529535
$chat_id,
530536
preg_replace('/\s+/', ' ', trim($text))
531537
);

0 commit comments

Comments
 (0)