Sha256: 754f0e28fc637f07b86712890519ca4dd5e0a4cc8fa7455b2fefb431bebd5431

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Slack
  module BlockKit
    module Element
      # An interactive element that inserts a button.
      # The button can be a trigger for anything from opening a simple link
      # to starting a complex workflow.
      #
      # https://api.slack.com/reference/messaging/block-elements#button
      class Button
        TYPE = 'button'

        attr_accessor :confirm

        def initialize(text:, action_id:, emoji: nil, url: nil, value: nil)
          @text = Composition::PlainText.new(text: text, emoji: emoji)
          @action_id = action_id
          @url = url
          @value = value

          yield(self) if block_given?
        end

        def confirmation_dialog
          @confirm = Composition::ConfirmationDialog.new

          yield(@confirm) if block_given?

          @confirm
        end

        def as_json(*)
          {
            type: TYPE,
            text: @text.as_json,
            action_id: @action_id,
            url: @url,
            value: @value,
            confirm: @confirm&.as_json
          }.compact
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
slack_block_kit-0.3.0 lib/slack/block_kit/element/button.rb
slack_block_kit-0.2.0 lib/slack/block_kit/element/button.rb