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

Bot doesn't work with credentials #74

Closed
npupko opened this issue Apr 23, 2018 · 11 comments
Closed

Bot doesn't work with credentials #74

npupko opened this issue Apr 23, 2018 · 11 comments

Comments

@npupko
Copy link

npupko commented Apr 23, 2018

I added in credentials:

telegram:
  bot: MY_TOKEN

but at start telegram:bot:poller I get an error Poller not found for :default
The token is exactly correct and works on another version of rails with secrets.yml

Help, please, in what format should I setup the yaml configuration?

Tracelog:

Poller not found for :default
/Users/random/.rvm/gems/ruby-2.5.0/gems/telegram-bot-0.13.0/lib/telegram/bot/updates_poller.rb:20:in `start'
/Users/random/.rvm/gems/ruby-2.5.0/gems/telegram-bot-0.13.0/lib/tasks/telegram-bot.rake:12:in `block (3 levels) in <main>'
/Users/random/.rvm/gems/ruby-2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:50:in `load'
/Users/random/.rvm/gems/ruby-2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:50:in `load'
/Users/random/.rvm/gems/ruby-2.5.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:277:in `block in load'
/Users/random/.rvm/gems/ruby-2.5.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:249:in `load_dependency'
/Users/random/.rvm/gems/ruby-2.5.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:277:in `load'
-e:1:in `<main>'
Tasks: TOP => telegram:bot:poller
(See full trace by running task with --trace)

Ruby: 2.5.0
Rails: 5.2.0

@printercu
Copy link
Member

Is config correctly fetched with Rails.application.credentials[:telegram]?

@npupko
Copy link
Author

npupko commented Apr 24, 2018

Sure. All works fine with bin/rails console too

@printercu
Copy link
Member

All works fine with bin/rails console too

You mean bot works fine in console? Telegram.bots_config also returns valid config?

@npupko
Copy link
Author

npupko commented Apr 24, 2018

Right.

2.5.0 :001 > Rails.application.credentials[:telegram]
 => {:bot=>"MY_TOKEN"}
2.5.0 :002 > Telegram.bots_config
 => {:default=>"MY_TOKEN"}

But poller doesn't work

rake telegram:bot:poller --trace                                                                                                                                                                                                                                      130 ↵
** Invoke telegram:bot:poller (first_time)
** Execute telegram:bot:poller
** Invoke environment (first_time)
** Execute environment
rake aborted!
Poller not found for :default
/Users/random/.rvm/gems/ruby-2.5.0/gems/telegram-bot-0.13.0/lib/telegram/bot/updates_poller.rb:20:in `start'
/Users/random/.rvm/gems/ruby-2.5.0/gems/telegram-bot-0.13.0/lib/tasks/telegram-bot.rake:12:in `block (3 levels) in <main>'
/Users/random/.rvm/gems/ruby-2.5.0/gems/rake-12.3.1/lib/rake/task.rb:271:in `block in execute'
/Users/random/.rvm/gems/ruby-2.5.0/gems/rake-12.3.1/lib/rake/task.rb:271:in `each'
/Users/random/.rvm/gems/ruby-2.5.0/gems/rake-12.3.1/lib/rake/task.rb:271:in `execute'
/Users/random/.rvm/gems/ruby-2.5.0/gems/rake-12.3.1/lib/rake/task.rb:213:in `block in invoke_with_call_chain'
/Users/random/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/monitor.rb:226:in `mon_synchronize'
/Users/random/.rvm/gems/ruby-2.5.0/gems/rake-12.3.1/lib/rake/task.rb:193:in `invoke_with_call_chain'
/Users/random/.rvm/gems/ruby-2.5.0/gems/rake-12.3.1/lib/rake/task.rb:182:in `invoke'
/Users/random/.rvm/gems/ruby-2.5.0/gems/rake-12.3.1/lib/rake/application.rb:160:in `invoke_task'
/Users/random/.rvm/gems/ruby-2.5.0/gems/rake-12.3.1/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/Users/random/.rvm/gems/ruby-2.5.0/gems/rake-12.3.1/lib/rake/application.rb:116:in `each'
/Users/random/.rvm/gems/ruby-2.5.0/gems/rake-12.3.1/lib/rake/application.rb:116:in `block in top_level'
/Users/random/.rvm/gems/ruby-2.5.0/gems/rake-12.3.1/lib/rake/application.rb:125:in `run_with_threads'
/Users/random/.rvm/gems/ruby-2.5.0/gems/rake-12.3.1/lib/rake/application.rb:110:in `top_level'
/Users/random/.rvm/gems/ruby-2.5.0/gems/rake-12.3.1/lib/rake/application.rb:83:in `block in run'
/Users/random/.rvm/gems/ruby-2.5.0/gems/rake-12.3.1/lib/rake/application.rb:186:in `standard_exception_handling'
/Users/random/.rvm/gems/ruby-2.5.0/gems/rake-12.3.1/lib/rake/application.rb:80:in `run'
/Users/random/.rvm/gems/ruby-2.5.0/gems/rake-12.3.1/exe/rake:27:in `<top (required)>'
/Users/random/.rvm/gems/ruby-2.5.0/bin/rake:23:in `load'
/Users/random/.rvm/gems/ruby-2.5.0/bin/rake:23:in `<main>'
/Users/random/.rvm/gems/ruby-2.5.0/bin/ruby_executable_hooks:15:in `eval'
/Users/random/.rvm/gems/ruby-2.5.0/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => telegram:bot:poller

@printercu
Copy link
Member

Seems like this is related: rails/rails#30717

I'll check carefully later.

@npupko
Copy link
Author

npupko commented Apr 24, 2018

@printercu Thank you, I really appreciate it!

@npupko
Copy link
Author

npupko commented Apr 24, 2018

I managed to run it from the console only like this:
Telegram::Bot::UpdatesPoller.new(Telegram.bots[:default], TelegramWebhooksController).start

@printercu
Copy link
Member

It's still not clear for me, how credentials should be used with multiple environments. There is long discussion, and still no comments on this from rails core team: rails/rails#30067.

For now here is workaround from rails/rails#30717:

If you move config.read_encrypted_secrets = true from environments\production.rb to application.rb, looks like every errors related to unread secrets are gone.

Other approach is to manually configure Telegram.bots_config= in initializers/telegram-bot.rb.

I have no ideas, how this should be properly handled in gem. Will wait for response from rails team with their vision. Suggestions are welcome.

@Soloma1488
Copy link

first u need delet old files.
EDITOR="nano" rails credentials:edit u can use any editor.
and put this code:

telegram: bot: token: <token> username: <username>

@printercu
Copy link
Member

printercu commented May 20, 2021

It works with several latest rails versions so I'll close this issue.

@gregogalante
Copy link

I think that the cause of the problem is the absence of the routes configuration in routes.rb file.

Adding this code on routes solves problems:

Rails.application.routes.draw do
  telegram_webhook TelegramController
  # ....
end

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

4 participants