Class: Whatsapp::Webhook::Message::Base
- Inherits:
-
Object
- Object
- Whatsapp::Webhook::Message::Base
- Defined in:
- lib/ruby/whatsapp/webhook/message/base.rb
Overview
Common envelope shared by every inbound message type: who sent it, its wamid, when it arrived, and (optionally) what it's replying to.
Direct Known Subclasses
Button, Contacts, Interactive, Location, Media, Order, Reaction, System, Text, Unknown
Instance Attribute Summary collapse
- #context ⇒ Context?
- #from ⇒ String?
-
#id ⇒ String?
The message's wamid.
- #referral ⇒ Referral?
- #timestamp ⇒ String?
- #type ⇒ String?
Class Method Summary collapse
-
.common_attributes(data) ⇒ Hash
Extracts the fields every message type shares, for subclasses to merge with their own type-specific payload before calling
new.
Instance Method Summary collapse
-
#initialize(from:, id:, timestamp:, type:, context: nil, referral: nil) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(from:, id:, timestamp:, type:, context: nil, referral: nil) ⇒ Base
Returns a new instance of Base.
33 34 35 36 37 38 39 40 |
# File 'lib/ruby/whatsapp/webhook/message/base.rb', line 33 def initialize(from:, id:, timestamp:, type:, context: nil, referral: nil) @from = from @id = id @timestamp = @type = type @context = context @referral = referral end |
Instance Attribute Details
#context ⇒ Context?
27 28 29 |
# File 'lib/ruby/whatsapp/webhook/message/base.rb', line 27 def context @context end |
#from ⇒ String?
11 12 13 |
# File 'lib/ruby/whatsapp/webhook/message/base.rb', line 11 def from @from end |
#id ⇒ String?
Returns The message's wamid.
15 16 17 |
# File 'lib/ruby/whatsapp/webhook/message/base.rb', line 15 def id @id end |
#referral ⇒ Referral?
31 32 33 |
# File 'lib/ruby/whatsapp/webhook/message/base.rb', line 31 def referral @referral end |
#timestamp ⇒ String?
19 20 21 |
# File 'lib/ruby/whatsapp/webhook/message/base.rb', line 19 def @timestamp end |
#type ⇒ String?
23 24 25 |
# File 'lib/ruby/whatsapp/webhook/message/base.rb', line 23 def type @type end |
Class Method Details
.common_attributes(data) ⇒ Hash
Extracts the fields every message type shares, for subclasses to
merge with their own type-specific payload before calling new.
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ruby/whatsapp/webhook/message/base.rb', line 47 def common_attributes(data) { from: data["from"], id: data["id"], timestamp: data["timestamp"], type: data["type"], context: Context.deserialize(data["context"]), referral: Referral.deserialize(data["referral"]), } end |