warb 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/.rubocop.yml +8 -0
  4. data/CHANGELOG.md +25 -0
  5. data/README.md +120 -0
  6. data/Rakefile +12 -0
  7. data/docs/README.md +13 -0
  8. data/docs/components/README.md +21 -0
  9. data/docs/components/address.md +68 -0
  10. data/docs/components/cta_action.md +13 -0
  11. data/docs/components/email.md +40 -0
  12. data/docs/components/list_action.md +29 -0
  13. data/docs/components/name.md +49 -0
  14. data/docs/components/org.md +42 -0
  15. data/docs/components/phone.md +57 -0
  16. data/docs/components/reply_button_action.md +32 -0
  17. data/docs/components/row.md +13 -0
  18. data/docs/components/section.md +30 -0
  19. data/docs/components/url.md +40 -0
  20. data/docs/images/contact-with-wa_id.png +0 -0
  21. data/docs/images/contact-without-wa_id.png +0 -0
  22. data/docs/messages/README.md +79 -0
  23. data/docs/messages/audio.md +119 -0
  24. data/docs/messages/contact.md +134 -0
  25. data/docs/messages/document.md +122 -0
  26. data/docs/messages/flow.md +12 -0
  27. data/docs/messages/image.md +116 -0
  28. data/docs/messages/indicator.md +39 -0
  29. data/docs/messages/interactive_call_to_action_url.md +96 -0
  30. data/docs/messages/interactive_list.md +159 -0
  31. data/docs/messages/interactive_reply_button.md +67 -0
  32. data/docs/messages/location.md +34 -0
  33. data/docs/messages/location_request.md +21 -0
  34. data/docs/messages/reaction.md +23 -0
  35. data/docs/messages/sticker.md +116 -0
  36. data/docs/messages/text.md +47 -0
  37. data/docs/messages/video.md +116 -0
  38. data/docs/setup.md +46 -0
  39. data/docs/webhook.md +24 -0
  40. data/examples/audio.rb +86 -0
  41. data/examples/document.rb +116 -0
  42. data/examples/image.rb +97 -0
  43. data/examples/interactive_call_to_action_url.rb +177 -0
  44. data/examples/interactive_list.rb +201 -0
  45. data/examples/interactive_reply_button.rb +174 -0
  46. data/examples/location.rb +85 -0
  47. data/examples/location_request.rb +55 -0
  48. data/examples/message.rb +61 -0
  49. data/examples/sticker.rb +86 -0
  50. data/examples/video.rb +96 -0
  51. data/examples/webhook.rb +144 -0
  52. data/lib/warb/client.rb +46 -0
  53. data/lib/warb/components/action.rb +121 -0
  54. data/lib/warb/components/address.rb +31 -0
  55. data/lib/warb/components/email.rb +21 -0
  56. data/lib/warb/components/name.rb +29 -0
  57. data/lib/warb/components/org.rb +23 -0
  58. data/lib/warb/components/phone.rb +23 -0
  59. data/lib/warb/components/url.rb +21 -0
  60. data/lib/warb/configuration.rb +13 -0
  61. data/lib/warb/connection.rb +47 -0
  62. data/lib/warb/dispatcher.rb +16 -0
  63. data/lib/warb/dispatcher_concern.rb +69 -0
  64. data/lib/warb/indicator_dispatcher.rb +31 -0
  65. data/lib/warb/media_dispatcher.rb +46 -0
  66. data/lib/warb/resources/audio.rb +19 -0
  67. data/lib/warb/resources/contact.rb +89 -0
  68. data/lib/warb/resources/document.rb +32 -0
  69. data/lib/warb/resources/flow.rb +34 -0
  70. data/lib/warb/resources/image.rb +31 -0
  71. data/lib/warb/resources/interactive_call_to_action_url.rb +48 -0
  72. data/lib/warb/resources/interactive_list.rb +36 -0
  73. data/lib/warb/resources/interactive_reply_button.rb +48 -0
  74. data/lib/warb/resources/location.rb +21 -0
  75. data/lib/warb/resources/location_request.rb +24 -0
  76. data/lib/warb/resources/reaction.rb +19 -0
  77. data/lib/warb/resources/resource.rb +51 -0
  78. data/lib/warb/resources/sticker.rb +19 -0
  79. data/lib/warb/resources/text.rb +29 -0
  80. data/lib/warb/resources/video.rb +31 -0
  81. data/lib/warb/utils.rb +5 -0
  82. data/lib/warb/version.rb +5 -0
  83. data/lib/warb.rb +58 -0
  84. data/sig/warb.rbs +4 -0
  85. metadata +153 -0
