Class: Whatsapp::Webhook::Message
- Inherits:
-
Object
- Object
- Whatsapp::Webhook::Message
- Defined in:
- lib/ruby/whatsapp/webhook/message.rb,
lib/ruby/whatsapp/webhook/message/base.rb,
lib/ruby/whatsapp/webhook/message/text.rb,
lib/ruby/whatsapp/webhook/message/audio.rb,
lib/ruby/whatsapp/webhook/message/image.rb,
lib/ruby/whatsapp/webhook/message/media.rb,
lib/ruby/whatsapp/webhook/message/order.rb,
lib/ruby/whatsapp/webhook/message/video.rb,
lib/ruby/whatsapp/webhook/message/button.rb,
lib/ruby/whatsapp/webhook/message/system.rb,
lib/ruby/whatsapp/webhook/message/context.rb,
lib/ruby/whatsapp/webhook/message/sticker.rb,
lib/ruby/whatsapp/webhook/message/unknown.rb,
lib/ruby/whatsapp/webhook/message/contacts.rb,
lib/ruby/whatsapp/webhook/message/document.rb,
lib/ruby/whatsapp/webhook/message/location.rb,
lib/ruby/whatsapp/webhook/message/reaction.rb,
lib/ruby/whatsapp/webhook/message/referral.rb,
lib/ruby/whatsapp/webhook/message/interactive.rb,
lib/ruby/whatsapp/webhook/message/contacts/org.rb,
lib/ruby/whatsapp/webhook/message/contacts/url.rb,
lib/ruby/whatsapp/webhook/message/contacts/name.rb,
lib/ruby/whatsapp/webhook/message/contacts/email.rb,
lib/ruby/whatsapp/webhook/message/contacts/phone.rb,
lib/ruby/whatsapp/webhook/message/contacts/address.rb,
lib/ruby/whatsapp/webhook/message/contacts/contact.rb,
lib/ruby/whatsapp/webhook/message/order/product_item.rb
Overview
Dispatches a single messages[] entry from the messages webhook field to
the class matching its type. Mirrors Whatsapp::Messages::KINDS — resolution
goes through this frozen whitelist (never const_get on the type string,
which comes straight from the internet), so an unrecognized type falls back to
Unknown rather than raising.
Defined Under Namespace
Classes: Audio, Base, Button, Contacts, Context, Document, Image, Interactive, Location, Media, Order, Reaction, Referral, Sticker, System, Text, Unknown, Video
Constant Summary collapse
- MESSAGE_TYPES =
{ text: Text, image: Image, video: Video, audio: Audio, document: Document, sticker: Sticker, location: Location, contacts: Contacts, interactive: Interactive, button: Button, order: Order, system: System, reaction: Reaction, }.freeze
Class Method Summary collapse
-
.deserialize(data) ⇒ Message::Base
One of the classes in MESSAGE_TYPES, or Unknown.
Class Method Details
.deserialize(data) ⇒ Message::Base
Returns One of the classes in MESSAGE_TYPES, or Unknown.
30 31 32 33 34 35 |
# File 'lib/ruby/whatsapp/webhook/message.rb', line 30 def deserialize(data) data ||= {} klass = MESSAGE_TYPES.fetch(data["type"].to_s.to_sym) { Unknown } klass.deserialize(data) end |