Module: Whatsapp::MessageTemplates::Categories

Defined in:
lib/ruby/whatsapp/message_templates/categories.rb

Overview

The three categories every template must declare.

The choice is not cosmetic: it drives pricing, it decides which components are legal, and Meta validates it against the template's actual content — a mismatch comes back as REJECTED with the reason INCORRECT_CATEGORY.

Shared by Template, ComponentSet and LibraryTemplate, hence its own file rather than living on any one of them. Source: https://developers.facebook.com/documentation/business-messaging/whatsapp/templates/template-categorization

Constant Summary collapse

AUTHENTICATION =

Identity verification with one-time passcodes. No URLs, media, or emojis, and parameters are capped at 15 characters.

"AUTHENTICATION"
MARKETING =

Promotions, awareness, retargeting. Anything ambiguous lands here.

"MARKETING"
UTILITY =

Transactional and non-promotional: order, account, or transaction updates, or genuinely essential notices.

"UTILITY"
ALL =
[AUTHENTICATION, MARKETING, UTILITY].freeze

Class Method Summary collapse

Class Method Details

.normalize(value) ⇒ String?

Normalizes caller input to a canonical uppercase category.

Meta's own docs are inconsistent about enum casing, so callers may reasonably pass :marketing, "marketing", or "MARKETING". Unrecognized values are returned untouched so validations can report them.

Parameters:

  • value (String, Symbol, nil)

Returns:

  • (String, nil)


33
34
35
36
37
38
# File 'lib/ruby/whatsapp/message_templates/categories.rb', line 33

def self.normalize(value)
  return if value.nil?

  candidate = value.to_s.upcase
  ALL.include?(candidate) ? candidate : value.to_s
end

.valid?(value) ⇒ Boolean

Parameters:

  • value (String, Symbol, nil)

Returns:

  • (Boolean)


42
43
44
# File 'lib/ruby/whatsapp/message_templates/categories.rb', line 42

def self.valid?(value)
  ALL.include?(normalize(value))
end