warb 0.1.0 → 0.1.2
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
data/examples/location.rb
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative
|
|
3
|
+
require_relative '../lib/warb'
|
|
4
4
|
|
|
5
5
|
# Configure your variables here
|
|
6
6
|
|
|
7
|
-
access_token =
|
|
8
|
-
business_id =
|
|
9
|
-
sender_id =
|
|
10
|
-
recipient_number =
|
|
7
|
+
access_token = ''
|
|
8
|
+
business_id = ''
|
|
9
|
+
sender_id = ''
|
|
10
|
+
recipient_number = ''
|
|
11
11
|
|
|
12
12
|
# We recommend testing one section at a time, as it can be overwhelming to see all the messages at once.
|
|
13
13
|
# So you can comment out the sections you don't want to test.
|
|
@@ -22,20 +22,20 @@ warb_from_setup = Warb.setup do |config|
|
|
|
22
22
|
config.sender_id = sender_id
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
warb_from_setup.location.dispatch(recipient_number, latitude:
|
|
25
|
+
warb_from_setup.location.dispatch(recipient_number, latitude: '37.44216251868683', longitude: '-122.16153582049394')
|
|
26
26
|
warb_from_setup.location.dispatch(
|
|
27
27
|
recipient_number,
|
|
28
|
-
latitude:
|
|
29
|
-
longitude:
|
|
30
|
-
name:
|
|
31
|
-
address:
|
|
28
|
+
latitude: '37.44216251868683',
|
|
29
|
+
longitude: '-122.16153582049394',
|
|
30
|
+
name: 'OPTIONAL - Location Name',
|
|
31
|
+
address: 'OPTIONAL - Location Address'
|
|
32
32
|
)
|
|
33
33
|
|
|
34
34
|
warb_from_setup.location.dispatch(recipient_number) do |builder|
|
|
35
|
-
builder.latitude =
|
|
36
|
-
builder.longitude =
|
|
37
|
-
builder.name =
|
|
38
|
-
builder.address =
|
|
35
|
+
builder.latitude = '37.44216251868683'
|
|
36
|
+
builder.longitude = '-122.16153582049394'
|
|
37
|
+
builder.name = 'OPTIONAL - Location Name'
|
|
38
|
+
builder.address = 'OPTIONAL - Location Address'
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
# ############################################ #
|
|
@@ -48,38 +48,38 @@ warb_from_new = Warb.new(
|
|
|
48
48
|
sender_id: sender_id
|
|
49
49
|
)
|
|
50
50
|
|
|
51
|
-
warb_from_new.location.dispatch(recipient_number, latitude:
|
|
51
|
+
warb_from_new.location.dispatch(recipient_number, latitude: '37.44216251868683', longitude: '-122.16153582049394')
|
|
52
52
|
warb_from_new.location.dispatch(
|
|
53
53
|
recipient_number,
|
|
54
|
-
latitude:
|
|
55
|
-
longitude:
|
|
56
|
-
name:
|
|
57
|
-
address:
|
|
54
|
+
latitude: '37.44216251868683',
|
|
55
|
+
longitude: '-122.16153582049394',
|
|
56
|
+
name: 'OPTIONAL - Location Name',
|
|
57
|
+
address: 'OPTIONAL - Location Address'
|
|
58
58
|
)
|
|
59
59
|
|
|
60
60
|
warb_from_new.location.dispatch(recipient_number) do |builder|
|
|
61
|
-
builder.latitude =
|
|
62
|
-
builder.longitude =
|
|
63
|
-
builder.name =
|
|
64
|
-
builder.address =
|
|
61
|
+
builder.latitude = '37.44216251868683'
|
|
62
|
+
builder.longitude = '-122.16153582049394'
|
|
63
|
+
builder.name = 'OPTIONAL - Location Name'
|
|
64
|
+
builder.address = 'OPTIONAL - Location Address'
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
# ################################################# #
|
|
68
68
|
# ============== Using Warb directly ============== #
|
|
69
69
|
# ################################################# #
|
|
70
70
|
|
|
71
|
-
Warb.location.dispatch(recipient_number, latitude:
|
|
71
|
+
Warb.location.dispatch(recipient_number, latitude: '37.44216251868683', longitude: '-122.16153582049394')
|
|
72
72
|
Warb.location.dispatch(
|
|
73
73
|
recipient_number,
|
|
74
|
-
latitude:
|
|
75
|
-
longitude:
|
|
76
|
-
name:
|
|
77
|
-
address:
|
|
74
|
+
latitude: '37.44216251868683',
|
|
75
|
+
longitude: '-122.16153582049394',
|
|
76
|
+
name: 'OPTIONAL - Location Name',
|
|
77
|
+
address: 'OPTIONAL - Location Address'
|
|
78
78
|
)
|
|
79
79
|
|
|
80
80
|
Warb.location.dispatch(recipient_number) do |builder|
|
|
81
|
-
builder.latitude =
|
|
82
|
-
builder.longitude =
|
|
83
|
-
builder.name =
|
|
84
|
-
builder.address =
|
|
81
|
+
builder.latitude = '37.44216251868683'
|
|
82
|
+
builder.longitude = '-122.16153582049394'
|
|
83
|
+
builder.name = 'OPTIONAL - Location Name'
|
|
84
|
+
builder.address = 'OPTIONAL - Location Address'
|
|
85
85
|
end
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative
|
|
3
|
+
require_relative '../lib/warb'
|
|
4
4
|
|
|
5
5
|
# Configure your variables here
|
|
6
6
|
|
|
7
|
-
access_token =
|
|
8
|
-
business_id =
|
|
9
|
-
sender_id =
|
|
10
|
-
recipient_number =
|
|
7
|
+
access_token = ''
|
|
8
|
+
business_id = ''
|
|
9
|
+
sender_id = ''
|
|
10
|
+
recipient_number = ''
|
|
11
11
|
|
|
12
12
|
# We recommend testing one section at a time, as it can be overwhelming to see all the messages at once.
|
|
13
13
|
# So you can comment out the sections you don't want to test.
|
|
@@ -22,10 +22,10 @@ warb_from_setup = Warb.setup do |config|
|
|
|
22
22
|
config.sender_id = sender_id
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
warb_from_setup.location_request.dispatch(recipient_number, body_text:
|
|
25
|
+
warb_from_setup.location_request.dispatch(recipient_number, body_text: 'Location request body text')
|
|
26
26
|
|
|
27
27
|
warb_from_setup.location_request.dispatch(recipient_number) do |builder|
|
|
28
|
-
builder.body_text =
|
|
28
|
+
builder.body_text = 'Location request body text'
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
# ############################################ #
|
|
@@ -38,18 +38,18 @@ warb_from_new = Warb.new(
|
|
|
38
38
|
sender_id: sender_id
|
|
39
39
|
)
|
|
40
40
|
|
|
41
|
-
warb_from_new.location_request.dispatch(recipient_number, body_text:
|
|
41
|
+
warb_from_new.location_request.dispatch(recipient_number, body_text: 'Location request body text')
|
|
42
42
|
|
|
43
43
|
warb_from_new.location_request.dispatch(recipient_number) do |builder|
|
|
44
|
-
builder.body_text =
|
|
44
|
+
builder.body_text = 'Location request body text'
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
# ################################################# #
|
|
48
48
|
# ============== Using Warb directly ============== #
|
|
49
49
|
# ################################################# #
|
|
50
50
|
|
|
51
|
-
Warb.location_request.dispatch(recipient_number, body_text:
|
|
51
|
+
Warb.location_request.dispatch(recipient_number, body_text: 'Location request body text')
|
|
52
52
|
|
|
53
53
|
Warb.location_request.dispatch(recipient_number) do |builder|
|
|
54
|
-
builder.body_text =
|
|
54
|
+
builder.body_text = 'Location request body text'
|
|
55
55
|
end
|
data/examples/message.rb
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative
|
|
3
|
+
require_relative '../lib/warb'
|
|
4
4
|
|
|
5
5
|
# Configure your variables here
|
|
6
6
|
|
|
7
|
-
access_token =
|
|
8
|
-
business_id =
|
|
9
|
-
sender_id =
|
|
10
|
-
recipient_number =
|
|
7
|
+
access_token = ''
|
|
8
|
+
business_id = ''
|
|
9
|
+
sender_id = ''
|
|
10
|
+
recipient_number = ''
|
|
11
11
|
|
|
12
12
|
# We recommend testing one section at a time, as it can be overwhelming to see all the messages at once.
|
|
13
13
|
# So you can comment out the sections you don't want to test.
|
|
@@ -27,7 +27,7 @@ warb_from_setup.message.dispatch(recipient_number, message: 'Hello from warb! Me
|
|
|
27
27
|
warb_from_setup.message.dispatch(recipient_number, text: 'Hello from warb! Message sent with "text" key')
|
|
28
28
|
|
|
29
29
|
warb_from_setup.message.dispatch(recipient_number) do |builder|
|
|
30
|
-
builder.content =
|
|
30
|
+
builder.content = 'Hello from warb! Message sent with block builder'
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
# ############################################ #
|
|
@@ -45,7 +45,7 @@ warb_from_new.message.dispatch(recipient_number, message: 'Hello from warb! Mess
|
|
|
45
45
|
warb_from_new.message.dispatch(recipient_number, text: 'Hello from warb! Message sent with "text" key')
|
|
46
46
|
|
|
47
47
|
warb_from_new.message.dispatch(recipient_number) do |builder|
|
|
48
|
-
builder.content =
|
|
48
|
+
builder.content = 'Hello from warb! Message sent with block builder'
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
# ################################################# #
|
|
@@ -57,5 +57,5 @@ Warb.message.dispatch(recipient_number, message: 'Hello from warb! Message sent
|
|
|
57
57
|
Warb.message.dispatch(recipient_number, text: 'Hello from warb! Message sent with "text" key')
|
|
58
58
|
|
|
59
59
|
Warb.message.dispatch(recipient_number) do |builder|
|
|
60
|
-
builder.content =
|
|
60
|
+
builder.content = 'Hello from warb! Message sent with block builder'
|
|
61
61
|
end
|
data/examples/sticker.rb
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative
|
|
3
|
+
require_relative '../lib/warb'
|
|
4
4
|
|
|
5
5
|
# Configure your variables here
|
|
6
6
|
|
|
7
|
-
access_token =
|
|
8
|
-
business_id =
|
|
9
|
-
sender_id =
|
|
10
|
-
recipient_number =
|
|
7
|
+
access_token = ''
|
|
8
|
+
business_id = ''
|
|
9
|
+
sender_id = ''
|
|
10
|
+
recipient_number = ''
|
|
11
11
|
|
|
12
|
-
image_link =
|
|
12
|
+
image_link = ''
|
|
13
13
|
|
|
14
14
|
# We recommend testing one section at a time, as it can be overwhelming to see all the messages at once.
|
|
15
15
|
# So you can comment out the sections you don't want to test.
|
|
@@ -25,8 +25,8 @@ warb_from_setup = Warb.setup do |config|
|
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
# To send sticker using its ID, you may need to retrieve it first, which can be retrieved this way
|
|
28
|
-
file_path =
|
|
29
|
-
file_type =
|
|
28
|
+
file_path = '' # fill this in with the file path pointing to wherever the sticker is located
|
|
29
|
+
file_type = 'image/webp' # fill this in with the mimetype of the sticker to be uploaded
|
|
30
30
|
# only image/webp is allowed for sticker file type
|
|
31
31
|
image_id = warb_from_setup.sticker.upload(file_path: file_path, file_type: file_type)
|
|
32
32
|
# if you already have an sticker id, you can simply replace the above line with such id
|
|
@@ -53,8 +53,8 @@ warb_from_new = Warb.new(
|
|
|
53
53
|
)
|
|
54
54
|
|
|
55
55
|
# Same as stated above, if you need a sticker id, you can upload it this way
|
|
56
|
-
file_path =
|
|
57
|
-
file_type =
|
|
56
|
+
file_path = '' # fill this in with the file path pointing to wherever the sticker is located
|
|
57
|
+
file_type = '' # fill this in with the mimetype of the sticker to be uploaded
|
|
58
58
|
# allow values for file_type: sticker/aac, sticker/amr, sticker/mpeg, sticker/mp4 or sticker/ogg
|
|
59
59
|
image_id = warb_from_setup.sticker.upload(file_path: file_path, file_type: file_type)
|
|
60
60
|
# if you already have a sticker id, you can simply replace the above line with such id
|
data/examples/video.rb
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative
|
|
3
|
+
require_relative '../lib/warb'
|
|
4
4
|
|
|
5
5
|
# Configure your variables here
|
|
6
6
|
|
|
7
|
-
access_token =
|
|
8
|
-
business_id =
|
|
9
|
-
sender_id =
|
|
10
|
-
recipient_number =
|
|
7
|
+
access_token = ''
|
|
8
|
+
business_id = ''
|
|
9
|
+
sender_id = ''
|
|
10
|
+
recipient_number = ''
|
|
11
11
|
|
|
12
|
-
video_link =
|
|
12
|
+
video_link = ''
|
|
13
13
|
|
|
14
14
|
# We recommend testing one section at a time, as it can be overwhelming to see all the messages at once.
|
|
15
15
|
# So you can comment out the sections you don't want to test.
|
|
@@ -25,24 +25,24 @@ warb_from_setup = Warb.setup do |config|
|
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
# To send video using its ID, you may need to retrieve it first, which can be retrieved this way
|
|
28
|
-
file_path =
|
|
29
|
-
file_type =
|
|
28
|
+
file_path = '' # fill this in with the file path pointing to wherever the video is located
|
|
29
|
+
file_type = '' # fill this in with the mimetype of the video to be uploaded. allowed values: "video/3gpp" or "video/mp4"
|
|
30
30
|
video_id = warb_from_setup.video.upload(file_path: file_path, file_type: file_type)
|
|
31
31
|
# if you already have a video id, you can simply replace the above line with such id
|
|
32
32
|
|
|
33
33
|
warb_from_setup.video.dispatch(recipient_number, media_id: video_id)
|
|
34
|
-
warb_from_setup.video.dispatch(recipient_number, media_id: video_id, caption:
|
|
34
|
+
warb_from_setup.video.dispatch(recipient_number, media_id: video_id, caption: 'OPTIONAL - Image caption')
|
|
35
35
|
warb_from_setup.video.dispatch(recipient_number, link: video_link)
|
|
36
|
-
warb_from_setup.video.dispatch(recipient_number, link: video_link, caption:
|
|
36
|
+
warb_from_setup.video.dispatch(recipient_number, link: video_link, caption: 'OPTIONAL - Image caption')
|
|
37
37
|
|
|
38
38
|
warb_from_setup.video.dispatch(recipient_number) do |builder|
|
|
39
39
|
builder.media_id = video_id
|
|
40
|
-
builder.caption =
|
|
40
|
+
builder.caption = 'OPTIONAL - Image caption'
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
warb_from_setup.video.dispatch(recipient_number) do |builder|
|
|
44
44
|
builder.link = video_link
|
|
45
|
-
builder.caption =
|
|
45
|
+
builder.caption = 'OPTIONAL - Image caption'
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
# ############################################ #
|
|
@@ -56,24 +56,24 @@ warb_from_new = Warb.new(
|
|
|
56
56
|
)
|
|
57
57
|
|
|
58
58
|
# Same as stated above, if you need a video id, you can upload it this way
|
|
59
|
-
file_path =
|
|
60
|
-
file_type =
|
|
59
|
+
file_path = '' # fill this in with the file path pointing to wherever the video is located
|
|
60
|
+
file_type = '' # fill this in with the mimetype of the video to be uploaded. allowed values: "video/3gpp" or "video/mp4"
|
|
61
61
|
video_id = warb_from_setup.video.upload(file_path: file_path, file_type: file_type)
|
|
62
62
|
# if you already have a video id, you can simply replace the above line with such id
|
|
63
63
|
|
|
64
64
|
warb_from_new.video.dispatch(recipient_number, media_id: video_id)
|
|
65
|
-
warb_from_new.video.dispatch(recipient_number, media_id: video_id, caption:
|
|
65
|
+
warb_from_new.video.dispatch(recipient_number, media_id: video_id, caption: 'OPTIONAL - Image caption')
|
|
66
66
|
warb_from_new.video.dispatch(recipient_number, link: video_link)
|
|
67
|
-
warb_from_new.video.dispatch(recipient_number, link: video_link, caption:
|
|
67
|
+
warb_from_new.video.dispatch(recipient_number, link: video_link, caption: 'OPTIONAL - Image caption')
|
|
68
68
|
|
|
69
69
|
warb_from_new.video.dispatch(recipient_number) do |builder|
|
|
70
70
|
builder.media_id = video_id
|
|
71
|
-
builder.caption =
|
|
71
|
+
builder.caption = 'OPTIONAL - Image caption'
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
warb_from_new.video.dispatch(recipient_number) do |builder|
|
|
75
75
|
builder.link = video_link
|
|
76
|
-
builder.caption =
|
|
76
|
+
builder.caption = 'OPTIONAL - Image caption'
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
# ################################################# #
|
|
@@ -81,16 +81,16 @@ end
|
|
|
81
81
|
# ################################################# #
|
|
82
82
|
|
|
83
83
|
Warb.video.dispatch(recipient_number, media_id: video_id)
|
|
84
|
-
Warb.video.dispatch(recipient_number, media_id: video_id, caption:
|
|
84
|
+
Warb.video.dispatch(recipient_number, media_id: video_id, caption: 'OPTIONAL - Image caption')
|
|
85
85
|
Warb.video.dispatch(recipient_number, link: video_link)
|
|
86
|
-
Warb.video.dispatch(recipient_number, link: video_link, caption:
|
|
86
|
+
Warb.video.dispatch(recipient_number, link: video_link, caption: 'OPTIONAL - Image caption')
|
|
87
87
|
|
|
88
88
|
Warb.video.dispatch(recipient_number) do |builder|
|
|
89
89
|
builder.media_id = video_id
|
|
90
|
-
builder.caption =
|
|
90
|
+
builder.caption = 'OPTIONAL - Image caption'
|
|
91
91
|
end
|
|
92
92
|
|
|
93
93
|
Warb.video.dispatch(recipient_number) do |builder|
|
|
94
94
|
builder.link = video_link
|
|
95
|
-
builder.caption =
|
|
95
|
+
builder.caption = 'OPTIONAL - Image caption'
|
|
96
96
|
end
|
data/examples/webhook.rb
CHANGED
|
@@ -1,35 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'sinatra/base'
|
|
4
|
+
require 'faraday'
|
|
3
5
|
|
|
4
6
|
class Webhook < Sinatra::Base
|
|
5
7
|
configure do
|
|
6
|
-
set :bind,
|
|
8
|
+
set :bind, '0.0.0.0'
|
|
7
9
|
set :port, 3000
|
|
8
10
|
set :host_authorization, { permitted_hosts: [] }
|
|
9
11
|
end
|
|
10
12
|
|
|
11
|
-
post
|
|
13
|
+
post '/webhook' do
|
|
12
14
|
request_body = JSON.parse(request.body.read)
|
|
13
15
|
|
|
14
16
|
puts "\n🪝 Incoming webhook message: #{request_body}"
|
|
15
17
|
|
|
16
|
-
message = request_body.dig(
|
|
18
|
+
message = request_body.dig('entry', 0, 'changes', 0, 'value', 'messages', 0)
|
|
17
19
|
|
|
18
|
-
if message && message[
|
|
19
|
-
message_id = message[
|
|
20
|
+
if message && message['type'] == 'text'
|
|
21
|
+
message_id = message['id']
|
|
20
22
|
|
|
21
23
|
Warb.indicator.mark_as_read(message_id)
|
|
22
24
|
|
|
23
|
-
Warb.message.dispatch(message[
|
|
25
|
+
Warb.message.dispatch(message['from'], reply_to: message_id, message: "Echo #{message['text']['body']}")
|
|
24
26
|
|
|
25
27
|
reaction = {
|
|
26
28
|
message_id:,
|
|
27
|
-
emoji:
|
|
29
|
+
emoji: '✅'
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
Warb.reaction.dispatch(message[
|
|
31
|
-
elsif message && message[
|
|
32
|
-
message_id = message[
|
|
32
|
+
Warb.reaction.dispatch(message['from'], **reaction)
|
|
33
|
+
elsif message && message['type'] == 'location'
|
|
34
|
+
message_id = message['id']
|
|
33
35
|
|
|
34
36
|
Warb.indicator.mark_as_read(message_id)
|
|
35
37
|
|
|
@@ -40,15 +42,15 @@ class Webhook < Sinatra::Base
|
|
|
40
42
|
sleep 2
|
|
41
43
|
|
|
42
44
|
location = {
|
|
43
|
-
latitude: message[
|
|
44
|
-
longitude: message[
|
|
45
|
-
name: message[
|
|
46
|
-
address: message[
|
|
45
|
+
latitude: message['location']['latitude'],
|
|
46
|
+
longitude: message['location']['longitude'],
|
|
47
|
+
name: message['location']['name'],
|
|
48
|
+
address: message['location']['address']
|
|
47
49
|
}
|
|
48
50
|
|
|
49
|
-
Warb.location.dispatch(message[
|
|
50
|
-
elsif message && message[
|
|
51
|
-
message_id = message[
|
|
51
|
+
Warb.location.dispatch(message['from'], reply_to: message_id, **location)
|
|
52
|
+
elsif message && message['type'] == 'image'
|
|
53
|
+
message_id = message['id']
|
|
52
54
|
|
|
53
55
|
Warb.indicator.mark_as_read(message_id)
|
|
54
56
|
|
|
@@ -67,39 +69,39 @@ class Webhook < Sinatra::Base
|
|
|
67
69
|
# below, we resend the received image, using its id.
|
|
68
70
|
|
|
69
71
|
image = {
|
|
70
|
-
media_id: message[
|
|
71
|
-
link: message[
|
|
72
|
-
caption: message[
|
|
72
|
+
media_id: message['image']['id'],
|
|
73
|
+
link: message['image']['link'],
|
|
74
|
+
caption: message['image']['caption']
|
|
73
75
|
}
|
|
74
76
|
|
|
75
|
-
Warb.image.dispatch(message[
|
|
77
|
+
Warb.image.dispatch(message['from'], reply_to: message_id, **image)
|
|
76
78
|
|
|
77
79
|
# and here, we download the received image
|
|
78
80
|
Warb.image.download(media_id: image[:media_id], file_path: "#{Time.now}.jpg")
|
|
79
|
-
elsif message && message[
|
|
80
|
-
message_id = message[
|
|
81
|
+
elsif message && message['type'] == 'document'
|
|
82
|
+
message_id = message['id']
|
|
81
83
|
|
|
82
84
|
Warb.indicator.mark_as_read(message_id)
|
|
83
85
|
|
|
84
86
|
document = {
|
|
85
|
-
id: message[
|
|
86
|
-
link: message[
|
|
87
|
-
caption: message[
|
|
88
|
-
filename: message[
|
|
87
|
+
id: message['document']['id'],
|
|
88
|
+
link: message['document']['link'],
|
|
89
|
+
caption: message['document']['caption'],
|
|
90
|
+
filename: message['document']['filename']
|
|
89
91
|
}
|
|
90
92
|
|
|
91
|
-
Warb.document.dispatch(message[
|
|
92
|
-
elsif message && message[
|
|
93
|
-
message_id = message[
|
|
93
|
+
Warb.document.dispatch(message['from'], reply_to: message_id, **document)
|
|
94
|
+
elsif message && message['type'] == 'sticker'
|
|
95
|
+
message_id = message['id']
|
|
94
96
|
|
|
95
97
|
Warb.indicator.mark_as_read(message_id)
|
|
96
98
|
|
|
97
99
|
sticker = {
|
|
98
|
-
media_id: message[
|
|
99
|
-
link: message[
|
|
100
|
+
media_id: message['sticker']['id'],
|
|
101
|
+
link: message['sticker']['link']
|
|
100
102
|
}
|
|
101
103
|
|
|
102
|
-
Warb.sticker.dispatch(message[
|
|
104
|
+
Warb.sticker.dispatch(message['from'], reply_to: message_id, **sticker)
|
|
103
105
|
# you could keep adding verifications for different types of messages...
|
|
104
106
|
# elsif message && message["type"] == "image"
|
|
105
107
|
# elsif message && message["type"] == "video"
|
|
@@ -115,12 +117,12 @@ class Webhook < Sinatra::Base
|
|
|
115
117
|
# this is the endpoint which gets called to verify the server within the Meta's API
|
|
116
118
|
# you can do whatever you want here to verify your server
|
|
117
119
|
# returning the challenge value which was received as query param is enough
|
|
118
|
-
get
|
|
119
|
-
mode = params[
|
|
120
|
-
token = params[
|
|
121
|
-
challenge = params[
|
|
120
|
+
get '/webhook' do
|
|
121
|
+
mode = params['hub.mode']
|
|
122
|
+
token = params['hub.verify_token']
|
|
123
|
+
challenge = params['hub.challenge']
|
|
122
124
|
|
|
123
|
-
if mode ==
|
|
125
|
+
if mode == 'subscribe' && token == Warb.configuration.webhook_verify_token
|
|
124
126
|
status 200
|
|
125
127
|
body challenge
|
|
126
128
|
|
|
@@ -135,8 +137,8 @@ class Webhook < Sinatra::Base
|
|
|
135
137
|
private
|
|
136
138
|
|
|
137
139
|
def conn
|
|
138
|
-
@conn ||= Faraday.new(
|
|
139
|
-
conn.headers[
|
|
140
|
+
@conn ||= Faraday.new('https://graph.facebook.com/v22.0') do |conn|
|
|
141
|
+
conn.headers['Authorization'] = "Bearer #{Warb.configuration.access_token}" if Warb.configuration.access_token
|
|
140
142
|
conn.request(:json)
|
|
141
143
|
conn.response(:json)
|
|
142
144
|
end
|
data/lib/warb/client.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative
|
|
3
|
+
require_relative 'connection'
|
|
4
4
|
module Warb
|
|
5
5
|
class Client
|
|
6
6
|
include DispatcherConcern
|
|
@@ -10,6 +10,7 @@ module Warb
|
|
|
10
10
|
|
|
11
11
|
def_delegators :@configuration, :access_token, :sender_id, :business_id, :adapter, :logger
|
|
12
12
|
|
|
13
|
+
# rubocop:disable Metrics/ParameterLists
|
|
13
14
|
def initialize(configuration = nil, access_token: nil, sender_id: nil, business_id: nil,
|
|
14
15
|
adapter: nil, logger: nil)
|
|
15
16
|
@configuration = (configuration || Warb.configuration).dup
|
|
@@ -20,21 +21,22 @@ module Warb
|
|
|
20
21
|
@configuration.adapter = adapter || @configuration.adapter
|
|
21
22
|
@configuration.logger = logger || @configuration.logger
|
|
22
23
|
end
|
|
24
|
+
# rubocop:enable Metrics/ParameterLists
|
|
23
25
|
|
|
24
26
|
def get(endpoint, data = {}, **args)
|
|
25
|
-
conn.send_request(http_method:
|
|
27
|
+
conn.send_request(http_method: 'get', endpoint: endpoint, data: data, **args)
|
|
26
28
|
end
|
|
27
29
|
|
|
28
30
|
def post(endpoint, data = {}, **args)
|
|
29
|
-
conn.send_request(http_method:
|
|
31
|
+
conn.send_request(http_method: 'post', endpoint: endpoint, data: data, **args)
|
|
30
32
|
end
|
|
31
33
|
|
|
32
34
|
def put(endpoint, data = {}, **args)
|
|
33
|
-
conn.send_request(http_method:
|
|
35
|
+
conn.send_request(http_method: 'put', endpoint: endpoint, data: data, **args)
|
|
34
36
|
end
|
|
35
37
|
|
|
36
38
|
def delete(endpoint, data = {}, **args)
|
|
37
|
-
conn.send_request(http_method:
|
|
39
|
+
conn.send_request(http_method: 'delete', endpoint: endpoint, data: data, **args)
|
|
38
40
|
end
|
|
39
41
|
|
|
40
42
|
private
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Warb
|
|
2
4
|
module Components
|
|
3
5
|
class Row
|
|
@@ -24,12 +26,12 @@ module Warb
|
|
|
24
26
|
@rows = rows
|
|
25
27
|
end
|
|
26
28
|
|
|
27
|
-
def add_row(**args, &
|
|
29
|
+
def add_row(**args, &)
|
|
28
30
|
row = Row.new(**args)
|
|
29
31
|
|
|
30
32
|
@rows << row
|
|
31
33
|
|
|
32
|
-
block_given? ? row.tap(&
|
|
34
|
+
block_given? ? row.tap(&) : row
|
|
33
35
|
end
|
|
34
36
|
|
|
35
37
|
def to_h
|
|
@@ -37,7 +39,7 @@ module Warb
|
|
|
37
39
|
title: @title,
|
|
38
40
|
rows: @rows.map.with_index do |row, index|
|
|
39
41
|
row_title = row.title.slice(0, 10)
|
|
40
|
-
title = row_title.normalize.gsub(/\s/,
|
|
42
|
+
title = row_title.normalize.gsub(/\s/, '').downcase
|
|
41
43
|
id = "#{title}_#{index}"
|
|
42
44
|
|
|
43
45
|
row.to_h.merge(id: id)
|
|
@@ -54,12 +56,12 @@ module Warb
|
|
|
54
56
|
@sections = sections
|
|
55
57
|
end
|
|
56
58
|
|
|
57
|
-
def add_section(**args, &
|
|
59
|
+
def add_section(**args, &)
|
|
58
60
|
section = Section.new(**args)
|
|
59
61
|
|
|
60
62
|
@sections << section
|
|
61
63
|
|
|
62
|
-
block_given? ? section.tap(&
|
|
64
|
+
block_given? ? section.tap(&) : section
|
|
63
65
|
end
|
|
64
66
|
|
|
65
67
|
def to_h
|
|
@@ -77,14 +79,15 @@ module Warb
|
|
|
77
79
|
@buttons_texts = buttons_texts
|
|
78
80
|
end
|
|
79
81
|
|
|
82
|
+
# rubocop:disable Metrics/MethodLength
|
|
80
83
|
def to_h
|
|
81
84
|
{
|
|
82
85
|
buttons: @buttons_texts.map.with_index do |button_text, index|
|
|
83
|
-
text = button_text.normalize.gsub(/\s/,
|
|
86
|
+
text = button_text.normalize.gsub(/\s/, '').downcase
|
|
84
87
|
id = "#{text}_#{index}"
|
|
85
88
|
|
|
86
89
|
{
|
|
87
|
-
type:
|
|
90
|
+
type: 'reply',
|
|
88
91
|
reply: {
|
|
89
92
|
id: id,
|
|
90
93
|
title: button_text
|
|
@@ -93,6 +96,7 @@ module Warb
|
|
|
93
96
|
end
|
|
94
97
|
}
|
|
95
98
|
end
|
|
99
|
+
# rubocop:enable Metrics/MethodLength
|
|
96
100
|
|
|
97
101
|
def add_button_text(button_text)
|
|
98
102
|
@buttons_texts << button_text
|
|
@@ -109,7 +113,7 @@ module Warb
|
|
|
109
113
|
|
|
110
114
|
def to_h
|
|
111
115
|
{
|
|
112
|
-
name:
|
|
116
|
+
name: 'cta_url',
|
|
113
117
|
parameters: {
|
|
114
118
|
display_text: @button_text,
|
|
115
119
|
url: @url
|
|
@@ -8,12 +8,12 @@ module Warb
|
|
|
8
8
|
def initialize(**params)
|
|
9
9
|
params[:sub_type] = button_type unless params[:sub_type]
|
|
10
10
|
|
|
11
|
-
super
|
|
11
|
+
super
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def to_h
|
|
15
15
|
{
|
|
16
|
-
type:
|
|
16
|
+
type: 'button',
|
|
17
17
|
sub_type: sub_type || @params[:sub_type],
|
|
18
18
|
index: index || @params[:index]
|
|
19
19
|
}
|