Class: BotMob::Bot

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#idObject

Returns the value of attribute id.



9
10
11
# File 'lib/bot_mob/bot.rb', line 9

def id
  @id
end

#networkObject

Returns the value of attribute network.



9
10
11
# File 'lib/bot_mob/bot.rb', line 9

def network
  @network
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/bot_mob/bot.rb', line 10

def options
  @options
end

Instance Method Details

#keyObject



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(message)
  inbound_message = message.is_a?(String) ? BotMob::InboundMessage.new(message) : message
  return unless respond?(inbound_message)

  BotMob.logger.info("Received message at #{Time.now}")
  BotMob.logger.info("  Parameters: #{inbound_message.params}")
  respond(inbound_message)
end

#respond(inbound_message) ⇒ Object



32
33
34
35
# File 'lib/bot_mob/bot.rb', line 32

def respond(inbound_message)
  outbound = BotMob::OutboundMessage.new(text: "#{self.class} ACK! #{inbound_message.text}")
  deliver(outbound)
end

#respond?(inbound_message) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/bot_mob/bot.rb', line 37

def respond?(inbound_message)
  true
end