class UI::QuickReplies

developers.facebook.com/docs/messenger-platform/send-api-reference/quick-replies

Public Class Methods

build(*replies) click to toggle source
# File lib/ui/quick_replies.rb, line 4
def self.build(*replies)
  replies.map do |reply|
    case reply
    when Hash then build_from_hash(reply)
    when Array then build_from_array(reply)
    when String then build_from_string(reply)
    else
      raise ArgumentError, 'Arguments should be hashes or arrays of two'
    end
  end
end
location() click to toggle source
# File lib/ui/quick_replies.rb, line 16
def self.location
  [{ content_type: 'location' }]
end

Private Class Methods

build_from_array(reply) click to toggle source
# File lib/ui/quick_replies.rb, line 32
                     def self.build_from_array(reply)
  error_msg = 'Only accepts arrays of two elements'
  raise ArgumentError, error_msg if reply.length != 2
  { content_type: 'text', title: reply[0].to_s, payload: reply[1].to_s }
end
build_from_hash(reply) click to toggle source
# File lib/ui/quick_replies.rb, line 20
                     def self.build_from_hash(reply)
  unless reply.key?(:content_type)
    reply[:content_type] = 'text'
    raise ArgumentError, "type 'text' should have a payload" unless reply.key?(:payload)
  end
  reply
end
build_from_string(reply) click to toggle source
# File lib/ui/quick_replies.rb, line 28
                     def self.build_from_string(reply)
  build_from_array([reply, reply.upcase])
end