Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to filter updates with allowed_updates? #243

Closed
sidelux opened this issue Dec 19, 2016 · 4 comments
Closed

How to filter updates with allowed_updates? #243

sidelux opened this issue Dec 19, 2016 · 4 comments
Assignees

Comments

@sidelux
Copy link

sidelux commented Dec 19, 2016

I read days ago new api version where telegram now take possibility to filter incoming update with allowed_updates in getUpdates method.
How can i write this method correctly to receive only text messages and edited messages?

Thanks a lot!

@GochoMugo
Copy link
Collaborator

GochoMugo commented Dec 21, 2016

This feature would certainly be useful 👍


First, the current implementation of the TelegramBot#getUpdates() does not allow us to pass the allowed_updates parameter. This is being addressed in PR #245. (DONE)


Second, we need a way to provide parameters to be re-used during polling, in our Constructor. For example,

const bot = new TelegramBot(token, {
  polling: {
    // parameters reused in each request during polling
    params: {
      "allowed_updates": ["message", "edited_channel_post", "callback_query"],
    },
  },
});

This will also allow us to pass an offset to determine the first update to be pulled. However, it should be updated after each poll interval! This will close issue #14!

(DONE — commit)

@GochoMugo GochoMugo self-assigned this Dec 21, 2016
@GochoMugo GochoMugo changed the title Example to filter updates with allowed_updates? How to filter updates with allowed_updates? Jan 7, 2017
@wojpawlik
Copy link
Contributor

wojpawlik commented Jan 7, 2017

@GochoMugo or, instead of allowing users specify which updates they wanna receive, what about building that list based on the updates they listen to?

this.allowedUpdates = [];
on(event, callback) {
    super(event, callback);
    this.addAllowedUpdate(event);
}
addAllowedUpdate(event) {
    if (!this.allowedUpdates.includes(event) {
        this.allowedUpdates.push(event);
    }
}
onText() {
    // other stuff
    addAllowedUpdate('message');
}

GochoMugo added a commit that referenced this issue Feb 9, 2017
Feature:

  Please see the updated API reference for more information on this
  new option.

Side-effects:

  * `options.timeout` is deprecated!

References:

  * "Feature request": #243
@GochoMugo
Copy link
Collaborator

GochoMugo commented Feb 9, 2017

I have just added this enhancement (in commit e75d51ca8fe46059e78a74e1ece7787c881157cb). Please try out the updated master branch's code to see this feature in action. See documentation on options.params.

@GingerPlusPlus Sorry, I felt your way being too complex. We would have to coordinate when polling starts and when are done scanning for the allowed updates. However, we can discuss more on it, in depth (preferably in an entirely new issue).

GochoMugo added a commit that referenced this issue Feb 10, 2017
Added:

1. Add constructor options:
  * (#243) `options.polling.params` (by @GochoMugo, requested-by @sidelux)
1. Add methods:
  * (#74) *TelegramBot#removeReplyListener()* (by @githugger)
1. (#283) Add proper error handling (by @GochoMugo)
1. (#272) Add health-check endpoint (by @mironov)
  * `options.webHook.healthEndpoint`
1. (#152) Add test for TelegramBot#sendDocument() using 'fileOpts'
   param (by @evolun)
1. Document `options.webHook.host` (by @GochoMugo)
1. (#264) Add Bot API version to README (by @kamikazechaser)
1. Add examples:
  - (#271) WebHook on Heroku (by @TheBeastOfCaerbannog)
  - (#274) WebHook on Zeit Now (by @ferrari)

Changed:

1. (#147) Use *String#indexOf()*, instead of *RegExp#test()*, to
   find token in webhook request (by @AVVS)

Fixed:

* Fix bug:
  - (#275, #280) fix es6 syntax error on Node.js v4.x (by @CrazyAbdul)
  - (#276) promise.warning from `request-promise` (by @GochoMugo,
    reported-by @preco21)
  - (#281) fix handling error during polling (by @GochoMugo,
    reported-by @dimawebmaker)
  - (#284) fix error during deletion of already-set webhook, during
    polling (by @GochoMugo, reported-by @dcparga)
1. Fix links in documentation (by @Ni2c2k)
@GochoMugo
Copy link
Collaborator

Shipped in v0.27.0.

Thanks @sidelux and @GingerPlusPlus for contributing to this feature.

N-Agency-member pushed a commit to N-Agency-member/TelegramBot-API-Node.js- that referenced this issue Sep 3, 2024
Feature:

  Please see the updated API reference for more information on this
  new option.

Side-effects:

  * `options.timeout` is deprecated!

References:

  * "Feature request": yagop/node-telegram-bot-api#243
passion-27 added a commit to passion-27/node-telegram-bot that referenced this issue Oct 2, 2024
Feature:

  Please see the updated API reference for more information on this
  new option.

Side-effects:

  * `options.timeout` is deprecated!

References:

  * "Feature request": yagop/node-telegram-bot-api#243
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants