whatsapp_sdk 0.9.1 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -1
  3. data/Gemfile +0 -6
  4. data/Gemfile.lock +16 -16
  5. data/README.md +32 -9
  6. data/example.rb +67 -1
  7. data/lib/whatsapp_sdk/api/business_profile.rb +8 -8
  8. data/lib/whatsapp_sdk/api/medias.rb +18 -18
  9. data/lib/whatsapp_sdk/api/messages.rb +67 -71
  10. data/lib/whatsapp_sdk/api/phone_numbers.rb +16 -16
  11. data/lib/whatsapp_sdk/api/response.rb +4 -4
  12. data/lib/whatsapp_sdk/api/responses/generic_error_response.rb +49 -0
  13. data/lib/whatsapp_sdk/api/responses/message_data_response.rb +8 -8
  14. data/lib/whatsapp_sdk/api/responses/message_error_response.rb +2 -38
  15. data/lib/whatsapp_sdk/api/responses/message_template_namespace_data_response.rb +37 -0
  16. data/lib/whatsapp_sdk/api/responses/template_data_response.rb +51 -0
  17. data/lib/whatsapp_sdk/api/responses/templates_data_response.rb +39 -0
  18. data/lib/whatsapp_sdk/api/templates.rb +201 -0
  19. data/lib/whatsapp_sdk/configuration.rb +2 -2
  20. data/lib/whatsapp_sdk/resource/component.rb +2 -2
  21. data/lib/whatsapp_sdk/resource/errors.rb +68 -0
  22. data/lib/whatsapp_sdk/resource/interactive_action.rb +5 -5
  23. data/lib/whatsapp_sdk/resource/interactive_action_reply_button.rb +2 -2
  24. data/lib/whatsapp_sdk/resource/interactive_action_section.rb +2 -2
  25. data/lib/whatsapp_sdk/resource/interactive_action_section_row.rb +5 -5
  26. data/lib/whatsapp_sdk/resource/interactive_body.rb +1 -1
  27. data/lib/whatsapp_sdk/resource/interactive_footer.rb +1 -1
  28. data/lib/whatsapp_sdk/resource/interactive_header.rb +1 -1
  29. data/lib/whatsapp_sdk/resource/languages.rb +86 -0
  30. data/lib/whatsapp_sdk/resource/media_types.rb +2 -1
  31. data/lib/whatsapp_sdk/resource/parameter_object.rb +2 -2
  32. data/lib/whatsapp_sdk/resource/template.rb +64 -0
  33. data/lib/whatsapp_sdk/version.rb +1 -1
  34. data/whatsapp_sdk.gemspec +8 -8
  35. metadata +22 -15
  36. data/lib/whatsapp_sdk/resource/error.rb +0 -39
