Class: Line::Bot::Receive::Message
- Inherits:
-
Object
- Object
- Line::Bot::Receive::Message
- Defined in:
- lib/line/bot/receive/message.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#event_type ⇒ Object
readonly
Returns the value of attribute event_type.
-
#from_channel_id ⇒ Object
readonly
Returns the value of attribute from_channel_id.
-
#from_mid ⇒ Object
readonly
Returns the value of attribute from_mid.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#to_channel_id ⇒ Object
readonly
Returns the value of attribute to_channel_id.
-
#to_mid ⇒ Object
readonly
Returns the value of attribute to_mid.
Instance Method Summary collapse
- #create_content(attrs) ⇒ Object
-
#initialize(env) ⇒ Message
constructor
A new instance of Message.
Constructor Details
#initialize(env) ⇒ Message
Returns a new instance of Message.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/line/bot/receive/message.rb', line 7 def initialize(env) @id = env['content']['id'] @from_mid = env['content']['from'] @to_mid = env['content']['to'] @from_channel_id = env['fromChannel'] @to_channel_id = env['toChannel'] @event_type = env['eventType'] @content = create_content(env['content']) end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
5 6 7 |
# File 'lib/line/bot/receive/message.rb', line 5 def content @content end |
#event_type ⇒ Object (readonly)
Returns the value of attribute event_type.
5 6 7 |
# File 'lib/line/bot/receive/message.rb', line 5 def event_type @event_type end |
#from_channel_id ⇒ Object (readonly)
Returns the value of attribute from_channel_id.
5 6 7 |
# File 'lib/line/bot/receive/message.rb', line 5 def from_channel_id @from_channel_id end |
#from_mid ⇒ Object (readonly)
Returns the value of attribute from_mid.
5 6 7 |
# File 'lib/line/bot/receive/message.rb', line 5 def from_mid @from_mid end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/line/bot/receive/message.rb', line 5 def id @id end |
#to_channel_id ⇒ Object (readonly)
Returns the value of attribute to_channel_id.
5 6 7 |
# File 'lib/line/bot/receive/message.rb', line 5 def to_channel_id @to_channel_id end |
#to_mid ⇒ Object (readonly)
Returns the value of attribute to_mid.
5 6 7 |
# File 'lib/line/bot/receive/message.rb', line 5 def to_mid @to_mid end |
Instance Method Details
#create_content(attrs) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/line/bot/receive/message.rb', line 19 def create_content(attrs) case attrs['contentType'] when Line::Bot::Message::ContentType::TEXT return Line::Bot::Message::Text.new( text: attrs['text'], ) when Line::Bot::Message::ContentType::IMAGE return Line::Bot::Message::Image.new( image_url: attrs['originalContentUrl'], preview_url: attrs['previewImageUrl'], ) when Line::Bot::Message::ContentType::VIDEO return Line::Bot::Message::Video.new( video_url: attrs['originalContentUrl'], preview_url: attrs['previewImageUrl'], ) when Line::Bot::Message::ContentType::AUDIO return Line::Bot::Message::Audio.new( audio_url: attrs['originalContentUrl'], duration: attrs['contentMetadata']['duration'].to_i, ) when Line::Bot::Message::ContentType::LOCATION return Line::Bot::Message::Location.new( title: attrs['location']['title'], address: attrs['location']['address'], latitude: attrs['location']['latitude'], longitude: attrs['location']['longitude'], ) when Line::Bot::Message::ContentType::STICKER return Line::Bot::Message::Sticker.new( stkpkgid: attrs['contentMetadata']['STKPKGID'], stkid: attrs['contentMetadata']['STKID'], stkver: attrs['contentMetadata']['STKVER'], ) else end end |