💎 ChatSDK Ruby

API: Modals

ChatSDK::Modals::Builder provides a DSL for constructing modal dialogs with text inputs, select menus, and static text.

ChatSDK::Modals::Builder provides a DSL for constructing modal dialogs that can be opened via Thread#open_modal. Modals are built as Cards::Node trees of type :modal.

Constructor

ChatSDK::Modals::Builder.new(
  title:,
  submit_label: nil,
  callback_id: nil,
  &block
)
ParameterTypeRequiredDefaultDescription
titleStringYes--Modal title
submit_labelStringNonilCustom label for the submit button
callback_idStringNonilCallback ID for identifying submissions

Building a Modal

modal = ChatSDK::Modals::Builder.new(
  title: "Create Incident",
  submit_label: "Submit",
  callback_id: "create_incident"
) do
  static_text "Please fill out the details below."

  text_input id: "title",
             label: "Incident Title",
             placeholder: "Brief description"

  text_input id: "description",
             label: "Description",
             placeholder: "What happened?",
             multiline: true,
             optional: true

  select_input id: "severity", label: "Severity", placeholder: "Choose severity" do
    option "Critical", value: "sev1"
    option "Major",    value: "sev2"
    option "Minor",    value: "sev3", description: "Non-urgent issue"
  end
end.build

Call .build to produce a Cards::Node of type :modal.

Instance Methods

text_input(id:, label:, placeholder: nil, multiline: false, optional: false)

Adds a text input field to the modal.

text_input id: "name", label: "Your Name"
text_input id: "notes", label: "Notes", multiline: true, optional: true
ParameterTypeRequiredDefaultDescription
idStringYes--Input identifier
labelStringYes--Display label
placeholderStringNonilPlaceholder text
multilineBooleanNofalseAllow multi-line input
optionalBooleanNofalseWhether the field is optional

Produces a Cards::Node of type :input with input_type: :text.

select_input(id:, label:, placeholder: nil, optional: false, &block)

Adds a select dropdown to the modal. Use option inside the block to define choices (same DSL as card selects via Cards::SelectContext).

select_input id: "team", label: "Team" do
  option "Backend",  value: "backend"
  option "Frontend", value: "frontend"
end
ParameterTypeRequiredDefaultDescription
idStringYes--Input identifier
labelStringYes--Display label
placeholderStringNonilPlaceholder text
optionalBooleanNofalseWhether the field is optional

Produces a Cards::Node of type :input with input_type: :select and option children.

static_text(content)

Adds a read-only text block to the modal.

static_text "This action cannot be undone."
ParameterTypeRequiredDescription
contentStringYesText content to display

Produces a Cards::Node of type :text.

build

Builds and returns the final Cards::Node of type :modal.

node = builder.build
# => Cards::Node(type: :modal, attributes: {title: "...", ...}, children: [...])

The returned node can be passed to Thread#open_modal or Adapter::Base#open_modal.

On this page