@@ -0,0 +1,37 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "data_response"
5
+ require_relative "../../resource/template"
6
+
7
+ module WhatsappSdk
8
+ module Api
9
+ module Responses
10
+ class MessageTemplateNamespaceDataResponse < DataResponse
11
+ sig { returns(String) }
12
+ attr_accessor :message_template_namespace
13
+
14
+ sig { returns(String) }
15
+ attr_accessor :id
16
+
17
+ sig { params(response: T::Hash[T.untyped, T.untyped]).void }
18
+ def initialize(response)
19
+ @id = T.let(response["id"], String)
20
+ @message_template_namespace = T.let(response["message_template_namespace"], String)
21
+
22
+ super(response)
23
+ end
24
+
25
+ sig do
26
+ override.params(response: T::Hash[T.untyped, T.untyped])
27
+ .returns(T.nilable(MessageTemplateNamespaceDataResponse))
28
+ end
29
+ def self.build_from_response(response:)
30
+ return unless response["id"]
31
+
32
+ new(response)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,51 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "data_response"
5
+ require_relative "../../resource/template"
6
+
7
+ module WhatsappSdk
8
+ module Api
9
+ module Responses
10
+ class TemplateDataResponse < DataResponse
11
+ sig { returns(::WhatsappSdk::Resource::Template) }
12
+ attr_reader :template
13
+
14
+ sig { params(response: T::Hash[T.untyped, T.untyped]).void }
15
+ def initialize(response:)
16
+ @template = parse_template(response)
17
+
18
+ super(response)
19
+ end
20
+
21
+ sig { override.params(response: T::Hash[T.untyped, T.untyped]).returns(T.nilable(TemplateDataResponse)) }
22
+ def self.build_from_response(response:)
23
+ return unless response["id"]
24
+
25
+ new(response: response)
26
+ end
27
+
28
+ private
29
+
30
+ sig { params(template_json: T::Hash[T.untyped, T.untyped]).returns(::WhatsappSdk::Resource::Template) }
31
+ def parse_template(template_json)
32
+ status = ::WhatsappSdk::Resource::Template::Status.try_deserialize(template_json["status"])
33
+ category = ::WhatsappSdk::Resource::Template::Category.try_deserialize(template_json["category"])
34
+ id = template_json["id"]
35
+ language = template_json["language"]
36
+ name = template_json["name"]
37
+ components_json = template_json["components"]
38
+
39
+ ::WhatsappSdk::Resource::Template.new(
40
+ id: id,
41
+ status: status,
42
+ category: category,
43
+ language: language,
44
+ name: name,
45
+ components_json: components_json
46
+ )
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,39 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "data_response"
5
+ require_relative "template_data_response"
6
+
7
+ module WhatsappSdk
8
+ module Api
9
+ module Responses
10
+ class TemplatesDataResponse < DataResponse
11
+ sig { returns(T::Array[TemplateDataResponse]) }
12
+ attr_reader :templates
13
+
14
+ sig { params(response: T::Hash[T.untyped, T.untyped]).void }
15
+ def initialize(response)
16
+ @templates = T.let(
17
+ response['data']&.map { |template| parse_templates(template) },
18
+ T::Array[TemplateDataResponse]
19
+ )
20
+ super(response)
21
+ end
22
+
23
+ sig { override.params(response: T::Hash[T.untyped, T.untyped]).returns(T.nilable(TemplatesDataResponse)) }
24
+ def self.build_from_response(response:)
25
+ return unless response["data"]
26
+
27
+ new(response)
28
+ end
29
+
30
+ private
31
+
32
+ sig { params(template: T::Hash[T.untyped, T.untyped]).returns(TemplateDataResponse) }
33
+ def parse_templates(template)
34
+ TemplateDataResponse.new(response: template)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,201 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "request"
5
+ require_relative "response"
6
+ require_relative 'responses/success_response'
7
+ require_relative 'responses/message_template_namespace_data_response'
8
+ require_relative 'responses/generic_error_response'
9
+ require_relative 'responses/template_data_response'
10
+ require_relative 'responses/templates_data_response'
11
+ require_relative "../resource/languages"
12
+
13
+ module WhatsappSdk
14
+ module Api
15
+ class Templates < Request
16
+ DEFAULT_HEADERS = T.let({ 'Content-Type' => 'application/json' }.freeze, Hash)
17
+
18
+ class InvalidCategoryError < StandardError
19
+ extend T::Sig
20
+
21
+ sig { returns(String) }
22
+ attr_reader :category
23
+
24
+ sig { params(category: String).void }
25
+ def initialize(category:)
26
+ @category = category
27
+
28
+ super("Invalid Category. The possible values are: AUTHENTICATION, MARKETING and UTILITY.")
29
+ end
30
+ end
31
+
32
+ # Create a template
33
+ #
34
+ # @param business_id [Integer] Business Id.
35
+ # @param name [String] the template's name.
36
+ # @param category [String] the template's category. Possible values: AUTHENTICATION, MARKETING, UTILITY.
37
+ # @param language [String] Template language and locale code (e.g. en_US).
38
+ # See the list of possible languages https://developers.facebook.com/docs/whatsapp/api/messages/message-templates
39
+ # @param components_json [Component] Components that make up the template. See the list of possible components:
40
+ # https://developers.facebook.com/docs/whatsapp/business-management-api/message-templates/components
41
+ # @param allow_category_change [Boolean] Optional Allow category change.
42
+ # Set to true to allow us to assign a category based on the template guidelines and the template's contents.
43
+ # This can prevent your template from being rejected for miscategorization.
44
+ # @return [WhatsappSdk::Api::Response] Response object.
45
+ sig do
46
+ params(
47
+ business_id: Integer,
48
+ name: String,
49
+ category: String,
50
+ language: String,
51
+ components_json: T.nilable(T::Array[T::Hash[T.untyped, T.untyped]]),
52
+ allow_category_change: T.nilable(T::Boolean)
53
+ ).returns(WhatsappSdk::Api::Response)
54
+ end
55
+ def create(
56
+ business_id:, name:, category:, language:, components_json: nil, allow_category_change: nil
57
+ )
58
+ unless WhatsappSdk::Resource::Template::Category.try_deserialize(category)
59
+ raise InvalidCategoryError.new(category: category)
60
+ end
61
+
62
+ unless WhatsappSdk::Resource::Languages.available?(language)
63
+ raise WhatsappSdk::Resource::Errors::InvalidLanguageError.new(language: language)
64
+ end
65
+
66
+ params = {
67
+ name: name,
68
+ category: category,
69
+ language: language,
70
+ components: components_json
71
+ }
72
+ params["allow_category_change"] = allow_category_change if allow_category_change
73
+
74
+ response = send_request(
75
+ endpoint: "#{business_id}/message_templates",
76
+ http_method: "post",
77
+ params: params,
78
+ headers: DEFAULT_HEADERS
79
+ )
80
+
81
+ WhatsappSdk::Api::Response.new(
82
+ response: response,
83
+ data_class_type: WhatsappSdk::Api::Responses::TemplateDataResponse,
84
+ error_class_type: WhatsappSdk::Api::Responses::GenericErrorResponse
85
+ )
86
+ end
87
+
88
+ # Get templates
89
+ #
90
+ # @param business_id [Integer] The business ID.
91
+ # @param limit [Integer] Optional. Number of templates to return in a single page.
92
+ # @return [WhatsappSdk::Api::Response] Response object.
93
+ sig { params(business_id: Integer, limit: T.nilable(Integer)).returns(WhatsappSdk::Api::Response) }
94
+ def templates(business_id:, limit: 100)
95
+ params = {}
96
+ params["limit"] = limit if limit
97
+
98
+ response = send_request(
99
+ endpoint: "#{business_id}/message_templates",
100
+ http_method: "get",
101
+ params: params
102
+ )
103
+
104
+ WhatsappSdk::Api::Response.new(
105
+ response: response,
106
+ data_class_type: WhatsappSdk::Api::Responses::TemplatesDataResponse,
107
+ error_class_type: WhatsappSdk::Api::Responses::GenericErrorResponse
108
+ )
109
+ end
110
+
111
+ # Get Message Template Namespace
112
+ # The message template namespace is required to send messages using the message templates.
113
+ #
114
+ # @param business_id [Integer] The business ID.
115
+ # @return [WhatsappSdk::Api::Response] Response object.
116
+ sig { params(business_id: Integer).returns(WhatsappSdk::Api::Response) }
117
+ def get_message_template_namespace(business_id:)
118
+ response = send_request(
119
+ endpoint: business_id.to_s,
120
+ http_method: "get",
121
+ params: { "fields" => "message_template_namespace" }
122
+ )
123
+
124
+ WhatsappSdk::Api::Response.new(
125
+ response: response,
126
+ data_class_type: WhatsappSdk::Api::Responses::MessageTemplateNamespaceDataResponse,
127
+ error_class_type: WhatsappSdk::Api::Responses::GenericErrorResponse
128
+ )
129
+ end
130
+
131
+ # Edit Template
132
+ #
133
+ # Editing a template replaces its old contents entirely, so include any components you wish
134
+ # to preserve as well as components you wish to update using the components parameter.
135
+ #
136
+ # Message templates can only be edited when in an Approved, Rejected, or Paused state.
137
+ #
138
+ # @param id [String] Required. The message_template-id.
139
+ # @param components_json [Json] Components that make up the template..
140
+ # return [WhatsappSdk::Api::Response] Response object.
141
+ def update(template_id:, category: nil, components_json: nil)
142
+ if category && !WhatsappSdk::Resource::Template::Category.try_deserialize(category)
143
+ raise InvalidCategoryError.new(category: category)
144
+ end
145
+
146
+ params = {}
147
+ params[:components] = components_json if components_json
148
+ params[:category] = category if category
149
+
150
+ response = send_request(
151
+ endpoint: template_id.to_s,
152
+ http_method: "post",
153
+ params: params,
154
+ headers: { "Content-Type" => "application/json" }
155
+ )
156
+
157
+ WhatsappSdk::Api::Response.new(
158
+ response: response,
159
+ data_class_type: WhatsappSdk::Api::Responses::SuccessResponse,
160
+ error_class_type: WhatsappSdk::Api::Responses::GenericErrorResponse
161
+ )
162
+ end
163
+
164
+ # Delete Template
165
+ #
166
+ # Deleting a template by name deletes all templates that match that name
167
+ # (meaning templates with the same name but different languages will also be deleted).
168
+ # To delete a template by ID, include the template's ID along with its name in your request;
169
+ # only the template with the matching template ID will be deleted.
170
+ #
171
+ # @param business_id [Integer] Required. The business ID.
172
+ # @param name [String] Required. The template's name.
173
+ # @param hsm_id [String] Optional. The template's id.
174
+ #
175
+ # @return [WhatsappSdk::Api::Response] Response object.
176
+ sig do
177
+ params(
178
+ business_id: Integer,
179
+ name: String,
180
+ hsm_id: T.nilable(String)
181
+ ).returns(WhatsappSdk::Api::Response)
182
+ end
183
+ def delete(business_id:, name:, hsm_id: nil)
184
+ params = { name: name }
185
+ params[:hsm_id] = hsm_id if hsm_id
186
+
187
+ response = send_request(
188
+ endpoint: "#{business_id}/message_templates",
189
+ http_method: "delete",
190
+ params: params
191
+ )
192
+
193
+ WhatsappSdk::Api::Response.new(
194
+ response: response,
195
+ data_class_type: WhatsappSdk::Api::Responses::SuccessResponse,
196
+ error_class_type: WhatsappSdk::Api::Responses::GenericErrorResponse
197
+ )
198
+ end
199
+ end
200
+ end
201
+ end
@@ -19,9 +19,9 @@ module WhatsappSdk
19
19
  @access_token = access_token
