Sha256: 615748c84880edb48e0ce825344826d26f363f654c11cd7c7a6d3be6a4b3fbbc
Contents?: true
Size: 1.64 KB
Versions: 28
Compression:
Stored size: 1.64 KB
Contents
module Bobot module Event class Message include Bobot::Event::Common ATTACHMENT_TYPES = %w[image audio video file location fallback].freeze def id @messaging['message']['mid'] end def seq @messaging['message']['seq'] end def text @messaging['message']['text'] end def echo? @messaging['message']['is_echo'].present? end def attachments @messaging['message']['attachments'] end def nlp @messaging['message']['nlp'] end def app_id @messaging['message']['app_id'] end ATTACHMENT_TYPES.each do |attachment_type| define_method "#{attachment_type}_attachment?" do attachment_type?(attachment_type) end end def attachment_type return if attachments.nil? attachments.first['type'] end def attachment_url return if attachments.nil? return unless %w[image audio video file].include? attachment_type attachments.first['payload']['url'] end def location_coordinates return [] unless attachment_type?('location') coordinates_data = attachments.first['payload']['coordinates'] [coordinates_data['lat'], coordinates_data['long']] end def quick_reply return unless @messaging['message']['quick_reply'] @messaging['message']['quick_reply']['payload'] end alias_method :payload, :quick_reply private def attachment_type?(attachment_type) !attachments.nil? && attachments.first['type'] == attachment_type end end end end
Version data entries
28 entries across 28 versions & 1 rubygems