Sha256: 7ae299fd229e42dfc91b1ae5bc0cad8b21270ad9782e8042d6af4c14018c7c79

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

require "json_schematize"
require "json_schematize/generator"

require "slack_bot/events/schemas/type/block"

module SlackBot
  module Events
    module Schemas
      module Type
        class Message < JsonSchematize::Generator
          schema_default option: :dig_type, value: :string

          add_field name: :type, type: String
          add_field name: :user, type: String
          add_field name: :ts, type: String
          add_field name: :client_msg_id, type: String
          add_field name: :text, type: String
          add_field name: :team, type: String

          add_field name: :blocks, type: SlackBot::Events::Schemas::Type::Block, array_of_types: true

          add_field name: :thread_ts, type: String, required: false
          add_field name: :parent_user_id, type: String, required: false

          add_field name: :channel, type: String
          add_field name: :event_ts, type: String
          add_field name: :channel_type, type: String

          def tldr
            "type: #{type}; channel:#{channel}; raw_text:#{text}"
          end

          def thread_ts
            return_nil?(@thread_ts) ? nil : @thread_ts
          end

          def parent_user_id
            return_nil?(@parent_user_id) ? nil : @parent_user_id
          end

          private

          def return_nil?(val)
            JsonSchematize::EmptyValue === val || val.nil?
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
slack_bot-events-0.1.0 lib/slack_bot/events/schemas/type/message.rb