Class: Igni::Bot
Instance Attribute Summary collapse
-
#hook ⇒ Object
readonly
Returns the value of attribute hook.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
-
#initialize(hash) ⇒ Bot
constructor
A new instance of Bot.
- #on(&block) ⇒ Object
- #register_webhook ⇒ Object
Methods included from API
#getMe, #getUpdates, #request, #sendMessage, #setWebhook
Constructor Details
#initialize(hash) ⇒ Bot
Returns a new instance of Bot.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/igni/bot.rb', line 13 def initialize(hash) puts "Igni version " + Igni::VERSION abort 'No token specified' if hash[:token] == nil abort 'No domain specified' if hash[:domain] == nil @token = hash[:token] @hook = hash[:domain] puts 'Registering webhook' if self.register_webhook puts 'Done!' else abort 'Error while registering webhook!' end abort 'Wrong token' if self.getMe['ok'] != true end |
Instance Attribute Details
#hook ⇒ Object (readonly)
Returns the value of attribute hook.
11 12 13 |
# File 'lib/igni/bot.rb', line 11 def hook @hook end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
10 11 12 |
# File 'lib/igni/bot.rb', line 10 def token @token end |
Instance Method Details
#on(&block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/igni/bot.rb', line 32 def on(&block) @app = Sinatra.new do post "/webhook/#{ENV['IGNI_TOKEN']}" do raw = request.env["rack.input"].read data = JSON.parse(raw) data["raw"] = raw puts raw block.call(data) end end @app.run! end |
#register_webhook ⇒ Object
49 50 51 |
# File 'lib/igni/bot.rb', line 49 def register_webhook self.setWebhook(@hook) end |