20
20
  end
21
21
 
22
- sig { returns(WhatsappSdk::Api::Client) }
22
+ sig { returns(Api::Client) }
23
23
  def client
24
- WhatsappSdk::Api::Client.new(access_token)
24
+ Api::Client.new(access_token)
25
25
  end
26
26
  end
27
27
  end
@@ -62,7 +62,7 @@ module WhatsappSdk
62
62
  # appending the text parameter to the predefined prefix URL in the template.
63
63
  #
64
64
  # @returns subtype [String]. Valid options are quick_reply and url.
65
- sig { returns(T.nilable(WhatsappSdk::Resource::Component::Subtype)) }
65
+ sig { returns(T.nilable(Component::Subtype)) }
66
66
  attr_accessor :sub_type
67
67
 
68
68
  # Required when type=button. Not used for the other types.
@@ -80,7 +80,7 @@ module WhatsappSdk
80
80
  sig do
81
81
  params(
82
82
  type: Type, parameters: T::Array[T.any(ButtonParameter, ParameterObject)],
83
- sub_type: T.nilable(WhatsappSdk::Resource::Component::Subtype), index: T.nilable(Integer)
83
+ sub_type: T.nilable(Component::Subtype), index: T.nilable(Integer)
84
84
  ).void
85
85
  end
