atipugin / telegram-bot-ruby

Ruby wrapper for Telegram's Bot API
https://core.telegram.org/bots/api
Do What The F*ck You Want To Public License
1.35k stars 217 forks source link

Getting a Missing attribute: "result" (Dry::Struct::MissingAttributeError) #307

Closed syxanash closed 3 months ago

syxanash commented 3 months ago

Hello, I recently bumped to version 2.0 everything worked fine a few days ago, and I was on 1.0 without any issues. My code has not really changed, but for some reason this morning I started getting the following error:

/Users/myuser/.rvm/gems/ruby-3.3.0/gems/dry-struct-1.6.0/lib/dry/struct.rb:148:in `block in []': Missing attribute: "result" (Dry::Struct::MissingAttributeError)
    from /Users/myuser/.rvm/gems/ruby-3.3.0/gems/dry-struct-1.6.0/lib/dry/struct.rb:148:in `fetch'
    from /Users/myuser/.rvm/gems/ruby-3.3.0/gems/dry-struct-1.6.0/lib/dry/struct.rb:148:in `[]'
        from /Users/myuser/Developer/joshua_bot/lib/plugin_handler.rb:5:in `handle'

the line that is failing is the following:

    bot_username = bot.api.getMe['result']['username']

I really can't figure out what's changed, I just bumped a few of my dependencies on the system but that is it... do you think you could help out?

this is what my Gemfile looks like:

source 'https://rubygems.org'

ruby '3.3.0'

gem 'ruby-openai', '~> 7.0.1'
gem 'telegram-bot-ruby', '~> 2.0'

# gems used by plugins
gem 'fileutils'
gem 'genius'
gem 'nokogiri'
gem 'rest-client'
gem 'similar_text'
syxanash commented 3 months ago

I figured it out, I was calling the getMe endpoint the wrong way, this is how I fixed it:

bot.api.getMe.username

Weird that the error didn't come up earlier 🤔 Anyway I'll close now, thanks!