warb 1.0.0 → 1.0.1
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 +32 -9
- data/Rakefile +3 -3
- data/docs/README.md +4 -1
- data/docs/components/README.md +4 -1
- data/docs/components/button.md +62 -0
- data/docs/components/copy_code_button.md +57 -0
- data/docs/components/flow_button.md +102 -0
- data/docs/components/url_button.md +57 -0
- data/docs/messages/README.md +2 -1
- data/docs/messages/flow.md +241 -5
- 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 +373 -0
- data/docs/resources/README.md +14 -0
- data/docs/resources/currency.md +22 -0
- data/docs/resources/date_time.md +11 -0
- data/docs/resources/text.md +9 -0
- data/docs/setup.md +45 -1
- 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 +77 -43
- data/lib/warb/category.rb +8 -0
- data/lib/warb/client.rb +7 -5
- data/lib/warb/components/action.rb +12 -8
- data/lib/warb/components/button.rb +29 -0
- data/lib/warb/components/component.rb +19 -0
- data/lib/warb/components/copy_code_button.rb +30 -0
- data/lib/warb/components/flow_button.rb +32 -0
- data/lib/warb/components/quick_reply_button.rb +15 -0
- data/lib/warb/components/url_button.rb +30 -0
- data/lib/warb/components/voice_call_button.rb +15 -0
- data/lib/warb/configuration.rb +4 -1
- data/lib/warb/connection.rb +15 -9
- data/lib/warb/dispatcher.rb +4 -3
- data/lib/warb/dispatcher_concern.rb +6 -0
- data/lib/warb/errors.rb +27 -0
- data/lib/warb/indicator_dispatcher.rb +4 -4
- data/lib/warb/language.rb +8 -0
- 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 +47 -0
- data/lib/warb/resources/date_time.rb +34 -0
- data/lib/warb/resources/document.rb +1 -1
- data/lib/warb/resources/flow.rb +82 -20
- data/lib/warb/resources/helpers/header.rb +35 -0
- 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 +11 -1
- data/lib/warb/resources/location_request.rb +5 -3
- data/lib/warb/resources/reaction.rb +1 -1
- data/lib/warb/resources/resource.rb +14 -4
- data/lib/warb/resources/sticker.rb +1 -1
- data/lib/warb/resources/template.rb +163 -0
- data/lib/warb/resources/text.rb +31 -3
- data/lib/warb/resources/validation.rb +30 -0
- 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 +21 -0
- data/lib/warb/utils.rb +3 -1
- data/lib/warb/version.rb +1 -1
- data/lib/warb.rb +67 -31
- metadata +34 -3
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)
|
|
@@ -6,11 +8,10 @@ module Warb
|
|
|
6
8
|
end
|
|
7
9
|
|
|
8
10
|
def dispatch(recipient_number, reply_to: nil, **args, &block)
|
|
9
|
-
resource = block_given? ? @klass.new.tap(&block) : @klass.new(**args)
|
|
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
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Warb
|
|
2
4
|
module DispatcherConcern
|
|
3
5
|
def message
|
|
@@ -56,6 +58,10 @@ module Warb
|
|
|
56
58
|
@contact ||= Dispatcher.new Resources::Contact, dispatcher
|
|
57
59
|
end
|
|
58
60
|
|
|
61
|
+
def template
|
|
62
|
+
@template ||= TemplateDispatcher.new Resources::Template, dispatcher
|
|
63
|
+
end
|
|
64
|
+
|
|
59
65
|
def flow
|
|
60
66
|
@flow ||= Dispatcher.new Resources::Flow, dispatcher
|
|
61
67
|
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
|
|
@@ -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
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Warb
|
|
4
|
+
module Resources
|
|
5
|
+
class Currency < Resource
|
|
6
|
+
BRL = 'BRL'
|
|
7
|
+
USD = 'USD'
|
|
8
|
+
|
|
9
|
+
attr_accessor :amount, :code, :fallback
|
|
10
|
+
|
|
11
|
+
def initialize(**params)
|
|
12
|
+
super
|
|
13
|
+
|
|
14
|
+
@code = params[:code]
|
|
15
|
+
@amount = params[:amount]
|
|
16
|
+
@fallback = params[:fallback]
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def build_template_named_parameter(parameter_name)
|
|
20
|
+
common_currency_params.merge(parameter_name: parameter_name)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def build_template_positional_parameter
|
|
24
|
+
common_currency_params
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
# rubocop:disable Naming/VariableNumber
|
|
30
|
+
def common_currency_params
|
|
31
|
+
{
|
|
32
|
+
type: 'currency',
|
|
33
|
+
currency: {
|
|
34
|
+
amount_1000: amount * 1000,
|
|
35
|
+
code: code,
|
|
36
|
+
fallback_value: fallback || default_fallback_value
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
end
|
|
40
|
+
# rubocop:enable Naming/VariableNumber
|
|
41
|
+
|
|
42
|
+
def default_fallback_value
|
|
43
|
+
"#{amount} (#{code})"
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Warb
|
|
4
|
+
module Resources
|
|
5
|
+
class DateTime < Resource
|
|
6
|
+
attr_accessor :date_time
|
|
7
|
+
|
|
8
|
+
def initialize(date_time = nil, **params)
|
|
9
|
+
super(**params)
|
|
10
|
+
|
|
11
|
+
@date_time = date_time || params[:date_time]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def build_template_named_parameter(parameter_name)
|
|
15
|
+
common_date_time_params.merge(parameter_name: parameter_name)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def build_template_positional_parameter
|
|
19
|
+
common_date_time_params
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def common_date_time_params
|
|
25
|
+
{
|
|
26
|
+
type: 'date_time',
|
|
27
|
+
date_time: {
|
|
28
|
+
fallback_value: date_time
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
data/lib/warb/resources/flow.rb
CHANGED
|
@@ -3,31 +3,93 @@
|
|
|
3
3
|
module Warb
|
|
4
4
|
module Resources
|
|
5
5
|
class Flow < Resource
|
|
6
|
-
|
|
6
|
+
include Helpers::Header
|
|
7
|
+
|
|
8
|
+
attr_accessor :flow_id, :screen, :flow_action, :mode,
|
|
9
|
+
:flow_cta, :flow_token, :body, :header, :footer, :data,
|
|
10
|
+
:draft, :data_exchange
|
|
7
11
|
|
|
8
12
|
def build_payload
|
|
13
|
+
validate!
|
|
14
|
+
|
|
9
15
|
{
|
|
10
|
-
type:
|
|
11
|
-
interactive:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
mode: "draft",
|
|
24
|
-
flow_action_payload: {
|
|
25
|
-
screen: screen || @params[:screen]
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
16
|
+
type: 'interactive',
|
|
17
|
+
interactive: build_interactive
|
|
18
|
+
}
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def build_interactive
|
|
24
|
+
interactive = {
|
|
25
|
+
type: 'flow',
|
|
26
|
+
action: {
|
|
27
|
+
name: 'flow',
|
|
28
|
+
parameters: build_action_parameters
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
+
|
|
32
|
+
header = resolve(:header)
|
|
33
|
+
if header.is_a?(Hash)
|
|
34
|
+
interactive[:header] = header
|
|
35
|
+
elsif header.respond_to?(:build_header)
|
|
36
|
+
interactive[:header] = header.build_header
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
resolve(:body)
|
|
40
|
+
.then { |body| interactive[:body] = { text: body } }
|
|
41
|
+
|
|
42
|
+
resolve(:footer)
|
|
43
|
+
.then { |footer| interactive[:footer] = { text: footer } unless blank?(footer) }
|
|
44
|
+
|
|
45
|
+
interactive
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def build_action_parameters
|
|
49
|
+
params = {
|
|
50
|
+
flow_message_version: '3',
|
|
51
|
+
flow_id: resolve(:flow_id),
|
|
52
|
+
flow_action: final_action,
|
|
53
|
+
mode: final_mode
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
resolve(:flow_cta)
|
|
57
|
+
.then { |label| params[:flow_cta] = label unless blank?(label) }
|
|
58
|
+
|
|
59
|
+
resolve(:flow_token)
|
|
60
|
+
.then { |token| params[:flow_token] = token unless blank?(token) }
|
|
61
|
+
|
|
62
|
+
if final_action == 'navigate'
|
|
63
|
+
payload = { screen: resolve(:screen) }
|
|
64
|
+
initial = resolve(:data)
|
|
65
|
+
payload[:data] = initial unless blank?(initial)
|
|
66
|
+
params[:flow_action_payload] = payload
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
params
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def final_action
|
|
73
|
+
explicit = raw_value(:flow_action)
|
|
74
|
+
return explicit.to_s unless blank?(explicit)
|
|
75
|
+
|
|
76
|
+
resolve(:data_exchange) ? 'data_exchange' : 'navigate'
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def final_mode
|
|
80
|
+
explicit = raw_value(:mode)
|
|
81
|
+
return explicit.to_s unless blank?(explicit)
|
|
82
|
+
|
|
83
|
+
resolve(:draft) ? 'draft' : 'published'
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def validate!
|
|
87
|
+
validates :flow_id, required: true
|
|
88
|
+
validates :body, required: true
|
|
89
|
+
|
|
90
|
+
validates :screen,
|
|
91
|
+
required: -> { final_action == 'navigate' },
|
|
92
|
+
message: 'screen is required for flow_action=navigate'
|
|
31
93
|
end
|
|
32
94
|
end
|
|
33
95
|
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module Warb
|
|
2
|
+
module Resources
|
|
3
|
+
module Helpers
|
|
4
|
+
module Header
|
|
5
|
+
def add_text_header(content: nil, message: nil, text: nil, parameter_name: nil, &block)
|
|
6
|
+
add_header(Warb::Resources::Text.new(content:, message:, text:, parameter_name:), &block)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def add_image_header(media_id: nil, link: nil, &block)
|
|
10
|
+
add_header(Warb::Resources::Image.new(media_id:, link:), &block)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def add_document_header(media_id: nil, link: nil, filename: nil, &block)
|
|
14
|
+
add_header(Warb::Resources::Document.new(media_id:, link:, filename:), &block)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def add_video_header(media_id: nil, link: nil, &block)
|
|
18
|
+
add_header(Warb::Resources::Video.new(media_id:, link:), &block)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def add_location_header(latitude: nil, longitude: nil, address: nil, name: nil, &block)
|
|
22
|
+
add_header(Warb::Resources::Location.new(latitude:, longitude:, address:, name:), &block)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def add_header(instance, &)
|
|
28
|
+
@header = instance
|
|
29
|
+
|
|
30
|
+
block_given? ? @header.tap(&) : @header
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
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
|