File tree Expand file tree Collapse file tree 3 files changed +49
-6
lines changed Expand file tree Collapse file tree 3 files changed +49
-6
lines changed Original file line number Diff line number Diff line change @@ -5,10 +5,13 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
5
5
6
6
## [ Unreleased]
7
7
### Added
8
+ - Custom output callback can be defined for getUpdates method.
8
9
### Changed
10
+ - Default output of getUpdates method now shows the message type or query text, not the text message content.
9
11
### Deprecated
10
12
### Removed
11
13
### Fixed
14
+ - GetUpdates method would crash if a non-text message was sent.
12
15
### Security
13
16
14
17
## [ 1.1.0] - 2017-05-23
Original file line number Diff line number Diff line change @@ -325,6 +325,43 @@ $bot = new BotManager([
325
325
326
326
Now, the updates can be done either through the [ browser] ( #via-browser ) or [ via CLI] ( #via-cli ) .
327
327
328
+ #### Custom getUpdates output
329
+
330
+ A callback can be defined, to override the default output when updates are handled via getUpdates.
331
+
332
+ Example of the default output:
333
+ ```
334
+ ...
335
+ 2017-07-10 14:59:25 - Updates processed: 1
336
+ 123456: <text>
337
+ 2017-07-10 14:59:27 - Updates processed: 0
338
+ 2017-07-10 14:59:30 - Updates processed: 0
339
+ 2017-07-10 14:59:32 - Updates processed: 0
340
+ 2017-07-10 14:59:34 - Updates processed: 1
341
+ 123456: <photo>
342
+ 2017-07-10 14:59:36 - Updates processed: 0
343
+ ...
344
+ ```
345
+
346
+ Using custom callback that must return a string:
347
+ ``` php
348
+ // In manager.php after $bot has been defined:
349
+ $bot->setCustomGetUpdatesCallback(function (ServerResponse $get_updates_response) {
350
+ $results = array_filter((array) $get_updates_response->getResult());
351
+
352
+ return sprintf('There are %d update(s)' . PHP_EOL, count($results));
353
+ });
354
+ ```
355
+ output:
356
+ ```
357
+ ...
358
+ There are 0 update(s)
359
+ There are 0 update(s)
360
+ There are 2 update(s)
361
+ There are 1 update(s)
362
+ ...
363
+ ```
364
+
328
365
## Development
329
366
330
367
When running live bot tests on a fork, you must enter the following environment variables to your [ repository settings] [ travis-repository-settings ] on travis-ci.org:
Original file line number Diff line number Diff line change @@ -478,25 +478,28 @@ public function handleGetUpdates(): self
478
478
*/
479
479
protected function defaultGetUpdatesCallback ($ get_updates_response ): string
480
480
{
481
+ /** @var Entities\Update[] $results */
481
482
$ results = array_filter ((array ) $ get_updates_response ->getResult ());
482
483
483
- $ output = date ('Y-m-d H:i:s ' ) . ' - ' ;
484
- $ output .= sprintf ('Updates processed: %d ' . PHP_EOL , count ($ results ));
484
+ $ output = sprintf (
485
+ '%s - Updates processed: %d ' . PHP_EOL ,
486
+ date ('Y-m-d H:i:s ' ),
487
+ count ($ results )
488
+ );
485
489
486
- /** @var Entities\Update $result */
487
490
foreach ($ results as $ result ) {
488
491
$ chat_id = 0 ;
489
- $ text = 'Nothing ' ;
492
+ $ text = '<n/a> ' ;
490
493
491
494
$ update_content = $ result ->getUpdateContent ();
492
495
if ($ update_content instanceof Entities \Message) {
493
496
$ chat_id = $ update_content ->getFrom ()->getId ();
494
- $ text = $ update_content ->getType ();
497
+ $ text = sprintf ( ' <%s> ' , $ update_content ->getType () );
495
498
} elseif ($ update_content instanceof Entities \InlineQuery ||
496
499
$ update_content instanceof Entities \ChosenInlineResult
497
500
) {
498
501
$ chat_id = $ update_content ->getFrom ()->getId ();
499
- $ text = $ update_content ->getQuery ();
502
+ $ text = sprintf ( ' <query> %s ' , $ update_content ->getQuery () );
500
503
}
501
504
502
505
$ output .= sprintf (
You can’t perform that action at this time.
0 commit comments