86
86
  def initialize(type:, parameters: [], sub_type: nil, index: nil)
@@ -0,0 +1,68 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module WhatsappSdk
5
+ module Resource
6
+ module Errors
7
+ class MissingArgumentError < StandardError
8
+ extend T::Sig
9
+
10
+ sig { returns(String) }
11
+ attr_reader :message
12
+
13
+ sig { params(message: String).void }
14
+ def initialize(message)
15
+ @message = message
16
+ super(message)
17
+ end
18
+ end
19
+
20
+ class MissingValue < Error
21
+ extend T::Sig
22
+
23
+ sig { returns(String) }
24
+ attr_reader :field
25
+
26
+ sig { returns(String) }
27
+ attr_reader :message
28
+
29
+ sig { params(field: String, message: String).void }
30
+ def initialize(field, message)
31
+ @field = field
32
+ @message = message
33
+ super(message)
34
+ end
35
+ end
36
+
37
+ class InvalidLanguageError < StandardError
38
+ extend T::Sig
39
+
40
+ URL_AVAILABLE_LANGUAGES = "https://developers.facebook.com/docs/whatsapp/api/messages/message-templates"
41
+
42
+ sig { returns(String) }
43
+ attr_reader :language
44
+
45
+ sig { params(language: String).void }
46
+ def initialize(language:)
47
+ @language = language
48
+
49
+ super("Invalid language. Check the available languages in #{URL_AVAILABLE_LANGUAGES}.")
50
+ end
51
+ end
52
+
53
+ class InvalidField < MissingValue; end
54
+
55
+ class InvalidInteractiveBody < Error; end
56
+
57
+ class InvalidInteractiveActionReplyButton < Error; end
58
+
59
+ class InvalidInteractiveActionButton < Error; end
60
+
61
+ class InvalidInteractiveActionSection < Error; end
62
+
63
+ class InvalidInteractiveActionSectionRow < Error; end
64
+
65
+ class InvalidInteractiveFooter < Error; end
66
+ end
67
+ end
68
+ end
@@ -103,18 +103,18 @@ module WhatsappSdk
103
103
  button_length = button.length
