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

Webhook secret_token verification #201

Closed
kshnurov opened this issue Mar 2, 2023 · 4 comments
Closed

Webhook secret_token verification #201

kshnurov opened this issue Mar 2, 2023 · 4 comments

Comments

@kshnurov
Copy link

kshnurov commented Mar 2, 2023

Webhook may have a secret_token set, which will be sent in a X-Telegram-Bot-Api-Secret-Token header and could be verified.
Didn't find a default functionality for that, tried to add a before_action, but it fails with undefined local variable or method 'request' for #<Telegram::WebhookController:0x0000000011acd8>.

Am I missing something? How do I access request headers?
I guess the only way is to override middleware?

@printercu
Copy link
Member

Yes, it doesn't support token verification at the moment. As a workaround you can have something like this

Telegram::Bot::Middleware.prepend(Module.new do
  def call(env)
    verify_token(env)
    super
  end
end)

@kshnurov
Copy link
Author

kshnurov commented Mar 4, 2023

@printercu thank you! I'd like to avoid monkey-patching, is there a specific reason why the request is not passed down to a controller's dispatch and not set there?

@printercu
Copy link
Member

Because it's not available in the poller mode. Maybe it makes sense to pass it in the webhook mode and set to nil in the poller mode.

@kshnurov
Copy link
Author

kshnurov commented Mar 4, 2023

@printercu definitely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants