Class: SlackBot::Events::Schemas::DataPayload

Inherits:
JsonSchematize::Generator
  • Object
show all
Defined in:
lib/slack_bot/events/schemas/data_payload.rb

Constant Summary collapse

ALLOWED_EVENT_TYPES =
[
  SlackBot::Events::Schemas::Type::ReactionModified,
  SlackBot::Events::Schemas::Type::Message,
  SlackBot::Events::Schemas::Type::Base,
]

Class Method Summary collapse

Class Method Details

.event_type(payload) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/slack_bot/events/schemas/data_payload.rb', line 39

def self.event_type(payload)
  case payload["type"]
  when "reaction_removed", "reaction_added"
    SlackBot::Events::Schemas::Type::ReactionModified.new(payload)
  when "message"
    case payload["subtype"]
    when nil
      SlackBot::Events::Schemas::Type::Message.new(payload)
    when "message_changed", "message_deleted"
      SlackBot::Events::Schemas::Type::Base.new(payload.merge("tldr" => "subtype: #{payload["subtype"]}"))
    else
      # messages that were changed can be considered, but not at this time
      SlackBot::Events::Schemas::Type::Base.new(payload)
    end
  else
    # When the event type does not exist yet; dont fret, give it the bare bones base objet that delegates
    SlackBot::Events::Schemas::Type::Base.new(payload)
  end
end