104
104
  sections_count = sections.length
105
105
  unless button_length.positive?
106
- raise WhatsappSdk::Resource::Error::InvalidInteractiveActionButton,
106
+ raise Errors::InvalidInteractiveActionButton,
107
107
  "Invalid button in action. Button label is required."
108
108
  end
109
109
 
110
110
  unless button_length <= LIST_BUTTON_TITLE_MAXIMUM
111
- raise WhatsappSdk::Resource::Error::InvalidInteractiveActionButton,
111
+ raise Errors::InvalidInteractiveActionButton,
112
112
  "Invalid length #{button_length} for button. Maximum length: " \
113
113
  "#{LIST_BUTTON_TITLE_MAXIMUM} characters."
114
114
  end
115
115
 
116
116
  unless (LIST_SECTIONS_MINIMUM..LIST_SECTIONS_MAXIMUM).cover?(sections_count)
117
- raise WhatsappSdk::Resource::Error::InvalidInteractiveActionSection,
117
+ raise Errors::InvalidInteractiveActionSection,
118
118
  "Invalid length #{sections_count} for sections in action. It should be between " \
119
119
  "#{LIST_SECTIONS_MINIMUM} and #{LIST_SECTIONS_MAXIMUM}."
120
120
  end
@@ -125,7 +125,7 @@ module WhatsappSdk
125
125
  def validate_reply_button
126
126
  buttons_count = buttons.length
127
127
  unless (REPLY_BUTTONS_MINIMUM..REPLY_BUTTONS_MAXIMUM).cover?(buttons_count)
128
- raise WhatsappSdk::Resource::Error::InvalidInteractiveActionReplyButton,
128
+ raise Errors::InvalidInteractiveActionReplyButton,
129
129
  "Invalid length #{buttons_count} for buttons in action. It should be between " \
130
130
  "#{REPLY_BUTTONS_MINIMUM} and #{REPLY_BUTTONS_MAXIMUM}."
131
131
  end
@@ -133,7 +133,7 @@ module WhatsappSdk
133
133
  button_ids = buttons.map(&:id)
134
134
  return if button_ids.length.eql?(button_ids.uniq.length)
135
135
 
136
- raise WhatsappSdk::Resource::Error::InvalidInteractiveActionReplyButton,
136
+ raise Errors::InvalidInteractiveActionReplyButton,
137
137
  "Duplicate ids #{button_ids} for buttons in action. They should be unique."
138
138
  end
139
139
  end
@@ -67,7 +67,7 @@ module WhatsappSdk
67
67
  title_length = title.length
68
68
  return if title_length <= ACTION_BUTTON_TITLE_MAXIMUM
69
69
 
70
- raise WhatsappSdk::Resource::Error::InvalidInteractiveActionReplyButton,
70
+ raise Errors::InvalidInteractiveActionReplyButton,
71
71
  "Invalid length #{title_length} for title in button. " \
72
72
  "Maximum length: #{ACTION_BUTTON_TITLE_MAXIMUM} characters."
73
73
  end
@@ -80,7 +80,7 @@ module WhatsappSdk
80
80
  id_length = id.length
81
81
  return if id_length <= ACTION_BUTTON_ID_MAXIMUM
82
82
 
