warb 0.1.0 → 0.1.3
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +12 -5
- data/README.md +8 -0
- data/Rakefile +3 -3
- data/docs/messages/interactive_call_to_action_url.md +9 -9
- data/docs/messages/interactive_list.md +2 -2
- data/docs/messages/interactive_reply_button.md +9 -9
- data/docs/messages/template.md +13 -13
- data/examples/audio.rb +10 -10
- data/examples/document.rb +34 -34
- data/examples/image.rb +22 -22
- data/examples/interactive_call_to_action_url.rb +46 -46
- data/examples/interactive_list.rb +61 -61
- data/examples/interactive_reply_button.rb +43 -43
- data/examples/location.rb +32 -32
- data/examples/location_request.rb +11 -11
- data/examples/message.rb +8 -8
- data/examples/sticker.rb +10 -10
- data/examples/video.rb +22 -22
- data/examples/webhook.rb +44 -42
- data/lib/warb/client.rb +7 -5
- data/lib/warb/components/action.rb +12 -8
- data/lib/warb/components/button.rb +2 -2
- data/lib/warb/components/component.rb +1 -1
- data/lib/warb/components/copy_code_button.rb +4 -4
- data/lib/warb/components/quick_reply_button.rb +1 -1
- data/lib/warb/components/url_button.rb +4 -4
- data/lib/warb/components/voice_call_button.rb +1 -1
- data/lib/warb/configuration.rb +4 -1
- data/lib/warb/connection.rb +15 -9
- data/lib/warb/dispatcher.rb +3 -2
- data/lib/warb/dispatcher_concern.rb +2 -0
- data/lib/warb/errors.rb +27 -0
- data/lib/warb/indicator_dispatcher.rb +4 -4
- data/lib/warb/language.rb +2 -2
- data/lib/warb/media_dispatcher.rb +10 -10
- data/lib/warb/resources/audio.rb +1 -1
- data/lib/warb/resources/contact.rb +22 -20
- data/lib/warb/resources/currency.rb +6 -4
- data/lib/warb/resources/date_time.rb +1 -1
- data/lib/warb/resources/document.rb +1 -1
- data/lib/warb/resources/flow.rb +10 -8
- data/lib/warb/resources/image.rb +1 -1
- data/lib/warb/resources/interactive_call_to_action_url.rb +10 -8
- data/lib/warb/resources/interactive_list.rb +7 -5
- data/lib/warb/resources/interactive_reply_button.rb +10 -8
- data/lib/warb/resources/location.rb +1 -1
- data/lib/warb/resources/location_request.rb +5 -3
- data/lib/warb/resources/reaction.rb +1 -1
- data/lib/warb/resources/resource.rb +4 -4
- data/lib/warb/resources/sticker.rb +1 -1
- data/lib/warb/resources/template.rb +30 -29
- data/lib/warb/resources/text.rb +4 -4
- data/lib/warb/resources/video.rb +1 -1
- data/lib/warb/response.rb +33 -0
- data/lib/warb/response_error_handler.rb +42 -0
- data/lib/warb/template_dispatcher.rb +4 -2
- data/lib/warb/utils.rb +3 -1
- data/lib/warb/version.rb +1 -1
- data/lib/warb.rb +50 -42
- metadata +10 -3
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module Warb
|
|
4
4
|
module Components
|
|
5
5
|
class CopyCodeButton < Button
|
|
6
|
-
BUTTON_TYPE =
|
|
6
|
+
BUTTON_TYPE = 'copy_code'
|
|
7
7
|
|
|
8
8
|
attr_accessor :coupon_code
|
|
9
9
|
|
|
@@ -12,9 +12,9 @@ module Warb
|
|
|
12
12
|
|
|
13
13
|
if coupon_code || @params[:coupon_code]
|
|
14
14
|
button_payload[:parameters] = Array.new(1, {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
type: 'coupon_code',
|
|
16
|
+
coupon_code: coupon_code || @params[:coupon_code]
|
|
17
|
+
})
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
button_payload
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module Warb
|
|
4
4
|
module Components
|
|
5
5
|
class UrlButton < Button
|
|
6
|
-
BUTTON_TYPE =
|
|
6
|
+
BUTTON_TYPE = 'url'
|
|
7
7
|
|
|
8
8
|
attr_accessor :text
|
|
9
9
|
|
|
@@ -12,9 +12,9 @@ module Warb
|
|
|
12
12
|
|
|
13
13
|
if text || @params[:text]
|
|
14
14
|
button_payload[:parameters] = Array.new(1, {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
type: 'text',
|
|
16
|
+
text: text || @params[:text]
|
|
17
|
+
})
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
button_payload
|
data/lib/warb/configuration.rb
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Warb
|
|
2
4
|
class Configuration
|
|
3
|
-
attr_accessor :access_token, :sender_id, :business_id, :adapter, :logger
|
|
5
|
+
attr_accessor :access_token, :sender_id, :business_id, :adapter, :logger, :custom_errors
|
|
4
6
|
|
|
5
7
|
def initialize(access_token: nil, sender_id: nil, business_id: nil, adapter: nil, logger: nil)
|
|
6
8
|
@access_token = access_token
|
|
@@ -8,6 +10,7 @@ module Warb
|
|
|
8
10
|
@business_id = business_id
|
|
9
11
|
@adapter = adapter || Faraday.default_adapter
|
|
10
12
|
@logger = logger || Logger.new($stdout)
|
|
13
|
+
@custom_errors = CustomErrors.new.build
|
|
11
14
|
end
|
|
12
15
|
end
|
|
13
16
|
end
|
data/lib/warb/connection.rb
CHANGED
|
@@ -8,28 +8,34 @@ module Warb
|
|
|
8
8
|
@client = client
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
+
# rubocop:disable Metrics/ParameterLists
|
|
11
12
|
def send_request(http_method:, endpoint:, url: nil, data: {}, headers: {}, multipart: false,
|
|
12
13
|
endpoint_prefix: :sender_id)
|
|
13
|
-
conn =
|
|
14
|
-
conn.send(http_method, handle_endpoint(endpoint:, endpoint_prefix:), data, headers)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
conn = connection(url:, multipart:)
|
|
15
|
+
response = conn.send(http_method, handle_endpoint(endpoint:, endpoint_prefix:), data, headers)
|
|
16
|
+
if response.success?
|
|
17
|
+
Warb::Response.new(response.body)
|
|
18
|
+
else
|
|
19
|
+
Warb::ResponseErrorHandler.new(response.body, response.status).handle
|
|
20
|
+
end
|
|
21
|
+
rescue Faraday::Error => e
|
|
22
|
+
msg = e.response_body || e.message
|
|
23
|
+
raise RequestError, msg
|
|
18
24
|
end
|
|
25
|
+
# rubocop:enable Metrics/ParameterLists
|
|
19
26
|
|
|
20
27
|
private
|
|
21
28
|
|
|
22
|
-
def
|
|
23
|
-
url ||=
|
|
29
|
+
def connection(url:, multipart:)
|
|
30
|
+
url ||= 'https://graph.facebook.com/v22.0'
|
|
24
31
|
|
|
25
32
|
Faraday.new(url) do |conn|
|
|
26
33
|
conn.request(:multipart) if multipart
|
|
27
34
|
conn.request(:url_encoded) if multipart
|
|
28
35
|
conn.request(:json)
|
|
29
36
|
conn.response(:json)
|
|
30
|
-
conn.headers[
|
|
37
|
+
conn.headers['Authorization'] = "Bearer #{@client.access_token}" unless @client.access_token.nil?
|
|
31
38
|
conn.adapter(@client.adapter)
|
|
32
|
-
conn.response :raise_error
|
|
33
39
|
end
|
|
34
40
|
end
|
|
35
41
|
|
data/lib/warb/dispatcher.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Warb
|
|
2
4
|
class Dispatcher
|
|
3
5
|
def initialize(klass, client)
|
|
@@ -9,8 +11,7 @@ module Warb
|
|
|
9
11
|
resource = block_given? ? @klass.new(**args).tap(&block) : @klass.new(**args)
|
|
10
12
|
|
|
11
13
|
data = resource.call(recipient_number, reply_to:)
|
|
12
|
-
|
|
13
|
-
@client.post("messages", data)
|
|
14
|
+
@client.post('messages', data)
|
|
14
15
|
end
|
|
15
16
|
end
|
|
16
17
|
end
|
data/lib/warb/errors.rb
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
5
|
+
module Warb
|
|
6
|
+
class RequestError < StandardError; end
|
|
7
|
+
class BadRequest < RequestError; end
|
|
8
|
+
class Unauthorized < RequestError; end
|
|
9
|
+
class Forbidden < RequestError; end
|
|
10
|
+
class NotFound < RequestError; end
|
|
11
|
+
class InternalServerError < RequestError; end
|
|
12
|
+
class ServiceUnavailable < RequestError; end
|
|
13
|
+
|
|
14
|
+
# custom error classes
|
|
15
|
+
class IntegrityError < Forbidden; end
|
|
16
|
+
class InvalidBusinessNumber < BadRequest; end
|
|
17
|
+
|
|
18
|
+
class CustomErrors
|
|
19
|
+
def build
|
|
20
|
+
{
|
|
21
|
+
400 => {
|
|
22
|
+
33 => InvalidBusinessNumber
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -7,15 +7,15 @@ module Warb
|
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
def send_typing_indicator(message_id)
|
|
10
|
-
data = common_indicator_params(message_id).merge(typing_indicator: { type:
|
|
10
|
+
data = common_indicator_params(message_id).merge(typing_indicator: { type: 'text' })
|
|
11
11
|
|
|
12
|
-
@client.post(
|
|
12
|
+
@client.post('messages', data)
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def mark_as_read(message_id)
|
|
16
16
|
data = common_indicator_params(message_id)
|
|
17
17
|
|
|
18
|
-
@client.post(
|
|
18
|
+
@client.post('messages', data)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
private
|
|
@@ -24,7 +24,7 @@ module Warb
|
|
|
24
24
|
{
|
|
25
25
|
messaging_product: Warb::MESSAGING_PRODUCT,
|
|
26
26
|
message_id: message_id,
|
|
27
|
-
status:
|
|
27
|
+
status: 'read'
|
|
28
28
|
}
|
|
29
29
|
end
|
|
30
30
|
end
|
data/lib/warb/language.rb
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Warb
|
|
2
4
|
class MediaDispatcher < Dispatcher
|
|
3
|
-
def upload(file_path:, file_type:
|
|
5
|
+
def upload(file_path:, file_type: 'text/plain')
|
|
4
6
|
file = Faraday::UploadIO.new(file_path, file_type)
|
|
5
7
|
|
|
6
8
|
data = { file:, messaging_product: Warb::MESSAGING_PRODUCT }
|
|
7
9
|
|
|
8
|
-
@client.post(
|
|
10
|
+
@client.post('media', data, multipart: true).body['id']
|
|
9
11
|
end
|
|
10
12
|
|
|
11
13
|
def download(file_path:, media_url: nil, media_id: nil)
|
|
12
|
-
media_url ||= retrieve(media_id)[
|
|
14
|
+
media_url ||= retrieve(media_id)['url']
|
|
13
15
|
|
|
14
16
|
resp = downloaded_media_response(media_url)
|
|
15
17
|
|
|
16
|
-
File.
|
|
17
|
-
file.write(resp.body)
|
|
18
|
-
end
|
|
18
|
+
File.binwrite(file_path, resp.body)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def retrieve(media_id)
|
|
@@ -25,9 +25,9 @@ module Warb
|
|
|
25
25
|
def delete(media_id)
|
|
26
26
|
response_body = @client.delete(media_id, endpoint_prefix: nil).body
|
|
27
27
|
|
|
28
|
-
return response_body[
|
|
28
|
+
return response_body['success'] if response_body['success']
|
|
29
29
|
|
|
30
|
-
response_body[
|
|
30
|
+
response_body['error']['message']
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
private
|
|
@@ -36,9 +36,9 @@ module Warb
|
|
|
36
36
|
uri = URI(url)
|
|
37
37
|
|
|
38
38
|
request = Net::HTTP::Get.new(uri)
|
|
39
|
-
request[
|
|
39
|
+
request['Authorization'] = "Bearer #{@client.access_token}"
|
|
40
40
|
|
|
41
|
-
Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme ==
|
|
41
|
+
Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
|
42
42
|
http.request(request)
|
|
43
43
|
end
|
|
44
44
|
end
|
data/lib/warb/resources/audio.rb
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative
|
|
4
|
-
require_relative
|
|
5
|
-
require_relative
|
|
6
|
-
require_relative
|
|
7
|
-
require_relative
|
|
8
|
-
require_relative
|
|
3
|
+
require_relative '../components/address'
|
|
4
|
+
require_relative '../components/name'
|
|
5
|
+
require_relative '../components/email'
|
|
6
|
+
require_relative '../components/org'
|
|
7
|
+
require_relative '../components/phone'
|
|
8
|
+
require_relative '../components/url'
|
|
9
9
|
|
|
10
10
|
module Warb
|
|
11
11
|
module Resources
|
|
@@ -13,7 +13,7 @@ module Warb
|
|
|
13
13
|
attr_accessor :addresses, :emails, :phones, :urls, :name, :org, :birthday
|
|
14
14
|
|
|
15
15
|
def initialize(**params)
|
|
16
|
-
super
|
|
16
|
+
super
|
|
17
17
|
|
|
18
18
|
@org = @params[:org]
|
|
19
19
|
@name = @params[:name]
|
|
@@ -24,9 +24,10 @@ module Warb
|
|
|
24
24
|
@urls = @params.fetch(:urls, [])
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
+
# rubocop:disable Metrics/MethodLength
|
|
27
28
|
def build_payload
|
|
28
29
|
{
|
|
29
|
-
type:
|
|
30
|
+
type: 'contacts',
|
|
30
31
|
contacts: [
|
|
31
32
|
{
|
|
32
33
|
birthday: birthday,
|
|
@@ -40,49 +41,50 @@ module Warb
|
|
|
40
41
|
]
|
|
41
42
|
}
|
|
42
43
|
end
|
|
44
|
+
# rubocop:enable Metrics/MethodLength
|
|
43
45
|
|
|
44
|
-
def add_address(**params, &
|
|
46
|
+
def add_address(**params, &)
|
|
45
47
|
address = Components::Address.new(**params)
|
|
46
48
|
|
|
47
49
|
@addresses << address
|
|
48
50
|
|
|
49
|
-
block_given? ? address.tap(&
|
|
51
|
+
block_given? ? address.tap(&) : address
|
|
50
52
|
end
|
|
51
53
|
|
|
52
|
-
def add_email(**params, &
|
|
54
|
+
def add_email(**params, &)
|
|
53
55
|
email = Components::Email.new(**params)
|
|
54
56
|
|
|
55
57
|
@emails << email
|
|
56
58
|
|
|
57
|
-
block_given? ? email.tap(&
|
|
59
|
+
block_given? ? email.tap(&) : email
|
|
58
60
|
end
|
|
59
61
|
|
|
60
|
-
def add_phone(**params, &
|
|
62
|
+
def add_phone(**params, &)
|
|
61
63
|
phone = Components::Phone.new(**params)
|
|
62
64
|
|
|
63
65
|
@phones << phone
|
|
64
66
|
|
|
65
|
-
block_given? ? phone.tap(&
|
|
67
|
+
block_given? ? phone.tap(&) : phone
|
|
66
68
|
end
|
|
67
69
|
|
|
68
|
-
def add_url(**params, &
|
|
70
|
+
def add_url(**params, &)
|
|
69
71
|
url = Components::URL.new(**params)
|
|
70
72
|
|
|
71
73
|
@urls << url
|
|
72
74
|
|
|
73
|
-
block_given? ? url.tap(&
|
|
75
|
+
block_given? ? url.tap(&) : url
|
|
74
76
|
end
|
|
75
77
|
|
|
76
|
-
def build_name(**params, &
|
|
78
|
+
def build_name(**params, &)
|
|
77
79
|
@name = Warb::Components::Name.new(**params)
|
|
78
80
|
|
|
79
|
-
block_given? ? @name.tap(&
|
|
81
|
+
block_given? ? @name.tap(&) : @name
|
|
80
82
|
end
|
|
81
83
|
|
|
82
|
-
def build_org(**params, &
|
|
84
|
+
def build_org(**params, &)
|
|
83
85
|
@org = Warb::Components::Org.new(**params)
|
|
84
86
|
|
|
85
|
-
block_given? ? @org.tap(&
|
|
87
|
+
block_given? ? @org.tap(&) : @org
|
|
86
88
|
end
|
|
87
89
|
end
|
|
88
90
|
end
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
module Warb
|
|
4
4
|
module Resources
|
|
5
5
|
class Currency < Resource
|
|
6
|
-
BRL =
|
|
7
|
-
USD =
|
|
6
|
+
BRL = 'BRL'
|
|
7
|
+
USD = 'USD'
|
|
8
8
|
|
|
9
9
|
attr_accessor :amount, :code, :fallback
|
|
10
10
|
|
|
11
11
|
def initialize(**params)
|
|
12
|
-
super
|
|
12
|
+
super
|
|
13
13
|
|
|
14
14
|
@code = params[:code]
|
|
15
15
|
@amount = params[:amount]
|
|
@@ -26,9 +26,10 @@ module Warb
|
|
|
26
26
|
|
|
27
27
|
private
|
|
28
28
|
|
|
29
|
+
# rubocop:disable Naming/VariableNumber
|
|
29
30
|
def common_currency_params
|
|
30
31
|
{
|
|
31
|
-
type:
|
|
32
|
+
type: 'currency',
|
|
32
33
|
currency: {
|
|
33
34
|
amount_1000: amount * 1000,
|
|
34
35
|
code: code,
|
|
@@ -36,6 +37,7 @@ module Warb
|
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
end
|
|
40
|
+
# rubocop:enable Naming/VariableNumber
|
|
39
41
|
|
|
40
42
|
def default_fallback_value
|
|
41
43
|
"#{amount} (#{code})"
|
data/lib/warb/resources/flow.rb
CHANGED
|
@@ -5,22 +5,23 @@ module Warb
|
|
|
5
5
|
class Flow < Resource
|
|
6
6
|
attr_accessor :flow_id, :screen
|
|
7
7
|
|
|
8
|
+
# rubocop:disable Metrics/MethodLength
|
|
8
9
|
def build_payload
|
|
9
10
|
{
|
|
10
|
-
type:
|
|
11
|
+
type: 'interactive',
|
|
11
12
|
interactive: {
|
|
12
|
-
type:
|
|
13
|
+
type: 'flow',
|
|
13
14
|
body: {
|
|
14
|
-
text:
|
|
15
|
+
text: 'Not shown in draft mode'
|
|
15
16
|
},
|
|
16
17
|
action: {
|
|
17
|
-
name:
|
|
18
|
+
name: 'flow',
|
|
18
19
|
parameters: {
|
|
19
|
-
flow_message_version:
|
|
20
|
-
flow_action:
|
|
20
|
+
flow_message_version: '3',
|
|
21
|
+
flow_action: 'navigate',
|
|
21
22
|
flow_id: flow_id || @params[:flow_id],
|
|
22
|
-
flow_cta:
|
|
23
|
-
mode:
|
|
23
|
+
flow_cta: 'Not shown in draft mode',
|
|
24
|
+
mode: 'draft',
|
|
24
25
|
flow_action_payload: {
|
|
25
26
|
screen: screen || @params[:screen]
|
|
26
27
|
}
|
|
@@ -29,6 +30,7 @@ module Warb
|
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
end
|
|
33
|
+
# rubocop:enable Metrics/MethodLength
|
|
32
34
|
end
|
|
33
35
|
end
|
|
34
36
|
end
|
data/lib/warb/resources/image.rb
CHANGED
|
@@ -5,11 +5,12 @@ module Warb
|
|
|
5
5
|
class InteractiveCallToActionUrl < Resource
|
|
6
6
|
attr_accessor :header, :body, :footer, :action
|
|
7
7
|
|
|
8
|
+
# rubocop:disable Metrics/MethodLength
|
|
8
9
|
def build_payload
|
|
9
10
|
{
|
|
10
|
-
type:
|
|
11
|
+
type: 'interactive',
|
|
11
12
|
interactive: {
|
|
12
|
-
type:
|
|
13
|
+
type: 'cta_url',
|
|
13
14
|
header: header || @params[:header]&.to_h,
|
|
14
15
|
body: {
|
|
15
16
|
text: body || @params[:body]
|
|
@@ -21,27 +22,28 @@ module Warb
|
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
end
|
|
25
|
+
# rubocop:enable Metrics/MethodLength
|
|
24
26
|
|
|
25
|
-
def
|
|
27
|
+
def add_text_header(text)
|
|
26
28
|
@header = Warb::Resources::Text.new(text:).build_header
|
|
27
29
|
end
|
|
28
30
|
|
|
29
|
-
def
|
|
31
|
+
def add_image_header(link: nil)
|
|
30
32
|
@header = Warb::Resources::Image.new(link:).build_header
|
|
31
33
|
end
|
|
32
34
|
|
|
33
|
-
def
|
|
35
|
+
def add_video_header(link: nil)
|
|
34
36
|
@header = Warb::Resources::Video.new(link:).build_header
|
|
35
37
|
end
|
|
36
38
|
|
|
37
|
-
def
|
|
39
|
+
def add_document_header(link: nil, filename: nil)
|
|
38
40
|
@header = Warb::Resources::Document.new(link:, filename:).build_header
|
|
39
41
|
end
|
|
40
42
|
|
|
41
|
-
def build_action(**params, &
|
|
43
|
+
def build_action(**params, &)
|
|
42
44
|
@action = Warb::Components::CTAAction.new(**params)
|
|
43
45
|
|
|
44
|
-
block_given? ? @action.tap(&
|
|
46
|
+
block_given? ? @action.tap(&) : @action
|
|
45
47
|
end
|
|
46
48
|
end
|
|
47
49
|
end
|
|
@@ -5,11 +5,12 @@ module Warb
|
|
|
5
5
|
class InteractiveList < Resource
|
|
6
6
|
attr_accessor :header, :body, :footer, :action
|
|
7
7
|
|
|
8
|
+
# rubocop:disable Metrics/MethodLength
|
|
8
9
|
def build_payload
|
|
9
10
|
{
|
|
10
|
-
type:
|
|
11
|
+
type: 'interactive',
|
|
11
12
|
interactive: {
|
|
12
|
-
type:
|
|
13
|
+
type: 'list',
|
|
13
14
|
header: header || @params[:header]&.to_h,
|
|
14
15
|
body: {
|
|
15
16
|
text: body || @params[:body]
|
|
@@ -21,15 +22,16 @@ module Warb
|
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
end
|
|
25
|
+
# rubocop:enable Metrics/MethodLength
|
|
24
26
|
|
|
25
|
-
def
|
|
27
|
+
def add_text_header(text)
|
|
26
28
|
@header = Warb::Resources::Text.new(text:).build_header
|
|
27
29
|
end
|
|
28
30
|
|
|
29
|
-
def build_action(**params, &
|
|
31
|
+
def build_action(**params, &)
|
|
30
32
|
@action = Warb::Components::ListAction.new(**params)
|
|
31
33
|
|
|
32
|
-
block_given? ? @action.tap(&
|
|
34
|
+
block_given? ? @action.tap(&) : @action
|
|
33
35
|
end
|
|
34
36
|
end
|
|
35
37
|
end
|
|
@@ -5,11 +5,12 @@ module Warb
|
|
|
5
5
|
class InteractiveReplyButton < Resource
|
|
6
6
|
attr_accessor :header, :body, :footer, :action
|
|
7
7
|
|
|
8
|
+
# rubocop:disable Metrics/MethodLength
|
|
8
9
|
def build_payload
|
|
9
10
|
{
|
|
10
|
-
type:
|
|
11
|
+
type: 'interactive',
|
|
11
12
|
interactive: {
|
|
12
|
-
type:
|
|
13
|
+
type: 'button',
|
|
13
14
|
header: header || @params[:header]&.to_h,
|
|
14
15
|
body: {
|
|
15
16
|
text: body || @params[:body]
|
|
@@ -21,27 +22,28 @@ module Warb
|
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
end
|
|
25
|
+
# rubocop:enable Metrics/MethodLength
|
|
24
26
|
|
|
25
|
-
def
|
|
27
|
+
def add_text_header(text)
|
|
26
28
|
@header = Warb::Resources::Text.new(text:).build_header
|
|
27
29
|
end
|
|
28
30
|
|
|
29
|
-
def
|
|
31
|
+
def add_image_header(media_id: nil, link: nil)
|
|
30
32
|
@header = Warb::Resources::Image.new(media_id:, link:).build_header
|
|
31
33
|
end
|
|
32
34
|
|
|
33
|
-
def
|
|
35
|
+
def add_video_header(media_id: nil, link: nil)
|
|
34
36
|
@header = Warb::Resources::Video.new(media_id:, link:).build_header
|
|
35
37
|
end
|
|
36
38
|
|
|
37
|
-
def
|
|
39
|
+
def add_document_header(media_id: nil, link: nil, filename: nil)
|
|
38
40
|
@header = Warb::Resources::Document.new(media_id:, link:, filename:).build_header
|
|
39
41
|
end
|
|
40
42
|
|
|
41
|
-
def build_action(**params, &
|
|
43
|
+
def build_action(**params, &)
|
|
42
44
|
@action = Warb::Components::ReplyButtonAction.new(**params)
|
|
43
45
|
|
|
44
|
-
block_given? ? @action.tap(&
|
|
46
|
+
block_given? ? @action.tap(&) : @action
|
|
45
47
|
end
|
|
46
48
|
end
|
|
47
49
|
end
|
|
@@ -5,20 +5,22 @@ module Warb
|
|
|
5
5
|
class LocationRequest < Resource
|
|
6
6
|
attr_accessor :body_text
|
|
7
7
|
|
|
8
|
+
# rubocop:disable Metrics/MethodLength
|
|
8
9
|
def build_payload
|
|
9
10
|
{
|
|
10
|
-
type:
|
|
11
|
+
type: 'interactive',
|
|
11
12
|
interactive: {
|
|
12
|
-
type:
|
|
13
|
+
type: 'location_request_message',
|
|
13
14
|
body: {
|
|
14
15
|
text: body_text || @params[:body_text]
|
|
15
16
|
},
|
|
16
17
|
action: {
|
|
17
|
-
name:
|
|
18
|
+
name: 'send_location'
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
end
|
|
23
|
+
# rubocop:enable Metrics/MethodLength
|
|
22
24
|
end
|
|
23
25
|
end
|
|
24
26
|
end
|