Class: Whatsapp::Webhook::Change

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/whatsapp/webhook/change.rb

Overview

A single entry[].changes[] item: field names which of Meta's ~19 documented webhook notification types this is, value is the deserialized payload for it.

FIELDS is populated incrementally as each field's value class is implemented (see Whatsapp::Webhook::CLAUDE.md) — never const_get on the field name, which comes straight from the internet; a field not yet in the registry falls back to UnknownField rather than raising.

Constant Summary collapse

FIELDS =
{
  messages: Messages,
  account_alerts: AccountAlerts,
  account_review_update: AccountReviewUpdate,
  account_update: AccountUpdate,
  automatic_events: AutomaticEvents,
  business_capability_update: BusinessCapabilityUpdate,
  history: History,
  message_template_components_update: MessageTemplateComponentsUpdate,
  message_template_quality_update: MessageTemplateQualityUpdate,
  message_template_status_update: MessageTemplateStatusUpdate,
  partner_solutions: PartnerSolutions,
  payment_configuration_update: PaymentConfigurationUpdate,
  phone_number_name_update: PhoneNumberNameUpdate,
  phone_number_quality_update: PhoneNumberQualityUpdate,
  security: Security,
  smb_app_state_sync: SmbAppStateSync,
  smb_message_echoes: SmbMessageEchoes,
  template_category_update: TemplateCategoryUpdate,
  user_preferences: UserPreferences,
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field:, value:) ⇒ Change

Returns a new instance of Change.



43
44
45
46
# File 'lib/ruby/whatsapp/webhook/change.rb', line 43

def initialize(field:, value:)
  @field = field
  @value = value
end

Instance Attribute Details

#fieldString

Returns:

  • (String)


37
38
39
# File 'lib/ruby/whatsapp/webhook/change.rb', line 37

def field
  @field
end

#valueObject

Returns One of the classes registered in FIELDS, or UnknownField.

Returns:



41
42
43
# File 'lib/ruby/whatsapp/webhook/change.rb', line 41

def value
  @value
end

Class Method Details

.deserialize(data) ⇒ Change

Parameters:

  • data (Hash)

    A raw changes[] entry.

Returns:



51
52
53
54
55
56
57
# File 'lib/ruby/whatsapp/webhook/change.rb', line 51

def deserialize(data)
  data ||= {}
  field = data["field"]
  klass = FIELDS.fetch(field.to_s.to_sym) { UnknownField }

  new(field:, value: klass.deserialize(data["value"]))
end