module Kamiflex::BasicElements

Public Instance Methods

filler() click to toggle source
# File lib/kamiflex/basic_elements.rb, line 54
def filler
  @flex_contents << {
    "type": "filler"
  }
end
icon(url, **params) click to toggle source
# File lib/kamiflex/basic_elements.rb, line 32
def icon(url, **params)
  @flex_contents << {
    "type": "icon",
    "url": url
  }.merge(params)
end
image(url, **params) click to toggle source
# File lib/kamiflex/basic_elements.rb, line 25
def image(url, **params)
  @flex_contents << {
    "type": "image",
    "url": url
  }.merge(params)
end
message_button(label, message, **params) click to toggle source
# File lib/kamiflex/basic_elements.rb, line 80
def message_button(label, message, **params)
  @flex_contents << {
    "type": "button",
    "action": {
      "type": "message",
      "label": label,
      "text": message
    }
  }.merge(params)
end
postback_button(label, data, **params) click to toggle source
# File lib/kamiflex/basic_elements.rb, line 91
def postback_button(label, data, **params)
  @flex_contents << {
    "type": "button",
    "action": {
      "type": "postback",
      "label": label,
      "data": data,
    }
  }.merge(params)
end
postback_text_button(label, message, data, **params) click to toggle source
# File lib/kamiflex/basic_elements.rb, line 102
def postback_text_button(label, message, data, **params)
  @flex_contents << {
    "type": "button",
    "action": {
      "type": "postback",
      "label": label,
      "displayText": message,
      "data": data,
    }
  }.merge(params)
end
separator(**params) click to toggle source
# File lib/kamiflex/basic_elements.rb, line 39
def separator(**params)
  @flex_contents << {
    "type": "separator",
    "margin": "md",
    "color": "#000000",
  }.merge(params)
end
spacer(**params) click to toggle source
# File lib/kamiflex/basic_elements.rb, line 47
def spacer(**params)
  @flex_contents << {
    "type": "spacer",
    "size": "md",
  }.merge(params)
end
span(message, **params) click to toggle source
# File lib/kamiflex/basic_elements.rb, line 18
def span(message, **params)
  @flex_contents << {
    "type": "span",
    "text": message
  }.merge(params)
end
text(message = nil, **params) { || ... } click to toggle source
# File lib/kamiflex/basic_elements.rb, line 3
def text(message = nil, **params)
  if block_given?
    _attributes, contents = flex_scope{ yield }
    @flex_contents << {
      type: "text",
      contents: contents,
    }.merge(params)
  else
    @flex_contents << {
      type: "text",
      text: message
    }.merge(params)
  end
end
url_button(label, url, **params) click to toggle source
# File lib/kamiflex/basic_elements.rb, line 60
def url_button(label, url, **params)
  action = {
    type: "uri",
    label: label,
    uri: url,
  }

  if params&.dig(:desktop)
    action[:altUri] = {
      desktop: params&.dig(:desktop)
    }
    params = params.reject {|key, value| key == :desktop }
  end

  @flex_contents << {
    type: "button",
    action: action
  }.merge(params)
end