83
- raise WhatsappSdk::Resource::Error::InvalidInteractiveActionReplyButton,
83
+ raise Errors::InvalidInteractiveActionReplyButton,
84
84
  "Invalid length #{id_length} for id in button. Maximum length: #{ACTION_BUTTON_ID_MAXIMUM} characters."
85
85
  end
86
86
  end
@@ -53,7 +53,7 @@ module WhatsappSdk
53
53
  title_length = title.length
54
54
  return if title_length <= ACTION_SECTION_TITLE_MAXIMUM
55
55
 
56
- raise WhatsappSdk::Resource::Error::InvalidInteractiveActionSection,
56
+ raise Errors::InvalidInteractiveActionSection,
57
57
  "Invalid length #{title_length} for title in section. Maximum length: " \
58
58
  "#{ACTION_SECTION_TITLE_MAXIMUM} characters."
59
59
  end
@@ -63,7 +63,7 @@ module WhatsappSdk
63
63
  rows_length = rows.length
64
64
  return if rows_length <= ACTION_SECTION_ROWS_MAXIMUM
65
65
 
66
- raise WhatsappSdk::Resource::Error::InvalidInteractiveActionSection,
66
+ raise Errors::InvalidInteractiveActionSection,
67
67
  "Invalid number of rows #{rows_length} in section. Maximum count: " \
68
68
  "#{ACTION_SECTION_ROWS_MAXIMUM}."
69
69
  end
@@ -61,8 +61,8 @@ module WhatsappSdk
61
61
  title_length = title.length
62
62
  return if title_length <= ACTION_SECTION_TITLE_MAXIMUM
63
63
 
64
- raise WhatsappSdk::Resource::Error::InvalidInteractiveActionSectionRow,
65
- "Invalid length #{title_length} for title in section row. "\
64
+ raise Errors::InvalidInteractiveActionSectionRow,
65
+ "Invalid length #{title_length} for title in section row. " \
66
66
  "Maximum length: #{ACTION_SECTION_TITLE_MAXIMUM} characters."
67
67
  end
68
68
 
@@ -74,8 +74,8 @@ module WhatsappSdk
74
74
  id_length = id.length
75
75
  return if id_length <= ACTION_SECTION_ID_MAXIMUM
76
76
 
77
- raise WhatsappSdk::Resource::Error::InvalidInteractiveActionSectionRow,
78
- "Invalid length #{id_length} for id in section row. Maximum length: "\
77
+ raise Errors::InvalidInteractiveActionSectionRow,
78
+ "Invalid length #{id_length} for id in section row. Maximum length: " \
79
79
  "#{ACTION_SECTION_ID_MAXIMUM} characters."
80
80
  end
81
81
 
@@ -84,7 +84,7 @@ module WhatsappSdk
84
84
  description_length = description.length
85
85
  return if description_length <= ACTION_SECTION_DESCRIPTION_MAXIMUM
86
86
 
87
- raise WhatsappSdk::Resource::Error::InvalidInteractiveActionSectionRow,
87
+ raise Errors::InvalidInteractiveActionSectionRow,
88
88
  "Invalid length #{description_length} for description in section " \
89
89
  "row. Maximum length: #{ACTION_SECTION_DESCRIPTION_MAXIMUM} characters."
90
90
  end
@@ -40,7 +40,7 @@ module WhatsappSdk
40
40
  text_length = text.length
41
41
  return if text_length <= MAXIMUM_LENGTH
42
42
 
43
- raise WhatsappSdk::Resource::Error::InvalidInteractiveBody,
43
+ raise Errors::InvalidInteractiveBody,
44
44
  "Invalid length #{text_length} for text in body. Maximum length: #{MAXIMUM_LENGTH} characters."
45
45
  end
46
46
  end
@@ -40,7 +40,7 @@ module WhatsappSdk
40
40
  text_length = text.length
41
41
  return if text_length <= MAXIMUM_LENGTH
42
42
 
43
- raise WhatsappSdk::Resource::Error::InvalidInteractiveFooter,
43
+ raise Errors::InvalidInteractiveFooter,
44
44
  "Invalid length #{text_length} for text in footer. Maximum length: #{MAXIMUM_LENGTH} characters."
45
45
  end
46
46
  end
@@ -109,7 +109,7 @@ module WhatsappSdk
109
109
 
