Class: Whatsapp::MessageTemplates::Response::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/whatsapp/message_templates/response/node.rb

Overview

A full template as Meta returns it, from reading one template or from each element of a list.

components is deliberately left as raw hashes rather than rebuilt into the Component classes. Those classes validate a payload being written, whereas this is Meta's own echo of it: it carries fields the write side does not model, and running write-side rules over data we did not author would raise on perfectly valid responses. Read it as data; build a new Template when you want to change something. Source: https://developers.facebook.com/docs/graph-api/reference/whats-app-business-hsm/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: nil, name: nil, status: nil, category: nil, language: nil, components: [], parameter_format: nil, sub_category: nil, rejected_reason: nil, quality_score: nil, previous_category: nil, correct_category: nil, message_send_ttl_seconds: nil, cta_url_link_tracking_opted_out: nil, library_template_name: nil) ⇒ Node

Returns a new instance of Node.

Parameters:

  • kwargs (Hash)

    One key per documented node field.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/ruby/whatsapp/message_templates/response/node.rb', line 78

def initialize(id: nil, name: nil, status: nil, category: nil, language: nil, components: [],
  parameter_format: nil, sub_category: nil, rejected_reason: nil, quality_score: nil,
  previous_category: nil, correct_category: nil, message_send_ttl_seconds: nil,
  cta_url_link_tracking_opted_out: nil, library_template_name: nil)
  @id = id
  @name = name
  @status = status
  @category = category
  @language = language
  @components = components
  @parameter_format = parameter_format
  @sub_category = sub_category
  @rejected_reason = rejected_reason
  @quality_score = quality_score
  @previous_category = previous_category
  @correct_category = correct_category
  @message_send_ttl_seconds = message_send_ttl_seconds
  @cta_url_link_tracking_opted_out = cta_url_link_tracking_opted_out
  @library_template_name = library_template_name
end

Instance Attribute Details

#categoryString?

Returns:

  • (String, nil)


31
32
33
# File 'lib/ruby/whatsapp/message_templates/response/node.rb', line 31

def category
  @category
end

#componentsArray<Hash>

Returns Raw component hashes — see the class comment.

Returns:

  • (Array<Hash>)

    Raw component hashes — see the class comment.



39
40
41
# File 'lib/ruby/whatsapp/message_templates/response/node.rb', line 39

def components
  @components
end

#correct_categoryString?

Returns The category Meta believes this should be.

Returns:

  • (String, nil)

    The category Meta believes this should be.



63
64
65
# File 'lib/ruby/whatsapp/message_templates/response/node.rb', line 63

def correct_category
  @correct_category
end

Returns:

  • (Boolean, nil)


71
72
73
# File 'lib/ruby/whatsapp/message_templates/response/node.rb', line 71

def cta_url_link_tracking_opted_out
  @cta_url_link_tracking_opted_out
end

#idString?

Returns:

  • (String, nil)


19
20
21
# File 'lib/ruby/whatsapp/message_templates/response/node.rb', line 19

def id
  @id
end

#languageString?

Returns:

  • (String, nil)


35
36
37
# File 'lib/ruby/whatsapp/message_templates/response/node.rb', line 35

def language
  @language
end

#library_template_nameString?

Returns Set when the template was cloned from the library.

Returns:

  • (String, nil)

    Set when the template was cloned from the library.



75
76
77
# File 'lib/ruby/whatsapp/message_templates/response/node.rb', line 75

def library_template_name
  @library_template_name
end

#message_send_ttl_secondsInteger?

Returns:

  • (Integer, nil)


67
68
69
# File 'lib/ruby/whatsapp/message_templates/response/node.rb', line 67

def message_send_ttl_seconds
  @message_send_ttl_seconds
end

#nameString?

Returns:

  • (String, nil)


23
24
25
# File 'lib/ruby/whatsapp/message_templates/response/node.rb', line 23

def name
  @name
end

#parameter_formatString?

Returns:

  • (String, nil)


43
44
45
# File 'lib/ruby/whatsapp/message_templates/response/node.rb', line 43

def parameter_format
  @parameter_format
end

#previous_categoryString?

Returns Set after an automatic recategorisation.

Returns:

  • (String, nil)

    Set after an automatic recategorisation.



59
60
61
# File 'lib/ruby/whatsapp/message_templates/response/node.rb', line 59

def previous_category
  @previous_category
end

#quality_scoreQualityScore?

Returns:



55
56
57
# File 'lib/ruby/whatsapp/message_templates/response/node.rb', line 55

def quality_score
  @quality_score
end

#rejected_reasonString?

Returns:



51
52
53
# File 'lib/ruby/whatsapp/message_templates/response/node.rb', line 51

def rejected_reason
  @rejected_reason
end

#statusString?

Returns One of Statuses::ALL.

Returns:



27
28
29
# File 'lib/ruby/whatsapp/message_templates/response/node.rb', line 27

def status
  @status
end

#sub_categoryString?

Returns:

  • (String, nil)


47
48
49
# File 'lib/ruby/whatsapp/message_templates/response/node.rb', line 47

def sub_category
  @sub_category
end

Class Method Details

.deserialize(data) ⇒ Node

Parameters:

  • data (Hash, nil)

    The parsed response body, or one element of a list.

Returns:



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/ruby/whatsapp/message_templates/response/node.rb', line 102

def deserialize(data)
  data ||= {}

  new(
    id: data["id"],
    name: data["name"],
    status: data["status"],
    category: data["category"],
    language: data["language"],
    components: Array(data["components"]),
    parameter_format: data["parameter_format"],
    sub_category: data["sub_category"],
    rejected_reason: data["rejected_reason"],
    quality_score: data["quality_score"] && QualityScore.deserialize(data["quality_score"]),
    previous_category: data["previous_category"],
    correct_category: data["correct_category"],
    message_send_ttl_seconds: data["message_send_ttl_seconds"],
    cta_url_link_tracking_opted_out: data["cta_url_link_tracking_opted_out"],
    library_template_name: data["library_template_name"]
  )
end

Instance Method Details

#approved?Boolean

Returns Whether the template can currently be sent.

Returns:

  • (Boolean)

    Whether the template can currently be sent.



126
127
128
# File 'lib/ruby/whatsapp/message_templates/response/node.rb', line 126

def approved?
  status == Statuses::APPROVED
end

#editable?Boolean

Whether Whatsapp::MessageTemplates#update would be accepted for this template.

Status is the only part that can be checked locally. Approved templates are also rate limited to 10 edits per 30 days and 1 per 24 hours, which only the API can adjudicate.

Returns:

  • (Boolean)


146
147
148
# File 'lib/ruby/whatsapp/message_templates/response/node.rb', line 146

def editable?
  Statuses::EDITABLE.include?(status)
end

#paused?Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/ruby/whatsapp/message_templates/response/node.rb', line 136

def paused?
  status == Statuses::PAUSED
end

#rejected?Boolean

Returns:

  • (Boolean)


131
132
133
# File 'lib/ruby/whatsapp/message_templates/response/node.rb', line 131

def rejected?
  status == Statuses::REJECTED
end