Class: BotMob::Bot
- Inherits:
-
Object
- Object
- BotMob::Bot
- Extended by:
- Forwardable
- Defined in:
- lib/bot_mob/bot.rb
Overview
## BotMob::Bot
This is the base for all bots that will connect to respond to messages received by your application.
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#network ⇒ Object
Returns the value of attribute network.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(*args) ⇒ Bot
constructor
A new instance of Bot.
- #key ⇒ Object
- #receive(message) ⇒ Object
- #respond(inbound_message) ⇒ Object
- #respond?(inbound_message) ⇒ Boolean
Constructor Details
#initialize(*args) ⇒ Bot
Returns a new instance of Bot.
15 16 17 |
# File 'lib/bot_mob/bot.rb', line 15 def initialize(*args) @network, @id, @options = *args end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
9 10 11 |
# File 'lib/bot_mob/bot.rb', line 9 def id @id end |
#network ⇒ Object
Returns the value of attribute network.
9 10 11 |
# File 'lib/bot_mob/bot.rb', line 9 def network @network end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/bot_mob/bot.rb', line 10 def @options end |
Instance Method Details
#key ⇒ Object
19 20 21 |
# File 'lib/bot_mob/bot.rb', line 19 def key "#{network}.#{id}" end |
#receive(message) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/bot_mob/bot.rb', line 23 def receive() = .is_a?(String) ? BotMob::InboundMessage.new() : return unless respond?() BotMob.logger.info("Received message at #{Time.now}") BotMob.logger.info(" Parameters: #{.params}") respond() end |
#respond(inbound_message) ⇒ Object
32 33 34 35 |
# File 'lib/bot_mob/bot.rb', line 32 def respond() outbound = BotMob::OutboundMessage.new(text: "#{self.class} ACK! #{.text}") deliver(outbound) end |
#respond?(inbound_message) ⇒ Boolean
37 38 39 |
# File 'lib/bot_mob/bot.rb', line 37 def respond?() true end |