110
110
  next unless value.nil?
111
111
 
112
- raise WhatsappSdk::Resource::Error::MissingValue.new(
112
+ raise Resource::Errors::MissingValue.new(
113
113
  type.serialize,
114
114
  "#{type.serialize} is required when the type is #{type_b}"
115
115
  )
@@ -0,0 +1,86 @@
1
+ # typed: false
2
+ # frozen_string_literal: true
3
+
4
+ module WhatsappSdk
5
+ module Resource
6
+ class Languages
7
+ AVAILABLE_LANGUAGES = Set.new([
8
+ "af", # Afrikaans
9
+ "sq", # Albanian
10
+ "ar", # Arabic
11
+ "az", # Azerbaijani
12
+ "bn", # Bengali
13
+ "bg", # Bulgarian
14
+ "ca", # Catalan
15
+ "zh_CN", # Chinese (CHN)
16
+ "zh_HK", # Chinese (HKG)
17
+ "zh_TW", # Chinese (TAI)
18
+ "hr", # Croatian
19
+ "cs", # Czech
20
+ "da", # Danish
21
+ "nl", # Dutch
22
+ "en", # English
23
+ "en_GB", # English (UK)
24
+ "en_US", # English (US)
25
+ "et", # Estonian
26
+ "fil", # Filipino
27
+ "fi", # Finnish
28
+ "fr", # French
29
+ "ka", # Georgian
30
+ "de", # German
31
+ "el", # Greek
32
+ "gu", # Gujarati
33
+ "ha", # Hausa
34
+ "he", # Hebrew
35
+ "hi", # Hindi
36
+ "hu", # Hungarian
37
+ "id", # Indonesian
38
+ "ga", # Irish
39
+ "it", # Italian
40
+ "ja", # Japanese
41
+ "kn", # Kannada
42
+ "kk", # Kazakh
43
+ "rw_RW", # Kinyarwanda
44
+ "ko", # Korean
45
+ "ky_KG", # Kyrgyz (Kyrgyzstan)
46
+ "lo", # Lao
47
+ "lv", # Latvian
48
+ "lt", # Lithuanian
49
+ "mk", # Macedonian
50
+ "ms", # Malay
51
+ "ml", # Malayalam
52
+ "mr", # Marathi
53
+ "nb", # Norwegian
54
+ "fa", # Persian
55
+ "pl", # Polish
56
+ "pt_BR", # Portuguese (BR)
57
+ "pt_PT", # Portuguese (POR)
58
+ "pa", # Punjabi
59
+ "ro", # Romanian
60
+ "ru", # Russian
61
+ "sr", # Serbian
62
+ "sk", # Slovak
63
+ "sl", # Slovenian
64
+ "es", # Spanish
65
+ "es_AR", # Spanish (ARG)
66
+ "es_ES", # Spanish (SPA)
67
+ "es_MX", # Spanish (MEX)
68
+ "sw", # Swahili
69
+ "sv", # Swedish
70
+ "ta", # Tamil
71
+ "te", # Telugu
72
+ "th", # Thai
73
+ "tr", # Turkish
74
+ "uk", # Ukrainian
75
+ "ur", # Urdu
76
+ "uz", # Uzbek
77
+ "vi", # Vietnamese
78
+ "zu" # Zulu
79
+ ])
80
+
81
+ def self.available?(language)
82
+ AVAILABLE_LANGUAGES.include?(language)
83
+ end
84
+ end
85
+ end
86
+ end
@@ -22,9 +22,10 @@ module WhatsappSdk
22
22
  application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
23
23
  ].freeze
24
24
  IMAGE_TYPES = %w[image/jpeg image/png].freeze
25
+ STICKER_TYPES = %w[image/webp].freeze
25
26
  VIDEO_TYPES = %w[video/mp4 video/3gp].freeze
26
27
 
27
- SUPPORTED_MEDIA_TYPES = [AUDIO_TYPES + DOCUMENT_TYPES + IMAGE_TYPES + VIDEO_TYPES].flatten.freeze
28
+ SUPPORTED_MEDIA_TYPES = [AUDIO_TYPES + DOCUMENT_TYPES + IMAGE_TYPES + STICKER_TYPES + VIDEO_TYPES].flatten.freeze
28
29
  end
29
30
  end
30
31
  end