whatsapp_sdk 0.12.1 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/codeql-analysis.yml +8 -6
- data/.gitignore +1 -0
- data/.rubocop.yml +0 -3
- data/CHANGELOG.md +9 -7
- data/Gemfile +0 -4
- data/Gemfile.lock +1 -20
- data/README.md +35 -55
- data/SECURITY.md +21 -0
- data/example.rb +23 -15
- data/lib/whatsapp_sdk/api/api_configuration.rb +2 -5
- data/lib/whatsapp_sdk/api/business_profile.rb +0 -12
- data/lib/whatsapp_sdk/api/client.rb +7 -43
- data/lib/whatsapp_sdk/api/medias.rb +8 -15
- data/lib/whatsapp_sdk/api/messages.rb +4 -81
- data/lib/whatsapp_sdk/api/phone_numbers.rb +0 -14
- data/lib/whatsapp_sdk/api/request.rb +0 -2
- data/lib/whatsapp_sdk/api/response.rb +1 -20
- data/lib/whatsapp_sdk/api/responses/business_profile_data_response.rb +11 -34
- data/lib/whatsapp_sdk/api/responses/data_response.rb +0 -9
- data/lib/whatsapp_sdk/api/responses/error_response.rb +1 -8
- data/lib/whatsapp_sdk/api/responses/generic_error_response.rb +8 -26
- data/lib/whatsapp_sdk/api/responses/media_data_response.rb +8 -26
- data/lib/whatsapp_sdk/api/responses/message_data_response.rb +4 -20
- data/lib/whatsapp_sdk/api/responses/message_error_response.rb +0 -1
- data/lib/whatsapp_sdk/api/responses/message_template_namespace_data_response.rb +3 -13
- data/lib/whatsapp_sdk/api/responses/phone_number_data_response.rb +19 -37
- data/lib/whatsapp_sdk/api/responses/phone_numbers_data_response.rb +2 -9
- data/lib/whatsapp_sdk/api/responses/read_message_data_response.rb +1 -6
- data/lib/whatsapp_sdk/api/responses/success_response.rb +1 -5
- data/lib/whatsapp_sdk/api/responses/template_data_response.rb +2 -7
- data/lib/whatsapp_sdk/api/responses/templates_data_response.rb +2 -9
- data/lib/whatsapp_sdk/api/templates.rb +3 -27
- data/lib/whatsapp_sdk/configuration.rb +2 -24
- data/lib/whatsapp_sdk/error.rb +0 -1
- data/lib/whatsapp_sdk/resource/address.rb +1 -30
- data/lib/whatsapp_sdk/resource/address_type.rb +3 -8
- data/lib/whatsapp_sdk/resource/business_profile.rb +0 -3
- data/lib/whatsapp_sdk/resource/button_parameter.rb +4 -20
- data/lib/whatsapp_sdk/resource/component.rb +12 -43
- data/lib/whatsapp_sdk/resource/contact.rb +1 -30
- data/lib/whatsapp_sdk/resource/contact_response.rb +1 -9
- data/lib/whatsapp_sdk/resource/currency.rb +0 -8
- data/lib/whatsapp_sdk/resource/date_time.rb +0 -6
- data/lib/whatsapp_sdk/resource/email.rb +1 -10
- data/lib/whatsapp_sdk/resource/errors.rb +1 -17
- data/lib/whatsapp_sdk/resource/interactive.rb +6 -27
- data/lib/whatsapp_sdk/resource/interactive_action.rb +10 -24
- data/lib/whatsapp_sdk/resource/interactive_action_reply_button.rb +5 -19
- data/lib/whatsapp_sdk/resource/interactive_action_section.rb +1 -11
- data/lib/whatsapp_sdk/resource/interactive_action_section_row.rb +0 -11
- data/lib/whatsapp_sdk/resource/interactive_body.rb +0 -10
- data/lib/whatsapp_sdk/resource/interactive_footer.rb +0 -10
- data/lib/whatsapp_sdk/resource/interactive_header.rb +25 -53
- data/lib/whatsapp_sdk/resource/location.rb +44 -0
- data/lib/whatsapp_sdk/resource/media.rb +10 -46
- data/lib/whatsapp_sdk/resource/media_types.rb +0 -3
- data/lib/whatsapp_sdk/resource/message.rb +0 -5
- data/lib/whatsapp_sdk/resource/name.rb +1 -28
- data/lib/whatsapp_sdk/resource/org.rb +1 -13
- data/lib/whatsapp_sdk/resource/parameter_object.rb +71 -74
- data/lib/whatsapp_sdk/resource/phone_number.rb +1 -13
- data/lib/whatsapp_sdk/resource/template.rb +23 -36
- data/lib/whatsapp_sdk/resource/url.rb +1 -10
- data/lib/whatsapp_sdk/version.rb +1 -2
- data/lib/whatsapp_sdk.rb +0 -4
- data/whatsapp_sdk.gemspec +0 -3
- metadata +5 -49
- data/sorbet/config +0 -6
- data/sorbet/rbi/annotations/faraday.rbi +0 -17
- data/sorbet/rbi/annotations/mocha.rbi +0 -34
- data/sorbet/rbi/annotations/rainbow.rbi +0 -269
- data/sorbet/rbi/gems/faraday-multipart@1.0.4.rbi +0 -270
- data/sorbet/rbi/gems/faraday-net_http@2.0.3.rbi +0 -182
- data/sorbet/rbi/gems/faraday@2.3.0.rbi +0 -2494
- data/sorbet/rbi/gems/method_source@1.0.0.rbi +0 -272
- data/sorbet/rbi/gems/minitest@5.16.1.rbi +0 -1459
- data/sorbet/rbi/gems/mocha@1.14.0.rbi +0 -60
- data/sorbet/rbi/gems/multipart-post@2.2.3.rbi +0 -239
- data/sorbet/rbi/gems/netrc@0.11.0.rbi +0 -150
- data/sorbet/rbi/gems/oj@3.13.14.rbi +0 -589
- data/sorbet/rbi/gems/zeitwerk@2.6.0.rbi +0 -867
- data/sorbet/rbi/todo.rbi +0 -8
- data/sorbet/shims/request.rbi +0 -10
- data/sorbet/tapioca/config.yml +0 -13
- data/sorbet/tapioca/require.rb +0 -4
@@ -1,18 +1,10 @@
|
|
1
|
-
# typed: strict
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module WhatsappSdk
|
5
4
|
module Resource
|
6
5
|
class ContactResponse
|
7
|
-
|
6
|
+
attr_accessor :wa_id, :input
|
8
7
|
|
9
|
-
sig { returns(String) }
|
10
|
-
attr_accessor :wa_id
|
11
|
-
|
12
|
-
sig { returns(String) }
|
13
|
-
attr_accessor :input
|
14
|
-
|
15
|
-
sig { params(input: String, wa_id: String).void }
|
16
8
|
def initialize(input:, wa_id:)
|
17
9
|
@input = input
|
18
10
|
@wa_id = wa_id
|
@@ -1,37 +1,29 @@
|
|
1
|
-
# typed: strict
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module WhatsappSdk
|
5
4
|
module Resource
|
6
5
|
class Currency
|
7
|
-
extend T::Sig
|
8
|
-
|
9
6
|
# Returns default text if localization fails.
|
10
7
|
#
|
11
8
|
# @returns fallback_value [String].
|
12
|
-
sig { returns(String) }
|
13
9
|
attr_accessor :fallback_value
|
14
10
|
|
15
11
|
# Currency code as defined in ISO 4217.
|
16
12
|
#
|
17
13
|
# @returns code [String].
|
18
|
-
sig { returns(String) }
|
19
14
|
attr_accessor :code
|
20
15
|
|
21
16
|
# Amount multiplied by 1000.
|
22
17
|
#
|
23
18
|
# @returns code [Float].
|
24
|
-
sig { returns(T.any(Float, Integer)) }
|
25
19
|
attr_accessor :amount
|
26
20
|
|
27
|
-
sig { params(fallback_value: String, code: String, amount: T.any(Float, Integer)).void }
|
28
21
|
def initialize(fallback_value:, code:, amount:)
|
29
22
|
@fallback_value = fallback_value
|
30
23
|
@code = code
|
31
24
|
@amount = amount
|
32
25
|
end
|
33
26
|
|
34
|
-
sig { returns(T::Hash[T.untyped, T.untyped]) }
|
35
27
|
def to_json
|
36
28
|
{
|
37
29
|
fallback_value: fallback_value,
|
@@ -1,23 +1,17 @@
|
|
1
|
-
# typed: strict
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module WhatsappSdk
|
5
4
|
module Resource
|
6
5
|
class DateTime
|
7
|
-
extend T::Sig
|
8
|
-
|
9
6
|
# Returns default text if localization fails.
|
10
7
|
#
|
11
8
|
# @returns fallback_value [String].
|
12
|
-
sig { returns(String) }
|
13
9
|
attr_accessor :fallback_value
|
14
10
|
|
15
|
-
sig { params(fallback_value: String).void }
|
16
11
|
def initialize(fallback_value:)
|
17
12
|
@fallback_value = fallback_value
|
18
13
|
end
|
19
14
|
|
20
|
-
sig { returns(T::Hash[T.untyped, T.untyped]) }
|
21
15
|
def to_json
|
22
16
|
{
|
23
17
|
fallback_value: fallback_value
|
@@ -1,24 +1,15 @@
|
|
1
|
-
# typed: strict
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module WhatsappSdk
|
5
4
|
module Resource
|
6
5
|
class Email
|
7
|
-
|
6
|
+
attr_accessor :email, :type
|
8
7
|
|
9
|
-
sig { returns(String) }
|
10
|
-
attr_accessor :email
|
11
|
-
|
12
|
-
sig { returns(AddressType) }
|
13
|
-
attr_accessor :type
|
14
|
-
|
15
|
-
sig { params(email: String, type: AddressType).void }
|
16
8
|
def initialize(email:, type:)
|
17
9
|
@email = email
|
18
10
|
@type = type
|
19
11
|
end
|
20
12
|
|
21
|
-
sig { returns(T::Hash[T.untyped, T.untyped]) }
|
22
13
|
def to_h
|
23
14
|
{
|
24
15
|
email: @email,
|
@@ -1,16 +1,11 @@
|
|
1
|
-
# typed: strict
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module WhatsappSdk
|
5
4
|
module Resource
|
6
5
|
module Errors
|
7
6
|
class MissingArgumentError < StandardError
|
8
|
-
extend T::Sig
|
9
|
-
|
10
|
-
sig { returns(String) }
|
11
7
|
attr_reader :message
|
12
8
|
|
13
|
-
sig { params(message: String).void }
|
14
9
|
def initialize(message)
|
15
10
|
@message = message
|
16
11
|
super(message)
|
@@ -18,15 +13,8 @@ module WhatsappSdk
|
|
18
13
|
end
|
19
14
|
|
20
15
|
class MissingValue < Error
|
21
|
-
|
22
|
-
|
23
|
-
sig { returns(String) }
|
24
|
-
attr_reader :field
|
16
|
+
attr_reader :field, :message
|
25
17
|
|
26
|
-
sig { returns(String) }
|
27
|
-
attr_reader :message
|
28
|
-
|
29
|
-
sig { params(field: String, message: String).void }
|
30
18
|
def initialize(field, message)
|
31
19
|
@field = field
|
32
20
|
@message = message
|
@@ -35,14 +23,10 @@ module WhatsappSdk
|
|
35
23
|
end
|
36
24
|
|
37
25
|
class InvalidLanguageError < StandardError
|
38
|
-
extend T::Sig
|
39
|
-
|
40
26
|
URL_AVAILABLE_LANGUAGES = "https://developers.facebook.com/docs/whatsapp/api/messages/message-templates"
|
41
27
|
|
42
|
-
sig { returns(String) }
|
43
28
|
attr_reader :language
|
44
29
|
|
45
|
-
sig { params(language: String).void }
|
46
30
|
def initialize(language:)
|
47
31
|
@language = language
|
48
32
|
|
@@ -1,58 +1,40 @@
|
|
1
|
-
# typed: strict
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module WhatsappSdk
|
5
4
|
module Resource
|
6
5
|
class Interactive
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
enums do
|
13
|
-
ListMessage = new("list")
|
14
|
-
ReplyButton = new("button")
|
15
|
-
SingleProductMessage = new("product")
|
16
|
-
MultiProductMessage = new("product_list")
|
17
|
-
end
|
6
|
+
module Type
|
7
|
+
LIST_MESSAGE = "list"
|
8
|
+
REPLY_BUTTON = "button"
|
9
|
+
SINGLE_PRODUCT_MESSAGE = "product"
|
10
|
+
MULTI_PRODUCT_MESSAGE = "product_list"
|
18
11
|
end
|
19
12
|
|
20
13
|
# Returns the Interactive type of message you want to send.
|
21
14
|
#
|
22
15
|
# @returns type [Type]. Supported Options are list, button, product and product_list.
|
23
|
-
sig { returns(Type) }
|
24
16
|
attr_accessor :type
|
25
17
|
|
26
18
|
# Returns the interactive header if present. Required for type product_list.
|
27
19
|
#
|
28
20
|
# @returns type [InteractiveHeader] It can be nil.
|
29
|
-
sig { returns(T.nilable(InteractiveHeader)) }
|
30
21
|
attr_accessor :header
|
31
22
|
|
32
23
|
# Returns the interactive body.
|
33
24
|
#
|
34
25
|
# @returns type [InteractiveBody] Valid option is of type text only.
|
35
|
-
sig { returns(InteractiveBody) }
|
36
26
|
attr_accessor :body
|
37
27
|
|
38
28
|
# Returns the interactive footer if present.
|
39
29
|
#
|
40
30
|
# @returns type [InteractiveFooter] Valid option is of type text only. It can be nil.
|
41
|
-
sig { returns(T.nilable(InteractiveFooter)) }
|
42
31
|
attr_accessor :footer
|
43
32
|
|
44
33
|
# Returns the interactive action.
|
45
34
|
#
|
46
35
|
# @returns type [InteractiveBody] Valid condition is buttons of length of 1, 2 or 3 if type is button.
|
47
|
-
sig { returns(InteractiveAction) }
|
48
36
|
attr_accessor :action
|
49
37
|
|
50
|
-
sig do
|
51
|
-
params(
|
52
|
-
type: Type, body: InteractiveBody, action: InteractiveAction,
|
53
|
-
header: T.nilable(InteractiveHeader), footer: T.nilable(InteractiveFooter)
|
54
|
-
).void
|
55
|
-
end
|
56
38
|
def initialize(type:, body:, action:, header: nil, footer: nil)
|
57
39
|
@type = type
|
58
40
|
@body = body
|
@@ -62,9 +44,8 @@ module WhatsappSdk
|
|
62
44
|
validate
|
63
45
|
end
|
64
46
|
|
65
|
-
sig { returns(T::Hash[T.untyped, T.untyped]) }
|
66
47
|
def to_json
|
67
|
-
json = { type: type
|
48
|
+
json = { type: type }
|
68
49
|
json[:header] = header.to_json if header
|
69
50
|
json[:body] = body.to_json
|
70
51
|
json[:footer] = footer.to_json if footer
|
@@ -75,12 +56,10 @@ module WhatsappSdk
|
|
75
56
|
|
76
57
|
private
|
77
58
|
|
78
|
-
sig { void }
|
79
59
|
def validate
|
80
60
|
validate_action
|
81
61
|
end
|
82
62
|
|
83
|
-
sig { void }
|
84
63
|
def validate_action
|
85
64
|
action.validate
|
86
65
|
end
|
@@ -1,53 +1,46 @@
|
|
1
|
-
# typed: strict
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module WhatsappSdk
|
5
4
|
module Resource
|
6
5
|
class InteractiveAction
|
7
|
-
|
6
|
+
module Type
|
7
|
+
LIST_MESSAGE = "list_message"
|
8
|
+
REPLY_BUTTON = "reply_button"
|
8
9
|
|
9
|
-
|
10
|
-
extend T::Sig
|
10
|
+
TYPES = [LIST_MESSAGE, REPLY_BUTTON].freeze
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
ReplyButton = new("reply_button")
|
12
|
+
def valid?(type)
|
13
|
+
TYPES.include?(type)
|
15
14
|
end
|
16
15
|
end
|
17
16
|
|
18
17
|
# Returns the type of interactive action you want to send.
|
19
18
|
#
|
20
19
|
# @returns type [Type]. Supported Options are list_message and reply_button.
|
21
|
-
sig { returns(Type) }
|
22
20
|
attr_accessor :type
|
23
21
|
|
24
22
|
# Returns the buttons of the Action. For reply_button type, it's required.
|
25
23
|
#
|
26
24
|
# @returns buttons [Array<InteractiveActionReplyButton>] .
|
27
|
-
sig { returns(T::Array[InteractiveActionReplyButton]) }
|
28
25
|
attr_accessor :buttons
|
29
26
|
|
30
27
|
# Returns the button of the Action. For list_message type, it's required.
|
31
28
|
#
|
32
29
|
# @returns button [String] .
|
33
|
-
sig { returns(String) }
|
34
30
|
attr_accessor :button
|
35
31
|
|
36
32
|
# Returns the sections of the Action. For list_message type, it's required.
|
37
33
|
#
|
38
34
|
# @returns sections [Array<InteractiveActionSection>] .
|
39
|
-
sig { returns(T::Array[InteractiveActionSection]) }
|
40
35
|
attr_accessor :sections
|
41
36
|
|
42
37
|
# TODO: attr_accessor :catalog_id
|
43
38
|
# TODO: attr_accessor :product_retailer_id
|
44
39
|
|
45
|
-
sig { params(reply_button: InteractiveActionReplyButton).void }
|
46
40
|
def add_reply_button(reply_button)
|
47
41
|
@buttons << reply_button
|
48
42
|
end
|
49
43
|
|
50
|
-
sig { params(section: InteractiveActionSection).void }
|
51
44
|
def add_section(section)
|
52
45
|
@sections << section
|
53
46
|
end
|
@@ -58,12 +51,6 @@ module WhatsappSdk
|
|
58
51
|
LIST_SECTIONS_MINIMUM = 1
|
59
52
|
LIST_SECTIONS_MAXIMUM = 10
|
60
53
|
|
61
|
-
sig do
|
62
|
-
params(
|
63
|
-
type: Type, buttons: T::Array[InteractiveActionReplyButton],
|
64
|
-
button: String, sections: T::Array[InteractiveActionSection]
|
65
|
-
).void
|
66
|
-
end
|
67
54
|
def initialize(type:, buttons: [], button: "", sections: [])
|
68
55
|
@type = type
|
69
56
|
@buttons = buttons
|
@@ -71,10 +58,9 @@ module WhatsappSdk
|
|
71
58
|
@sections = sections
|
72
59
|
end
|
73
60
|
|
74
|
-
sig { returns(T::Hash[T.untyped, T.untyped]) }
|
75
61
|
def to_json
|
76
62
|
json = {}
|
77
|
-
case type
|
63
|
+
case type
|
78
64
|
when "list_message"
|
79
65
|
json = { button: button, sections: sections.map(&:to_json) }
|
80
66
|
when "reply_button"
|
@@ -91,10 +77,10 @@ module WhatsappSdk
|
|
91
77
|
private
|
92
78
|
|
93
79
|
def validate_fields
|
94
|
-
case type
|
95
|
-
when
|
80
|
+
case type
|
81
|
+
when Type::LIST_MESSAGE
|
96
82
|
validate_list_message
|
97
|
-
when
|
83
|
+
when Type::REPLY_BUTTON
|
98
84
|
validate_reply_button
|
99
85
|
end
|
100
86
|
end
|
@@ -1,52 +1,41 @@
|
|
1
|
-
# typed: strict
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module WhatsappSdk
|
5
4
|
module Resource
|
6
5
|
class InteractiveActionReplyButton
|
7
|
-
|
8
|
-
|
9
|
-
class Type < T::Enum
|
10
|
-
extend T::Sig
|
11
|
-
|
12
|
-
enums do
|
13
|
-
Reply = new("reply")
|
14
|
-
end
|
6
|
+
module Type
|
7
|
+
REPLY = "reply"
|
15
8
|
end
|
16
9
|
|
17
10
|
# Returns the ActionButton type of message you want to send.
|
18
11
|
#
|
19
12
|
# @returns type [String]. Supported Options are reply only.
|
20
|
-
sig { returns(Type) }
|
21
13
|
attr_accessor :type
|
22
14
|
|
23
15
|
# Returns the ActionButton title you want to send.
|
24
16
|
#
|
25
17
|
# @returns title [String]. The character limit is 20 characters.
|
26
|
-
sig { returns(String) }
|
27
18
|
attr_accessor :title
|
28
19
|
|
29
20
|
# Returns the ActionButton unique identifier you want to send.
|
30
21
|
# This ID is returned in the webhook when the button is clicked by the user.
|
31
22
|
#
|
32
23
|
# @returns id [String]. The character limit is 256 characters.
|
33
|
-
sig { returns(String) }
|
34
24
|
attr_accessor :id
|
35
25
|
|
36
26
|
ACTION_BUTTON_TITLE_MAXIMUM = 20
|
37
27
|
ACTION_BUTTON_ID_MAXIMUM = 256
|
38
28
|
|
39
|
-
sig { params(title: String, id: String).void }
|
40
29
|
def initialize(title:, id:)
|
41
|
-
@type = Type::
|
30
|
+
@type = Type::REPLY
|
42
31
|
@title = title
|
43
32
|
@id = id
|
44
33
|
validate
|
45
34
|
end
|
46
35
|
|
47
36
|
def to_json
|
48
|
-
json = { type: type
|
49
|
-
json[type.
|
37
|
+
json = { type: type }
|
38
|
+
json[type.to_sym] = {
|
50
39
|
id: id,
|
51
40
|
title: title
|
52
41
|
}
|
@@ -56,13 +45,11 @@ module WhatsappSdk
|
|
56
45
|
|
57
46
|
private
|
58
47
|
|
59
|
-
sig { void }
|
60
48
|
def validate
|
61
49
|
validate_title
|
62
50
|
validate_id
|
63
51
|
end
|
64
52
|
|
65
|
-
sig { void }
|
66
53
|
def validate_title
|
67
54
|
title_length = title.length
|
68
55
|
return if title_length <= ACTION_BUTTON_TITLE_MAXIMUM
|
@@ -72,7 +59,6 @@ module WhatsappSdk
|
|
72
59
|
"Maximum length: #{ACTION_BUTTON_TITLE_MAXIMUM} characters."
|
73
60
|
end
|
74
61
|
|
75
|
-
sig { void }
|
76
62
|
def validate_id
|
77
63
|
id_unfrozen = id.dup
|
78
64
|
id_unfrozen.strip! # You cannot have leading or trailing spaces when setting the ID.
|
@@ -1,24 +1,18 @@
|
|
1
|
-
# typed: strict
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module WhatsappSdk
|
5
4
|
module Resource
|
6
5
|
class InteractiveActionSection
|
7
|
-
extend T::Sig
|
8
|
-
|
9
6
|
# Returns the ActionSection title you want to send.
|
10
7
|
#
|
11
8
|
# @returns title [String]. The character limit is 24 characters.
|
12
|
-
sig { returns(String) }
|
13
9
|
attr_accessor :title
|
14
10
|
|
15
11
|
# Returns the ActionSection rows you want to send.
|
16
12
|
#
|
17
|
-
# @returns
|
18
|
-
sig { returns(T::Array[InteractiveActionSectionRow]) }
|
13
|
+
# @returns an array of InteractiveActionSectionRow. There must be at least one rows object.
|
19
14
|
attr_accessor :rows
|
20
15
|
|
21
|
-
sig { params(row: InteractiveActionSectionRow).void }
|
22
16
|
def add_row(row)
|
23
17
|
@rows << row
|
24
18
|
end
|
@@ -26,7 +20,6 @@ module WhatsappSdk
|
|
26
20
|
ACTION_SECTION_TITLE_MAXIMUM = 24
|
27
21
|
ACTION_SECTION_ROWS_MAXIMUM = 10
|
28
22
|
|
29
|
-
sig { params(title: String, rows: T::Array[InteractiveActionSectionRow]).void }
|
30
23
|
def initialize(title:, rows: [])
|
31
24
|
@title = title
|
32
25
|
@rows = rows
|
@@ -40,7 +33,6 @@ module WhatsappSdk
|
|
40
33
|
}
|
41
34
|
end
|
42
35
|
|
43
|
-
sig { params(skip_rows: T.nilable(T::Boolean)).void }
|
44
36
|
def validate(skip_rows: false)
|
45
37
|
validate_title
|
46
38
|
validate_rows unless skip_rows
|
@@ -48,7 +40,6 @@ module WhatsappSdk
|
|
48
40
|
|
49
41
|
private
|
50
42
|
|
51
|
-
sig { void }
|
52
43
|
def validate_title
|
53
44
|
title_length = title.length
|
54
45
|
return if title_length <= ACTION_SECTION_TITLE_MAXIMUM
|
@@ -58,7 +49,6 @@ module WhatsappSdk
|
|
58
49
|
"#{ACTION_SECTION_TITLE_MAXIMUM} characters."
|
59
50
|
end
|
60
51
|
|
61
|
-
sig { void }
|
62
52
|
def validate_rows
|
63
53
|
rows_length = rows.length
|
64
54
|
return if rows_length <= ACTION_SECTION_ROWS_MAXIMUM
|
@@ -1,35 +1,28 @@
|
|
1
|
-
# typed: strict
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module WhatsappSdk
|
5
4
|
module Resource
|
6
5
|
class InteractiveActionSectionRow
|
7
|
-
extend T::Sig
|
8
|
-
|
9
6
|
# Returns the ActionSection title you want to send.
|
10
7
|
#
|
11
8
|
# @returns title [String]. The character limit is 24 characters.
|
12
|
-
sig { returns(String) }
|
13
9
|
attr_accessor :title
|
14
10
|
|
15
11
|
# Returns the ActionSection description you want to send.
|
16
12
|
#
|
17
13
|
# @returns description [String]. The character limit is 72 characters if present.
|
18
|
-
sig { returns(String) }
|
19
14
|
attr_accessor :description
|
20
15
|
|
21
16
|
# Returns the ActionSection unique identifier you want to send.
|
22
17
|
# This ID is returned in the webhook when the section is selected by the user.
|
23
18
|
#
|
24
19
|
# @returns id [String]. The character limit is 256 characters.
|
25
|
-
sig { returns(String) }
|
26
20
|
attr_accessor :id
|
27
21
|
|
28
22
|
ACTION_SECTION_TITLE_MAXIMUM = 24
|
29
23
|
ACTION_SECTION_DESCRIPTION_MAXIMUM = 72
|
30
24
|
ACTION_SECTION_ID_MAXIMUM = 256
|
31
25
|
|
32
|
-
sig { params(title: String, id: String, description: T.nilable(String)).void }
|
33
26
|
def initialize(title:, id:, description: "")
|
34
27
|
@title = title
|
35
28
|
@id = id
|
@@ -49,14 +42,12 @@ module WhatsappSdk
|
|
49
42
|
|
50
43
|
private
|
51
44
|
|
52
|
-
sig { void }
|
53
45
|
def validate
|
54
46
|
validate_title
|
55
47
|
validate_id
|
56
48
|
validate_description
|
57
49
|
end
|
58
50
|
|
59
|
-
sig { void }
|
60
51
|
def validate_title
|
61
52
|
title_length = title.length
|
62
53
|
return if title_length <= ACTION_SECTION_TITLE_MAXIMUM
|
@@ -66,7 +57,6 @@ module WhatsappSdk
|
|
66
57
|
"Maximum length: #{ACTION_SECTION_TITLE_MAXIMUM} characters."
|
67
58
|
end
|
68
59
|
|
69
|
-
sig { void }
|
70
60
|
def validate_id
|
71
61
|
id_unfrozen = id.dup
|
72
62
|
id_unfrozen.strip! # You cannot have leading or trailing spaces when setting the ID.
|
@@ -79,7 +69,6 @@ module WhatsappSdk
|
|
79
69
|
"#{ACTION_SECTION_ID_MAXIMUM} characters."
|
80
70
|
end
|
81
71
|
|
82
|
-
sig { void }
|
83
72
|
def validate_description
|
84
73
|
description_length = description.length
|
85
74
|
return if description_length <= ACTION_SECTION_DESCRIPTION_MAXIMUM
|
@@ -1,27 +1,19 @@
|
|
1
|
-
# typed: strict
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module WhatsappSdk
|
5
4
|
module Resource
|
6
5
|
class InteractiveBody
|
7
|
-
extend T::Sig
|
8
|
-
|
9
6
|
# Returns Text string if the parameter object type is text.
|
10
7
|
# For the body interactive, the character limit is 1024 characters.
|
11
8
|
#
|
12
9
|
# @returns text [String]
|
13
|
-
sig { returns(String) }
|
14
10
|
attr_accessor :text
|
15
11
|
|
16
|
-
sig do
|
17
|
-
params(text: String).void
|
18
|
-
end
|
19
12
|
def initialize(text:)
|
20
13
|
@text = text
|
21
14
|
validate
|
22
15
|
end
|
23
16
|
|
24
|
-
sig { returns(T::Hash[T.untyped, T.untyped]) }
|
25
17
|
def to_json
|
26
18
|
{ text: text }
|
27
19
|
end
|
@@ -30,12 +22,10 @@ module WhatsappSdk
|
|
30
22
|
|
31
23
|
private
|
32
24
|
|
33
|
-
sig { void }
|
34
25
|
def validate
|
35
26
|
validate_text
|
36
27
|
end
|
37
28
|
|
38
|
-
sig { void }
|
39
29
|
def validate_text
|
40
30
|
text_length = text.length
|
41
31
|
return if text_length <= MAXIMUM_LENGTH
|
@@ -1,27 +1,19 @@
|
|
1
|
-
# typed: strict
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module WhatsappSdk
|
5
4
|
module Resource
|
6
5
|
class InteractiveFooter
|
7
|
-
extend T::Sig
|
8
|
-
|
9
6
|
# Returns Text string if the parameter object type is text.
|
10
7
|
# For the body interactive, the character limit is 60 characters.
|
11
8
|
#
|
12
9
|
# @returns text [String]
|
13
|
-
sig { returns(String) }
|
14
10
|
attr_accessor :text
|
15
11
|
|
16
|
-
sig do
|
17
|
-
params(text: String).void
|
18
|
-
end
|
19
12
|
def initialize(text:)
|
20
13
|
@text = text
|
21
14
|
validate
|
22
15
|
end
|
23
16
|
|
24
|
-
sig { returns(T::Hash[T.untyped, T.untyped]) }
|
25
17
|
def to_json
|
26
18
|
{ text: text }
|
27
19
|
end
|
@@ -30,12 +22,10 @@ module WhatsappSdk
|
|
30
22
|
|
31
23
|
private
|
32
24
|
|
33
|
-
sig { void }
|
34
25
|
def validate
|
35
26
|
validate_text
|
36
27
|
end
|
37
28
|
|
38
|
-
sig { void }
|
39
29
|
def validate_text
|
40
30
|
text_length = text.length
|
41
31
|
return if text_length <= MAXIMUM_LENGTH
|