Sha256: 9b7e2f691bf21f3e7263aed874caba41b2e2f2c8c2e16a83628e1f364f1ddabb

Contents?: true

Size: 912 Bytes

Versions: 4

Compression:

Stored size: 912 Bytes

Contents

# rubocop:disable Metrics/MethodLength

module UI
  ########################### OPEN GRAPH TEMPLATE #############################
  # https://developers.facebook.com/docs/messenger-platform/send-messages/template/open-graph
  class FBOpenGraphTemplate < UI::BaseUiElement
    include UI::Common::HasButtons

    def initialize(url, buttons = [])
      @url = url
      @buttons = buttons

      @template = {
        recipient: {
          id: nil
        },
        message: {
          attachment: {
            type: 'template',
            payload: {
              template_type: 'open_graph',
              elements: elements
            }
          }
        }
      }
    end

    private

    attr_reader :url, :buttons

    def elements
      res = { url: url }

      buttons_payload = parse_buttons(buttons)
      res[:buttons] = buttons_payload if buttons_payload.any?

      [res]
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubotnik-0.2.3 lib/ui/fb_open_graph_template.rb
rubotnik-0.2.2 lib/ui/fb_open_graph_template.rb
rubotnik-0.2.1 lib/ui/fb_open_graph_template.rb
rubotnik-0.2.0 lib/ui/fb_open_graph_template.rb