@@ -0,0 +1,116 @@
1
+ # Video
2
+
3
+ For starters, not all video formats are supported by WhatsApp. Here is a table of supported video formats:
4
+
5
+ | Video Type | Extension | MIME Type | Max Size |
6
+ |------------|-----------|--------------|----------|
7
+ | MP4 | `.mp4` | `video/mp4` | 16 MB |
8
+ | 3GPP | `.3gp` | `video/3gpp` | 16 MB |
9
+
10
+ To send a video message, use the `video` dispatch wrapper as follows:
11
+
12
+ ```ruby
13
+ recipient_number = "..."
14
+ Warb.video.dispatch(recipient_number, ...)
15
+ ```
16
+
17
+ **Note**: For the examples below, take into account `Warb.setup` was called to configure the global client instance, and that the variable `recipient_number` is already set.
18
+
19
+ You can send a simple video message like this:
20
+
21
+ ```ruby
22
+ Warb.video.dispatch(recipient_number, link: "https://example.com/video.mp4")
23
+ ```
24
+
25
+ You can also use the block building strategy to send a video message:
26
+
27
+ ```ruby
28
+ Warb.video.dispatch(recipient_number) do |video|
29
+ video.link = "https://example.com/video.mp4"
30
+ end
31
+ ```
32
+
33
+ As seen above, the `link` field is used to set the video file URL. This must be a direct link to a video file hosted online.
34
+
35
+ Also, if using a link, the video file must be publicly accessible, meaning it should not require any authentication or special permissions to access.
36
+
37
+ Aside from a link, you can also send a video by using its ID. For that, you need to have the ID of the video file already uploaded to WhatsApp.
38
+
39
+ #### Upload
40
+
41
+ Since our `video` wrapper is a media dispatcher, it supports media-related operations, like `upload` and `download` methods.
42
+
43
+ So, we can use the `upload` method to upload a video file and get its ID:
44
+
45
+ ```ruby
46
+ video_id = Warb.video.upload(file_path: "path/to/video.mp4", file_type: "video/mp4")
47
+ ```
48
+
49
+ > `file_type` must be one of the supported video types listed [above](#), and `file_path` is the path to the video file you want to upload.
50
+
51
+ **Note**: At this point, it is not possible to retrieve the ID of a video file that was previously uploaded, so keep the ID returned by the `upload` method for later use.
52
+
53
+ **Note**: Also, note that uploaded videos are stored on WhatsApp servers for 30 days. After that period, they will be deleted and you won't be able to use the ID anymore.
54
+
55
+ #### Sending with Video ID
56
+
57
+ With the video ID in hand, you can use it to send the video message:
58
+
59
+ ```ruby
60
+ Warb.video.dispatch(recipient_number, media_id: video_id)
61
+ ```
62
+
63
+ You can also use the block building strategy to send a video message with an ID:
64
+
65
+ ```ruby
66
+ Warb.video.dispatch(recipient_number) do |video|
67
+ video.media_id = video_id
68
+ end
69
+ ```
70
+
71
+ **Note**: Either only one of the `link` or `media_id` fields can be set at a time.
72
+
73
+ #### Downloading Video
74
+
75
+ You can also download a video file using its ID:
76
+
77
+ ```ruby
78
+ Warb.video.download(media_id: video_id, file_path: "path/to/save/video.mp4")
79
+ ```
80
+
81
+ This will download the video file to the specified path.
82
+
83
+ Under the hood, the `download` method will use the `retrieve` method to get the download URL.
84
+
85
+ With the URL in hand, the `download` method will, in fact, download the file to the specified path.
86
+
87
+ The `retrieve` method receives a single parameter, which is the `media_id` of the video file you want to retrieve.
88
+
89
+ ```ruby
90
+ Warb.video.retrieve(media_id: video_id)
91
+ ```
92
+
93
+ And here is a sample response from the `retrieve` method:
94
+
95
+ ```json
96
+ {
97
+ "url": "https://lookaside.fbsbx.com/...",
98
+ "mime_type": "video/mp4",
99
+ "sha256": "4b4719...",
100
+ "file_size": 1048576,
101
+ "id": "134183...",
102
+ "messaging_product": "whatsapp"
103
+ }
104
+ ```
105
+
106
+ #### Deleting Video
107
+
108
+ You can delete a video file using its ID:
109
+
110
+ ```ruby
111
+ Warb.video.delete(video_id)
112
+ ```
113
+
114
+ This will delete the video file from WhatsApp servers and return `true` on success.
115
+
116
+ This is useful if you want to free up space or if you no longer need the video file.
data/docs/setup.md ADDED
@@ -0,0 +1,46 @@
1
+ # Setup
2
+
3
+ ## Global
4
+ You can configure `Warb` globally as follow:
5
+
6
+ ```ruby
7
+ Warb.setup do |config|
8
+ config.access_token = "access_token"
9
+ config.sender_id = "sender_id"
10
+ end
11
+ ```
12
+
13
+ This way, every time you use any method from Warb, like `Warb.message` or `Warb.audio`, the global configuration is going to be used automatically.
14
+
15
+ So if you're running a Rails Application, you can put this code in an initializer file, like `config/initializers/warb.rb`.
16
+
17
+ If you're not using Rails, you can put it in your main application file, like `app.rb` or `main.rb`.
18
+
19
+
20
+ ## Local
21
+
22
+ Instead of using the global configuration, you might want to use a different configuration for a specific task. In such cases, it's possible to instatiate a client directly using `Warb.new`:
23
+
24
+ ```ruby
25
+ client = Warb.new(access_token: "access_token", sender_id: "sender_id")
26
+ client.message.dispatch(...)
27
+ ```
28
+
29
+ Also, it is possible to reuse the global configuration but override some of the parameters, like `sender_id`:
30
+
31
+ ```ruby
32
+ client = Warb.new(sender_id: "another_id")
33
+ # This client will use the global `access_token` but a different `sender_id`
34
+ client.message.dispatch(...)
35
+ ```
36
+
37
+ Aside from the `access_token` and `sender_id`, you can also pass any other parameter that is supported by the `Warb::Client` class, a logger, or a custom HTTP client.
38
+
39
+ ```ruby
40
+ Warb.setup do |config|
41
+ config.logger = Logger.new($stdout) # or any other logger you prefer
42
+ config.adapter = :net_http # or any other HTTP client adapter you prefer
43
+ end
44
+ ```
45
+
46
+ Also, note that calling `Warb.setup` multiple times **WILL NOT** override the previous configuration, so you can use it to change the global configuration at any time.
data/docs/webhook.md ADDED
@@ -0,0 +1,24 @@
1
+ # Webhook
2
+
3
+ You need to setup a webhook to receive messages from WhatsApp. The webhook is a URL that WhatsApp will call whenever there is an event related to your WhatsApp Business Account, such as receiving a message or a status update.
4
+
5
+ Such status or updates include:
6
+ - New Messages
7
+ - Message delivery status
8
+ - Message read status
9
+ - Message reaction
10
+ - Message template status
11
+ - Message interactive list response
12
+ - Message interactive reply button response
13
+ - Errors responses
14
+
15
+ To set up a webhook, follow these steps:
16
+ 1. **Create a Webhook URL**: This is the URL that WhatsApp will call to send you updates. It should be publicly accessible and able to handle POST requests.
17
+ 2. **Configure the Webhook in WhatsApp**: Go to your WhatsApp Business Account settings and configure the webhook URL. You will need to provide the URL and select the events you want to receive.
18
+ 3. **Handle Incoming Webhook Requests**: In your application, you need to create an endpoint that can handle incoming POST requests from WhatsApp. This endpoint should parse the incoming data and respond with a 200 OK status to acknowledge receipt of the message.
19
+ 4. **Verify the Webhook**: WhatsApp will send a verification request to your webhook URL. You need to respond with the `hub.challenge` parameter to verify that you own the webhook URL.
20
+ 5. **Test the Webhook**: Send a test message to your WhatsApp Business Account to ensure that your webhook is working correctly and that you are receiving updates as expected.
21
+
22
+ After configuring the webhook in the WhatsApp Business Account settings, for a quick start, you can refer to [webhook.rb example](../examples/webhook.rb) to see how to handle incoming webhook requests in your application.
23
+
24
+ Or you can refer to the official [Webhook Setup](https://developers.facebook.com/docs/whatsapp/cloud-api/guides/set-up-webhooks) or [Webhook payload structure](https://developers.facebook.com/docs/whatsapp/cloud-api/webhooks/components) for more details.
data/examples/audio.rb ADDED
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../lib/warb"
4
+
5
+ # Configure your variables here
6
+
7
+ access_token = ""
8
+ business_id = ""
9
+ sender_id = ""
10
+ recipient_number = ""
11
+
12
+ audio_link = ""
13
+
14
+ # We recommend testing one section at a time, as it can be overwhelming to see all the messages at once.
15
+ # So you can comment out the sections you don't want to test.
16
+
17
+ # ############################################## #
18
+ # ============== Using Warb.setup ============== #
19
+ # ############################################## #
20
+
21
+ warb_from_setup = Warb.setup do |config|
22
+ config.access_token = access_token
23
+ config.business_id = business_id
24
+ config.sender_id = sender_id
25
+ end
26
+
27
+ # To send audio using its ID, you may need to retrieve it first, which can be retrieved this way
28
+ file_path = "" # fill this in with the file path pointing to wherever the audio is located
29
+ file_type = "" # fill this in with the mimetype of the audio to be uploaded
30
+ # allow values for file_type: audio/aac, audio/amr, audio/mpeg, audio/mp4 or audio/ogg
31
+ audio_id = warb_from_setup.audio.upload(file_path: file_path, file_type: file_type)
32
+ # if you already have an audio id, you can simply replace the above line with such id
33
+
34
+ warb_from_setup.audio.dispatch(recipient_number, media_id: audio_id)
35
+ warb_from_setup.audio.dispatch(recipient_number, link: audio_link)
36
+
37
+ warb_from_setup.audio.dispatch(recipient_number) do |builder|
38
+ builder.media_id = audio_id
39
+ end
40
+
41
+ warb_from_setup.audio.dispatch(recipient_number) do |builder|
42
+ builder.link = audio_link
43
+ end
44
+
45
+ # ############################################ #
46
+ # ============== Using Warb.new ============== #
47
+ # ############################################ #
48
+
49
+ warb_from_new = Warb.new(
50
+ access_token: access_token,
51
+ business_id: business_id,
52
+ sender_id: sender_id
53
+ )
54
+
55
+ # Same as stated above, if you need an audio id, you can upload it this way
56
+ file_path = "" # fill this in with the file path pointing to wherever the audio is located
57
+ file_type = "" # fill this in with the mimetype of the audio to be uploaded
58
+ # allow values for file_type: audio/aac, audio/amr, audio/mpeg, audio/mp4 or audio/ogg
59
+ audio_id = warb_from_setup.audio.upload(file_path: file_path, file_type: file_type)
60
+ # if you already have an audio id, you can simply replace the above line with such id
61
+
62
+ warb_from_new.audio.dispatch(recipient_number, media_id: audio_id)
63
+ warb_from_new.audio.dispatch(recipient_number, link: audio_link)
64
+
65
+ warb_from_new.audio.dispatch(recipient_number) do |builder|
66
+ builder.media_id = audio_id
67
+ end
68
+
69
+ warb_from_new.audio.dispatch(recipient_number) do |builder|
70
+ builder.link = audio_link
71
+ end
72
+
73
+ # ################################################# #
74
+ # ============== Using Warb directly ============== #
75
+ # ################################################# #
76
+
77
+ Warb.audio.dispatch(recipient_number, media_id: audio_id)
78
+ Warb.audio.dispatch(recipient_number, link: audio_link)
79
+
80
+ Warb.audio.dispatch(recipient_number) do |builder|
81
+ builder.media_id = audio_id
82
+ end
83
+
84
+ Warb.audio.dispatch(recipient_number) do |builder|
85
+ builder.link = audio_link
86
+ end
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../lib/warb"
4
+
5
+ # Configure your variables here
6
+
7
+ access_token = ""
8
+ business_id = ""
9
+ sender_id = ""
10
+ recipient_number = ""
11
+
12
+ document_link = ""
13
+
14
+ # We recommend testing one section at a time, as it can be overwhelming to see all the messages at once.
15
+ # So you can comment out the sections you don't want to test.
16
+
17
+ # ############################################## #
18
+ # ============== Using Warb.setup ============== #
19
+ # ############################################## #
20
+
21
+ warb_from_setup = Warb.setup do |config|
22
+ config.access_token = access_token
23
+ config.business_id = business_id
24
+ config.sender_id = sender_id
25
+ end
26
+
27
+ # To send document using its ID, you may need to retrieve it first, which can be retrieved this way
28
+ file_path = "" # fill this in with the file path pointing to wherever the document is located
29
+ file_type = "" # fill this in with the mimetype of the document to be uploaded
30
+ # allow values for file_type:
31
+ # text/plain, application/vnd.ms-excel, application/msword
32
+ # application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-powerpoint,
33
+ # application/vnd.openxmlformats-officedocument.presentationml.presentation or application/pdf
34
+ document_id = warb_from_setup.document.upload(file_path: file_path, file_type: file_type)
35
+ # if you already have a document id, you can simply replace the above line with such id
36
+
37
+ warb_from_setup.document.dispatch(recipient_number, media_id: document_id)
38
+ warb_from_setup.document.dispatch(recipient_number, media_id: document_id, filename: "optional_name.pdf")
39
+ warb_from_setup.document.dispatch(recipient_number, media_id: document_id, caption: "OPTIONAL - Document caption")
40
+ warb_from_setup.document.dispatch(recipient_number, link: document_link)
41
+ warb_from_setup.document.dispatch(recipient_number, link: document_link, filename: "optional_name.pdf")
42
+ warb_from_setup.document.dispatch(recipient_number, link: document_link, caption: "OPTIONAL - Document caption")
43
+
44
+ warb_from_setup.document.dispatch(recipient_number) do |builder|
45
+ builder.media_id = document_id
46
+ builder.filename = "optional_name.pdf"
47
+ builder.caption = "OPTIONAL - Document caption"
48
+ end
49
+
50
+ warb_from_setup.document.dispatch(recipient_number) do |builder|
51
+ builder.link = document_link
52
+ builder.filename = "optional_name.pdf"
53
+ builder.caption = "OPTIONAL - Document caption"
54
+ end
55
+
56
+ # ############################################ #
57
+ # ============== Using Warb.new ============== #
58
+ # ############################################ #
59
+
60
+ warb_from_new = Warb.new(
61
+ access_token: access_token,
62
+ business_id: business_id,
63
+ sender_id: sender_id
64
+ )
65
+
66
+ # Same as stated above, if you need a document id, you can upload it this way
67
+ file_path = "" # fill this in with the file path pointing to wherever the document is located
68
+ file_type = "" # fill this in with the mimetype of the document to be uploaded
69
+ # allow values for file_type:
70
+ # text/plain, application/vnd.ms-excel, application/msword
71
+ # application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-powerpoint,
72
+ # application/vnd.openxmlformats-officedocument.presentationml.presentation or application/pdf
73
+ document_id = warb_from_setup.document.upload(file_path: file_path, file_type: file_type)
74
+ # if you already have a document id, you can simply replace the above line with such id
75
+
76
+ warb_from_new.document.dispatch(recipient_number, media_id: document_id)
77
+ warb_from_new.document.dispatch(recipient_number, media_id: document_id, filename: "optional_name.pdf")
78
+ warb_from_new.document.dispatch(recipient_number, media_id: document_id, caption: "OPTIONAL - Document caption")
79
+ warb_from_new.document.dispatch(recipient_number, link: document_link)
80
+ warb_from_new.document.dispatch(recipient_number, link: document_link, filename: "optional_name.pdf")
81
+ warb_from_new.document.dispatch(recipient_number, link: document_link, caption: "OPTIONAL - Document caption")
82
+
83
+ warb_from_new.document.dispatch(recipient_number) do |builder|
84
+ builder.media_id = document_id
85
+ builder.filename = "optional_name.pdf"
86
+ builder.caption = "OPTIONAL - Document caption"
87
+ end
88
+
89
+ warb_from_new.document.dispatch(recipient_number) do |builder|
90
+ builder.link = document_link
91
+ builder.filename = "optional_name.pdf"
92
+ builder.caption = "OPTIONAL - Document caption"
93
+ end
94
+
95
+ # ################################################# #
96
+ # ============== Using Warb directly ============== #
97
+ # ################################################# #
98
+
99
+ Warb.document.dispatch(recipient_number, media_id: document_id)
100
+ Warb.document.dispatch(recipient_number, media_id: document_id, filename: "optional_name.pdf")
101
+ Warb.document.dispatch(recipient_number, media_id: document_id, caption: "OPTIONAL - Document caption")
102
+ Warb.document.dispatch(recipient_number, link: document_link)
103
+ Warb.document.dispatch(recipient_number, link: document_link, filename: "optional_name.pdf")
104
+ Warb.document.dispatch(recipient_number, link: document_link, caption: "OPTIONAL - Document caption")
105
+
106
+ Warb.document.dispatch(recipient_number) do |builder|
107
+ builder.media_id = document_id
108
+ builder.filename = "optional_name.pdf"
109
+ builder.caption = "OPTIONAL - Document caption"
110
+ end
111
+
112
+ Warb.document.dispatch(recipient_number) do |builder|
113
+ builder.link = document_link
114
+ builder.filename = "optional_name.pdf"
115
+ builder.caption = "OPTIONAL - Document caption"
116
+ end
data/examples/image.rb ADDED
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../lib/warb"
4
+
5
+ # Configure your variables here
6
+
7
+ access_token = ""
8
+ business_id = ""
9
+ sender_id = ""
10
+ recipient_number = ""
11
+
12
+ image_link = ""
13
+
14
+ # We recommend testing one section at a time, as it can be overwhelming to see all the messages at once.
15
+ # So you can comment out the sections you don't want to test.
16
+
17
+ # ############################################## #
18
+ # ============== Using Warb.setup ============== #
19
+ # ############################################## #
20
+
21
+ warb_from_setup = Warb.setup do |config|
22
+ config.access_token = access_token
23
+ config.business_id = business_id
24
+ config.sender_id = sender_id
25
+ end
26
+
27
+ warb_from_setup.image.dispatch(recipient_number, link: image_link)
28
+ warb_from_setup.image.dispatch(recipient_number, link: image_link, caption: "OPTIONAL - Image caption")
29
+
30
+ # To send image using its ID, you may need to retrieve it first, which can be retrieved this way
31
+ file_path = "" # fill this in with the file path pointing to wherever the image is located
32
+ file_type = "" # fill this in with the mimetype of the image to be uploaded. allowed values: "image/jpeg" or "image/png"
33
+ image_id = warb_from_setup.image.upload(file_path: file_path, file_type: file_type)
34
+ # if you already have an image id, you can simply replace the above line with such id
35
+
36
+ warb_from_setup.image.dispatch(recipient_number, media_id: image_id)
37
+ warb_from_setup.image.dispatch(recipient_number, media_id: image_id, caption: "OPTIONAL - Image caption")
38
+
39
+ warb_from_setup.image.dispatch(recipient_number) do |builder|
40
+ builder.media_id = image_id
41
+ builder.caption = "OPTIONAL - Image caption"
42
+ end
43
+
44
+ warb_from_setup.image.dispatch(recipient_number) do |builder|
45
+ builder.link = image_link
46
+ builder.caption = "OPTIONAL - Image caption"
47
+ end
48
+
49
+ # ############################################ #
50
+ # ============== Using Warb.new ============== #
51
+ # ############################################ #
52
+
53
+ warb_from_new = Warb.new(
54
+ access_token: access_token,
55
+ business_id: business_id,
56
+ sender_id: sender_id
57
+ )
58
+
59
+ # Same as stated above, if you need an image id, you can upload it this way
60
+ file_path = "" # fill this in with the file path pointing to wherever the image is located
61
+ file_type = "" # fill this in with the mimetype of the image to be uploaded. allowed values: "image/jpeg" or "image/png"
62
+ image_id = warb_from_new.image.upload(file_path: file_path, file_type: file_type)
63
+ # if you already have an image id, you can simply replace the above line with such id
64
+
65
+ warb_from_new.image.dispatch(recipient_number, media_id: image_id)
66
+ warb_from_new.image.dispatch(recipient_number, media_id: image_id, caption: "OPTIONAL - Image caption")
67
+ warb_from_new.image.dispatch(recipient_number, link: image_link)
68
+ warb_from_new.image.dispatch(recipient_number, link: image_link, caption: "OPTIONAL - Image caption")
69
+
70
+ warb_from_new.image.dispatch(recipient_number) do |builder|
71
+ builder.media_id = image_id
72
+ builder.caption = "OPTIONAL - Image caption"
73
+ end
74
+
75
+ warb_from_new.image.dispatch(recipient_number) do |builder|
76
+ builder.link = image_link
77
+ builder.caption = "OPTIONAL - Image caption"
78
+ end
79
+
80
+ # ################################################# #
81
+ # ============== Using Warb directly ============== #
82
+ # ################################################# #
83
+
84
+ Warb.image.dispatch(recipient_number, media_id: image_id)
85
+ Warb.image.dispatch(recipient_number, media_id: image_id, caption: "OPTIONAL - Image caption")
86
+ Warb.image.dispatch(recipient_number, link: image_link)
87
+ Warb.image.dispatch(recipient_number, link: image_link, caption: "OPTIONAL - Image caption")
88
+
89
+ Warb.image.dispatch(recipient_number) do |builder|
90
+ builder.media_id = image_id
91
+ builder.caption = "OPTIONAL - Image caption"
92
+ end
93
+
94
+ Warb.image.dispatch(recipient_number) do |builder|
95
+ builder.link = image_link
96
+ builder.caption = "OPTIONAL - Image caption"
97
+ end
@@ -0,0 +1,177 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../lib/warb"
4
+
5
+ # Configure your variables here
6
+
7
+ access_token = ""
8
+ business_id = ""
9
+ sender_id = ""
10
+ recipient_number = ""
11
+
12
+ # You can use Resources to create headers for your messages.
13
+ text_header = Warb::Resources::Text.as_header("OPTIONAL - Header")
14
+ image_header = Warb::Resources::Image.as_header(media_id: image_id)
15
+ video_header = Warb::Resources::Video.as_header(link: image_url)
16
+
17
+ # You can use Action Components to create actions for your messages.
18
+ action_component = Warb::Components::CTAAction.new(button_text: "Action button text", url: "https://www.rebase.com.br")
19
+
20
+ # We recommend testing one section at a time, as it can be overwhelming to see all the messages at once.
21
+ # So you can comment out the sections you don't want to test.
22
+
23
+ # ############################################## #
24
+ # ============== Using Warb.setup ============== #
25
+ # ############################################## #
26
+
27
+ warb_from_setup = Warb.setup do |config|
28
+ config.access_token = access_token
29
+ config.business_id = business_id
30
+ config.sender_id = sender_id
31
+ end
32
+
33
+ warb_from_setup.interactive_call_to_action_url.dispatch(
34
+ recipient_number,
35
+ header: text_header,
36
+ body: "body",
37
+ footer: "footer",
38
+ action: action_component
39
+ )
40
+
41
+ warb_from_setup.interactive_call_to_action_url.dispatch(
42
+ recipient_number,
43
+ header: image_header,
44
+ body: "body",
45
+ footer: "footer",
46
+ action: action_component
47
+ )
48
+
49
+ warb_from_setup.interactive_call_to_action_url.dispatch(
50
+ recipient_number,
51
+ header: video_header,
52
+ body: "body",
53
+ footer: "footer",
54
+ action: action_component
55
+ )
56
+
57
+ warb_from_setup.interactive_call_to_action_url.dispatch(recipient_number) do |builder|
58
+ # OPTIONAL Headers: you can choose between text, image, or video headers.
59
+
60
+ builder.set_text_header("Text Header")
61
+
62
+ # If you want to use an image header, uncomment the line below and provide a valid or Media ID or Link.
63
+ # builder.set_image_header(media_id: image_id) # or builder.set_image_header(link: image_link)
64
+
65
+ # If you want to use a video header, uncomment the line below and provide a valid Media ID or Link.
66
+ # builder.set_video_header(media_id: video_id) # or builder.set_video_header(link: video_link)
67
+
68
+ builder.body = "body"
69
+ builder.footer = "footer"
70
+
71
+ builder.build_action do |action|
72
+ action.button_text = "Action Button Text"
73
+ action.url = "https://www.rebase.com.br"
74
+ end
75
+ end
76
+
77
+ # ############################################ #
78
+ # ============== Using Warb.new ============== #
79
+ # ############################################ #
80
+
81
+ warb_from_new = Warb.new(
82
+ access_token: access_token,
83
+ business_id: business_id,
84
+ sender_id: sender_id
85
+ )
86
+
87
+ warb_from_new.interactive_call_to_action_url.dispatch(
88
+ recipient_number,
89
+ header: text_header,
90
+ body: "body",
91
+ footer: "footer",
92
+ action: action_component
93
+ )
94
+
95
+ warb_from_new.interactive_call_to_action_url.dispatch(
96
+ recipient_number,
97
+ header: image_header,
98
+ body: "body",
99
+ footer: "footer",
100
+ action: action_component
101
+ )
102
+
103
+ warb_from_new.interactive_call_to_action_url.dispatch(
104
+ recipient_number,
105
+ header: video_header,
106
+ body: "body",
107
+ footer: "footer",
108
+ action: action_component
109
+ )
110
+
111
+ warb_from_new.interactive_call_to_action_url.dispatch(recipient_number) do |builder|
112
+ # Headers: you can choose between text, image, or video headers.
113
+
114
+ builder.set_text_header("Text Header")
115
+
116
+ # If you want to use an image header, uncomment the line below and provide a valid or Media ID or Link.
117
+ # builder.set_image_header(media_id: image_id) # or builder.set_image_header(link: image_link)
118
+
119
+ # If you want to use a video header, uncomment the line below and provide a valid Media ID or Link.
120
+ # builder.set_video_header(media_id: video_id) # or builder.set_video_header(link: video_link)
121
+
122
+ builder.body = "body"
123
+ builder.footer = "footer"
124
+
125
+ builder.build_action do |action|
126
+ action.button_text = "Action Button Text"
127
+ action.url = "https://www.rebase.com.br"
128
+ end
129
+ end
130
+
131
+ # ################################################# #
132
+ # ============== Using Warb directly ============== #
133
+ # ################################################# #
134
+
135
+ Warb.interactive_call_to_action_url.dispatch(
136
+ recipient_number,
137
+ header: text_header,
138
+ body: "body",
139
+ footer: "footer",
140
+ action: action_component
141
+ )
142
+
143
+ Warb.interactive_call_to_action_url.dispatch(
144
+ recipient_number,
145
+ header: image_header,
146
+ body: "body",
147
+ footer: "footer",
148
+ action: action_component
149
+ )
150
+
151
+ Warb.interactive_call_to_action_url.dispatch(
152
+ recipient_number,
153
+ header: video_header,
154
+ body: "body",
155
+ footer: "footer",
156
+ action: action_component
157
+ )
158
+
159
+ Warb.interactive_call_to_action_url.dispatch(recipient_number) do |builder|
160
+ # Headers: you can choose between text, image, or video headers.
161
+
162
+ builder.set_text_header("Text Header")
163
+
164
+ # If you want to use an image header, uncomment the line below and provide a valid or Media ID or Link.
165
+ # builder.set_image_header(media_id: image_id) # or builder.set_image_header(link: image_link)
166
+
167
+ # If you want to use a video header, uncomment the line below and provide a valid Media ID or Link.
168
+ # builder.set_video_header(media_id: video_id) # or builder.set_video_header(link: video_link)
169
+
170
+ builder.body = "body"
171
+ builder.footer = "footer"
172
+
173
+ builder.build_action do |action|
174
+ action.button_text = "Action Button Text"
175
+ action.url = "https://www.rebase.com.br"
176
+ end
177
+ end