Class: BotMob::InboundMessage
- Inherits:
-
Object
- Object
- BotMob::InboundMessage
- Defined in:
- lib/bot_mob/inbound_message.rb
Overview
# BotMob::InboundMessage
Structured data provided to a bot
Direct Known Subclasses
Networks::Roaming::InboundMessage, Networks::Slack::InboundMessage
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#network ⇒ Object
readonly
Returns the value of attribute network.
-
#user_name ⇒ Object
readonly
Returns the value of attribute user_name.
Class Method Summary collapse
- .default_network ⇒ Object
- .default_user_name ⇒ Object
- .message_attributes ⇒ Object
- .message_attrs(*attrs) ⇒ Object
-
.prepare(message, options = {}) ⇒ Object
##
prepare.
Instance Method Summary collapse
-
#human? ⇒ Boolean
##
human?. -
#initialize(**options) ⇒ InboundMessage
constructor
A new instance of InboundMessage.
-
#params ⇒ Object
##
params.
Constructor Details
#initialize(**options) ⇒ InboundMessage
Returns a new instance of InboundMessage.
8 9 10 11 12 13 14 15 |
# File 'lib/bot_mob/inbound_message.rb', line 8 def initialize(**) @body ||= [:body] @network ||= [:network] ().each do |attr| instance_variable_set("@#{attr}".to_sym, [attr.to_sym]) end end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
6 7 8 |
# File 'lib/bot_mob/inbound_message.rb', line 6 def body @body end |
#network ⇒ Object (readonly)
Returns the value of attribute network.
6 7 8 |
# File 'lib/bot_mob/inbound_message.rb', line 6 def network @network end |
#user_name ⇒ Object (readonly)
Returns the value of attribute user_name.
6 7 8 |
# File 'lib/bot_mob/inbound_message.rb', line 6 def user_name @user_name end |
Class Method Details
.default_network ⇒ Object
68 69 70 |
# File 'lib/bot_mob/inbound_message.rb', line 68 def default_network :roaming end |
.default_user_name ⇒ Object
64 65 66 |
# File 'lib/bot_mob/inbound_message.rb', line 64 def default_user_name ENV['MOB_NAME'] || 'nomad' end |
.message_attributes ⇒ Object
60 61 62 |
# File 'lib/bot_mob/inbound_message.rb', line 60 def || [] end |
.message_attrs(*attrs) ⇒ Object
55 56 57 58 |
# File 'lib/bot_mob/inbound_message.rb', line 55 def (*attrs) = attrs attr_reader(*) end |
.prepare(message, options = {}) ⇒ Object
## prepare
Prepare accepts three different data types and attempts to coerce it into a contextual inbound message. In the case of an inbound message, it simply assumes the provided message is already correct. In the case of a hash, it passes the hash along as the initialize attrs. In the case of a string, it overrides the body key of the provided options, then passes the options provided to prepare as the initialize params
26 27 28 29 30 31 32 33 |
# File 'lib/bot_mob/inbound_message.rb', line 26 def self.prepare(, = {}) return if .is_a?(BotMob::InboundMessage) .symbolize_keys! approach = "prepare_#{message.class.to_s.downcase}_attrs".to_sym attrs = send(approach, , ) (attrs[:network]).new(attrs) end |
Instance Method Details
#human? ⇒ Boolean
## human?
This should be overrode in the inheriting bot class. Use this to determine if the inbound message was written by a human
39 40 41 |
# File 'lib/bot_mob/inbound_message.rb', line 39 def human? ENV['MOB_NAME'] != user_name end |
#params ⇒ Object
## params
A representation of the relevant data attached to a bot
46 47 48 49 50 51 52 |
# File 'lib/bot_mob/inbound_message.rb', line 46 def params @params ||= { body: body, network: network, user_name: user_name } end |