warb 0.1.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 (104) 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 +135 -0
  6. data/Rakefile +12 -0
  7. data/docs/README.md +16 -0
  8. data/docs/components/README.md +24 -0
  9. data/docs/components/address.md +68 -0
  10. data/docs/components/button.md +61 -0
  11. data/docs/components/copy_code_button.md +57 -0
  12. data/docs/components/cta_action.md +13 -0
  13. data/docs/components/email.md +40 -0
  14. data/docs/components/list_action.md +29 -0
  15. data/docs/components/name.md +49 -0
  16. data/docs/components/org.md +42 -0
  17. data/docs/components/phone.md +57 -0
  18. data/docs/components/reply_button_action.md +32 -0
  19. data/docs/components/row.md +13 -0
  20. data/docs/components/section.md +30 -0
  21. data/docs/components/url.md +40 -0
  22. data/docs/components/url_button.md +57 -0
  23. data/docs/images/contact-with-wa_id.png +0 -0
  24. data/docs/images/contact-without-wa_id.png +0 -0
  25. data/docs/messages/README.md +80 -0
  26. data/docs/messages/audio.md +119 -0
  27. data/docs/messages/contact.md +134 -0
  28. data/docs/messages/document.md +122 -0
  29. data/docs/messages/flow.md +12 -0
  30. data/docs/messages/image.md +116 -0
  31. data/docs/messages/indicator.md +39 -0
  32. data/docs/messages/interactive_call_to_action_url.md +96 -0
  33. data/docs/messages/interactive_list.md +159 -0
  34. data/docs/messages/interactive_reply_button.md +67 -0
  35. data/docs/messages/location.md +34 -0
  36. data/docs/messages/location_request.md +21 -0
  37. data/docs/messages/reaction.md +23 -0
  38. data/docs/messages/sticker.md +116 -0
  39. data/docs/messages/template.md +327 -0
  40. data/docs/messages/text.md +47 -0
  41. data/docs/messages/video.md +116 -0
  42. data/docs/resources/currency.md +22 -0
  43. data/docs/resources/date_time.md +11 -0
  44. data/docs/resources/index.md +14 -0
  45. data/docs/resources/text.md +9 -0
  46. data/docs/setup.md +46 -0
  47. data/docs/webhook.md +24 -0
  48. data/examples/audio.rb +86 -0
  49. data/examples/document.rb +116 -0
  50. data/examples/image.rb +97 -0
  51. data/examples/interactive_call_to_action_url.rb +177 -0
  52. data/examples/interactive_list.rb +201 -0
  53. data/examples/interactive_reply_button.rb +174 -0
  54. data/examples/location.rb +85 -0
  55. data/examples/location_request.rb +55 -0
  56. data/examples/message.rb +61 -0
  57. data/examples/sticker.rb +86 -0
  58. data/examples/video.rb +96 -0
  59. data/examples/webhook.rb +144 -0
  60. data/lib/warb/client.rb +46 -0
  61. data/lib/warb/components/action.rb +121 -0
  62. data/lib/warb/components/address.rb +31 -0
  63. data/lib/warb/components/button.rb +29 -0
  64. data/lib/warb/components/component.rb +19 -0
  65. data/lib/warb/components/copy_code_button.rb +30 -0
  66. data/lib/warb/components/email.rb +21 -0
  67. data/lib/warb/components/name.rb +29 -0
  68. data/lib/warb/components/org.rb +23 -0
  69. data/lib/warb/components/phone.rb +23 -0
  70. data/lib/warb/components/quick_reply_button.rb +15 -0
  71. data/lib/warb/components/url.rb +21 -0
  72. data/lib/warb/components/url_button.rb +30 -0
  73. data/lib/warb/components/voice_call_button.rb +15 -0
  74. data/lib/warb/configuration.rb +13 -0
  75. data/lib/warb/connection.rb +47 -0
  76. data/lib/warb/dispatcher.rb +16 -0
  77. data/lib/warb/dispatcher_concern.rb +73 -0
  78. data/lib/warb/indicator_dispatcher.rb +31 -0
  79. data/lib/warb/language.rb +8 -0
  80. data/lib/warb/media_dispatcher.rb +46 -0
  81. data/lib/warb/resources/audio.rb +19 -0
  82. data/lib/warb/resources/contact.rb +89 -0
  83. data/lib/warb/resources/currency.rb +45 -0
  84. data/lib/warb/resources/date_time.rb +34 -0
  85. data/lib/warb/resources/document.rb +32 -0
  86. data/lib/warb/resources/flow.rb +34 -0
  87. data/lib/warb/resources/image.rb +31 -0
  88. data/lib/warb/resources/interactive_call_to_action_url.rb +48 -0
  89. data/lib/warb/resources/interactive_list.rb +36 -0
  90. data/lib/warb/resources/interactive_reply_button.rb +48 -0
  91. data/lib/warb/resources/location.rb +31 -0
  92. data/lib/warb/resources/location_request.rb +24 -0
  93. data/lib/warb/resources/reaction.rb +19 -0
  94. data/lib/warb/resources/resource.rb +59 -0
  95. data/lib/warb/resources/sticker.rb +19 -0
  96. data/lib/warb/resources/template.rb +166 -0
  97. data/lib/warb/resources/text.rb +47 -0
  98. data/lib/warb/resources/video.rb +31 -0
  99. data/lib/warb/template_dispatcher.rb +10 -0
  100. data/lib/warb/utils.rb +5 -0
  101. data/lib/warb/version.rb +5 -0
  102. data/lib/warb.rb +69 -0
  103. data/sig/warb.rbs +4 -0
  104. metadata +172 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ae3d5993ad731dab7a7aeb08130e76aff0872f4f4420680c8724613241043966
4
+ data.tar.gz: c1fa725f65ad1f69dd37abee564a9864b8cb96b224bc2e098d6ffee183fa33a6
5
+ SHA512:
6
+ metadata.gz: 30e29c7d31ea2d88bb844c1d50c727cbecf7a32d08d4eb5b6b0114a7d756eb16a103c8e4ca3e32c9532d0a834d0524e8d4d90ba536de8560bb2523dc3dd0c34a
7
+ data.tar.gz: 765c7adf8cefc2a3eb53dfacfa847f1e29ffddbfd512273a6af8ae09a8f247259b4d6f4465a3c9ea46f83621781c94fa24176c1158589b9e0bda7e9e37c6e355
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.1
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
data/CHANGELOG.md ADDED
@@ -0,0 +1,25 @@
1
+ # Changelog
2
+
3
+ ## [Unreleased]
4
+
5
+ ## [1.0.0] - 2025-07-01
6
+
7
+ ### Added
8
+ - Messages sending
9
+ - Text
10
+ - Audio
11
+ - Image
12
+ - Video
13
+ - Document
14
+ - Sticker
15
+ - Contact
16
+ - Location
17
+ - Location Request
18
+ - Interactive List
19
+ - Interactive Reply Button
20
+ - Interactive Call to Action URL
21
+ - Draft Flows
22
+ - Message builder module using blocks
23
+ - Media Uploading/Downloading
24
+ - Message Reaction
25
+ - Typing/Mark Messages as read indicators
data/README.md ADDED
@@ -0,0 +1,135 @@
1
+ # Warb
2
+
3
+ <p>
4
+ <img src="https://img.shields.io/badge/em_desenvolvimento-lightgreen?label=status"/>
5
+ <img src="https://img.shields.io/badge/0.0.0-lightgreen?label=version"/>
6
+ </p>
7
+
8
+ A Ruby Gem focused on wrap all the functionalities and use cases of the WhatsApp Business API. With Warb you can send messages, audio, images, videos, locations and so much more.
9
+
10
+ ## Installation
11
+
12
+ Add `warb` to your bundle
13
+
14
+ ```ruby
15
+ bundle add warb
16
+ ```
17
+
18
+ or add it manually to your Gemfile if you prefer.
19
+
20
+ ```ruby
21
+ gem 'warb'
22
+ ```
23
+
24
+ ## Configuration
25
+
26
+ If you don't have a **facebook developer account**, **business portfolio** and **meta app** created yet, please redirect to this [official documentation](https://developers.facebook.com/docs/whatsapp/cloud-api/get-started) to get started.
27
+
28
+ ### Rails
29
+
30
+ To use Warb in your Rails application first you will need to initialize it in `config/initializers/warb.rb`:
31
+
32
+ ```ruby
33
+ Warb.setup do |config|
34
+ config.access_token = <YOUR_WHATSAPP_BUSINESS_ACCESS_TOKEN>
35
+ config.business_id = <YOUR_WHATSAPP_BUSINESS_ID>
36
+ config.sender_id = <YOUR_WHATSAPP_BUSINESS_PHONE_ID>
37
+ config.adapter = <YOUR_ADAPTER_CHOICE> # defaults to Faraday.default_adapter (which is "":net_http" at the moment)
38
+ config.logger = <YOUR_PERSONALIZED_LOGGER> # defaults to Logger.new($stdout)
39
+ end
40
+ ```
41
+
42
+ If you would like a more direct way to use it, you can always instanciate it directly:
43
+
44
+ ```ruby
45
+ warb = Warb.new(
46
+ access_token: <YOUR_WHATSAPP_BUSINESS_ACCESS_TOKEN>,
47
+ business_id: <YOUR_WHATSAPP_BUSINESS_ID>,
48
+ sender_id: <YOUR_WHATSAPP_BUSINESS_PHONE_ID>
49
+ adapter: <YOUR_ADAPTER_CHOICE> # defaults to Faraday.default_adapter (which is "":net_http" at the moment)
50
+ logger: <YOUR_PERSONALIZED_LOGGER> # defaults to Logger.new($stdout)
51
+ )
52
+ ```
53
+
54
+ ## Usage
55
+
56
+ ### Initial Steps
57
+
58
+ Warb is simple to use — either directly from the module or via an instance.
59
+
60
+ The **first** and **second** usage modes share a common global configuration instance. The **third** mode, however, creates a new configuration instance, allowing you to define separate local configurations **based on the global configuration (if it exists)** when needed.
61
+
62
+ 1. From the Warb module:
63
+ ```ruby
64
+ Warb.message.dispatch(recipient_number, message: "Hello from warb!")
65
+ ```
66
+
67
+ 2. From the Warb instance returned from `.setup`:
68
+ ```ruby
69
+ warb = Warb.setup { |config| ... }
70
+
71
+ warb.message.dispatch(recipient_number, message: "Hello from warb!")
72
+ ```
73
+
74
+ 3. From the Warb instance return from `.new`:
75
+ ```ruby
76
+ warb = Warb.new(...)
77
+
78
+ warb.message.dispatch(recipient_number, message: "Hello from warb!")
79
+ ```
80
+
81
+ ### What more can we do?
82
+
83
+ You can also pass a block to the `dispatch` method, which look like this:
84
+
85
+ ```ruby
86
+ Warb.message.dispatch(recipient_number) do |builder|
87
+ builder.message = "Hello from warb!"
88
+ end
89
+ ```
90
+
91
+ ### What types of messages can I send?
92
+
93
+ Warb implements the main types of WhatsApp messages, you can follow the message types [`here`](docs/messages/README.md#messages-types)
94
+
95
+ examples:
96
+
97
+ ```ruby
98
+
99
+ warb = Warb.new(...)
100
+
101
+ warb.message.dispatch(...)
102
+ warb.audio.dispatch(...)
103
+ warb.video.dispatch(...)
104
+ warb.image.dispatch(...)
105
+ ...
106
+ ```
107
+
108
+ ### Find all usage examples
109
+
110
+ We suggest heading to the [`examples`](examples) directory, where you'll find documentation files with plenty of usage examples, organized by **Resources** (**Resources** are the types of messages you can send via WhatsApp using Warb).
111
+
112
+ You can also check the [`docs`](docs/README.md) for a more structured overview of the available resources and their usage.
113
+
114
+ ### Webhook Support
115
+
116
+ You might want to take action in response to messages users send. For example:
117
+
118
+ 1. A user sends a message like: “generate an image based on...”
119
+ 2. You receive the message, so you mark it as read to let the user know their request was acknowledged.
120
+ 3. Since the operation might take some time, you send a typing indicator to show that the request is being processed.
121
+
122
+ To enable this kind of flow, you’ll need to know **when** a message is received. For that, you’ll need to run your own server to listen for incoming webhook events and respond accordingly.
123
+
124
+ > ⚠️ **Note:** This gem **does not** provide built-in support for webhooks.
125
+ > However, you can look at [`examples/webhook.rb`](examples/webhook.rb) for a starting point on how to implement it. Also, check the [official documentation](https://developers.facebook.com/docs/whatsapp/cloud-api/webhooks/payload-examples) for more details if you get stuck.
126
+
127
+ ## Development
128
+
129
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
130
+
131
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
132
+
133
+ ## Contributing
134
+
135
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/warb.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/docs/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # Warb Documentation
2
+
3
+ ## Configuration
4
+ Refer to [setup](setup.md) for more details on how to configure Warb.
5
+
6
+ ## Webhook
7
+ Refer to [webhook](webhook.md) for more details on how to setup a webhook to get started.
8
+
9
+ ## Sending Messages
10
+ Refer to [messages](./messages/README.md) for more details on how to send messages using Warb.
11
+
12
+ ## Components
13
+ Refer to [components](./components/README.md) for more details on how Warb components work.
14
+
15
+ ## Resources
16
+ Refer to [resources](./resources/README.md) for more details on resources.
@@ -0,0 +1,24 @@
1
+ # Components
2
+
3
+ Components cannot be used directly, they are used in messages.
4
+
5
+ Components are used to build complex messages with multiple fields and types.
6
+
7
+ Here is a table of available components, and where they can be used:
8
+
9
+ | Component Class | Used in Message Types | Component DOC |
10
+ |---------------------------------------|---------------------------------------------------------------------------------|----------------------------------------------|
11
+ | `Warb::Components::Address` | [Contact](../messages/contact.md) | [Address](./address.md) |
12
+ | `Warb::Components::Email` | [Contact](../messages/contact.md) | [Email](./email.md) |
13
+ | `Warb::Components::Name` | [Contact](../messages/contact.md) | [Name](./name.md) |
14
+ | `Warb::Components::Phone` | [Contact](../messages/contact.md) | [Phone](./phone.md) |
15
+ | `Warb::Components::Org` | [Contact](../messages/contact.md) | [Org](./org.md) |
16
+ | `Warb::Components::URL` | [Contact](../messages/contact.md) | [URL](./url.md) |
17
+ | `Warb::Components::CTAAction` | [Interactive Call to Action URL](../messages/interactive_call_to_action_url.md) | [CTAAction](./cta_action.md) |
18
+ | `Warb::Components::ReplyButtonAction` | [Interactive Reply Button](../messages/interactive_reply_button.md) | [Reply Button Action](./reply_button_action) |
19
+ | `Warb::Components::Row` | [Interactive List](../messages/interactive_list.md) | [Row](./row.md) |
20
+ | `Warb::Components::ListAction` | [Interactive List](../messages/interactive_list.md) | [List Action](./list_action.md) |
21
+ | `Warb::Components::Section` | [Interactive List](../messages/interactive_list.md) | [Section](./section.md) |
22
+ | `Warb::Components::Button` | [Template](../messages/template.md) | [Button](./button.md) |
23
+ | `Warb::Components::UrlButton` | [Template](../messages/template.md) | [UrlButton](./url_button.md) |
24
+ | `Warb::Components::CopyCodeButton` | [Template](../messages/template.md) | [CopyCodeButton](./copy_code_button.md) |
@@ -0,0 +1,68 @@
1
+ # Address
2
+
3
+ Address, `Warb::Components::Address`, is a component used in the `Contact` message type.
4
+
5
+ It represents an address with the following fields:
6
+
7
+ |Attribute | Type | Description | Required |
8
+ |----------------|----------|-------------------------------------------------|----------|
9
+ | `street` | `String` | The street address | No |
10
+ | `city` | `String` | The city of the address | No |
11
+ | `state` | `String` | The state of the address | No |
12
+ | `zip` | `String` | The ZIP code of the address | No |
13
+ | `country` | `String` | The country of the address | No |
14
+ | `country_code` | `String` | The country code of the address | No |
15
+ | `type` | `String` | The type of the address (e.g., "HOME", "WORK" ) | No |
16
+
17
+ When using the `Warb::Components::Address` component directly, you can set these attributes in the initializer or by assigning them directly to the instance.
18
+
19
+ ```ruby
20
+ address = Warb::Components::Address.new(
21
+ street: "123 Main St",
22
+ city: "Springfield",
23
+ state: "IL",
24
+ zip: "62701",
25
+ country: "USA",
26
+ country_code: "US",
27
+ type: "HOME"
28
+ )
29
+ ```
30
+
31
+ or
32
+
33
+ ```ruby
34
+ address = Warb::Components::Address.new
35
+ address.street = "123 Main St"
36
+ address.city = "Springfield"
37
+ address.state = "IL"
38
+ address.zip = "62701"
39
+ address.country = "USA"
40
+ ```
41
+
42
+ But is better to use it in the context of a `Contact` message type, where you can add addresses using the `add_address` method:
43
+
44
+ ```ruby
45
+ Warb.contact.dispatch(recipient_number) do |contact|
46
+ # Adding an address using a block
47
+ contact.add_address do |address|
48
+ address.street = "123 Main St"
49
+ address.city = "Springfield"
50
+ address.state = "IL"
51
+ address.zip = "62701"
52
+ address.country = "USA"
53
+ address.country_code = "US"
54
+ address.type = "HOME"
55
+ end
56
+
57
+ # Adding an address with parameters
58
+ contact.add_address(
59
+ street: "456 Elm St",
60
+ city: "Shelbyville",
61
+ state: "IL",
62
+ zip: "62565",
63
+ country: "USA",
64
+ country_code: "US",
65
+ type: "WORK"
66
+ )
67
+ end
68
+ ```
@@ -0,0 +1,61 @@
1
+ # Button
2
+
3
+ `Warb::Components::Button` is a component that represents a generic button used in template messages. It's part of the Components module, which contains reusable parts of complex structures.
4
+
5
+ It represents a generic button, which can be set with the following attributes:
6
+
7
+ ## Attributes
8
+ | Attribute | Type | Required | Description |
9
+ |--------------|-----------|----------|-----------------------------------------------|
10
+ | `index` | `Integer` | Yes | An identifier or position for the button. |
11
+ | `sub_type` | `String` | Yes | A more specific classification for the button |
12
+
13
+ ## Common Button Types
14
+ | Button Type | Template Instance Method | Params |
15
+ |---------------|------------------------------|-------------------------|
16
+ | `quick_reply` | `add_quick_reply_button` | `index` |
17
+ | `voice_call` | `add_voice_call_button` | `index` |
18
+ | `url` | `add_dynamic_url_button` | `index`, `text` |
19
+ | `copy_code` | `add_copy_code_button` | `index`, `coupon_code` |
20
+
21
+ Please, refer to our [templates messaging documentation](../messages/template.md) for more info. You can check the methods to insert a button in the "Adding Buttons" section.
22
+
23
+ ## Examples
24
+
25
+ ### Quick Reply button
26
+ ```ruby
27
+ quick_reply = Warb::Components::Button.new(index: 0, sub_type: "quick_reply")
28
+ quick_reply.to_h
29
+ => {
30
+ type: "button",
31
+ sub_type: "quick_reply",
32
+ index: 0
33
+ }
34
+ ```
35
+
36
+ ### Voice Call button
37
+ ```ruby
38
+ voice_call = Warb::Components::Button.new(index: 1, sub_type: "voice_call")
39
+ voice_call.to_h
40
+ => {
41
+ type: "button",
42
+ sub_type: "voice_call",
43
+ index: 1
44
+ }
45
+ ```
46
+
47
+ ## Usage in Templates
48
+
49
+ Buttons are typically used within template messages. Here's how to add them:
50
+
51
+ ```ruby
52
+ template = Warb::Resources::Template.new(name: "my_template", language: "en_US")
53
+
54
+ # Add a quick reply button
55
+ template.add_quick_reply_button(index: 0)
56
+
57
+ # Add a voice call button
58
+ template.add_voice_call_button(index: 1)
59
+
60
+ # The buttons will be included in the template's build_payload (as components)
61
+ ```
@@ -0,0 +1,57 @@
1
+ # CopyCodeButton
2
+
3
+ `Warb::Components::CopyCodeButton` is a component used in template messages for copy code buttons.
4
+
5
+ ## Attributes
6
+ | Attribute | Type | Required | Description |
7
+ |----------------|-----------|----------|-----------------------------------------------|
8
+ | `index` | `Integer` | Yes | An identifier or position for the button. |
9
+ | `sub_type` | `String` | Yes | Always "copy_code" for this button type |
10
+ | `coupon_code` | `String` | No | The coupon code to be copied when button is pressed |
11
+
12
+ ## Examples
13
+
14
+ ### Basic copy code button
15
+ ```ruby
16
+ copy_button = Warb::Components::CopyCodeButton.new(index: 0, sub_type: "copy_code", coupon_code: "SAVE20")
17
+ copy_button.to_h
18
+ => {
19
+ type: "button",
20
+ sub_type: "copy_code",
21
+ index: 0,
22
+ parameters: [
23
+ {
24
+ type: "coupon_code",
25
+ coupon_code: "SAVE20"
26
+ }
27
+ ]
28
+ }
29
+ ```
30
+
31
+ ### Copy code button without coupon code
32
+ ```ruby
33
+ copy_button = Warb::Components::CopyCodeButton.new(index: 1, sub_type: "copy_code")
34
+ copy_button.to_h
35
+ => {
36
+ type: "button",
37
+ sub_type: "copy_code",
38
+ index: 1
39
+ }
40
+ ```
41
+
42
+ ## Usage in Templates
43
+
44
+ Copy code buttons are typically added to templates using the `add_copy_code_button` method:
45
+
46
+ ```ruby
47
+ template = Warb::Resources::Template.new(name: "my_template", language: "en_US")
48
+
49
+ # Add a copy code button
50
+ template.add_copy_code_button(index: 0, coupon_code: "SAVE20")
51
+
52
+ # Or using a block for more complex configuration
53
+ template.add_copy_code_button do |button|
54
+ button.index = 0
55
+ button.coupon_code = "SAVE20"
56
+ end
57
+ ```
@@ -0,0 +1,13 @@
1
+ # Call To Action Url Action (CTAAction)
2
+
3
+ The `CTAAction` component is used to define the action of a call to action URL message.
4
+
5
+ You don't need to create an instance of `CTAAction` manually, as the `Warb::Resources::InteractiveCalltoActionURL` resource class provides a convenient method to build it, but here are its parameters:
6
+ | Attribute | Type | Description | Required |
7
+ |---------------|----------|----------------------------------------------------------|----------|
8
+ | `url` | `String` | The URL to redirect the user when the button is clicked. | Yes |
9
+ | `button_text` | `String` | The text to display on the button. | Yes |
10
+
11
+ The `button_text` content must be, at most, 20 characters long.
12
+
13
+ See its usage in the [Interactive Call to Action URL Message](../messages/interactive_call_to_action_url.md) documentation.
@@ -0,0 +1,40 @@
1
+ # Email
2
+
3
+ Email, `Warb::Components::Email`, is a component used in the `Contact` message type.
4
+
5
+ It represents an email address with the following fields:
6
+
7
+ |Attribute | Type | Description | Required |
8
+ |----------|----------|-----------------------------------------------|----------|
9
+ | `email` | `String` | The email address | No |
10
+ | `type` | `String` | The type of the email (e.g., "HOME", "WORK" ) | No |
11
+
12
+ When using the `Warb::Components::Email` component directly, you can set these attributes in the initializer or by assigning them directly to the instance.
13
+
14
+ ```ruby
15
+ address = Warb::Components::Email.new(
16
+ email: "personal@example.com",
17
+ type: "HOME"
18
+ )
19
+ ```
20
+ or
21
+
22
+ ```ruby
23
+ address = Warb::Components::Email.new(type: "WORK")
24
+ address.email = "work@example.com"
25
+ ```
26
+
27
+ But is better to use it in the context of a `Contact` message type, where you can add emails using the `add_email` method:
28
+
29
+ ```ruby
30
+ Warb.contact.dispatch(recipient_number) do |contact|
31
+ # Adding an email using a block
32
+ contact.add_email do |email|
33
+ email.email = "work@example.com"
34
+ email.type = "WORK"
35
+ end
36
+
37
+ # Adding an email with parameters
38
+ contact.add_email(email: "home@example.com", type: "HOME")
39
+ end
40
+ ```
@@ -0,0 +1,29 @@
1
+ # Interactive List Action
2
+
3
+ The `ListAction` component is used to define the action of an interactive list message.
4
+
5
+ You don't need to create an instance of `ListAction` manually, as the `Warb::Resources::InteractiveList` resource class provides a convenient method to build it, but here are its parameters:
6
+
7
+ | Attribute | Type | Description | Required |
8
+ |---------------|----------|----------------------------------------------------------------------------------------------------------------------|----------|
9
+ | button_text | String | The text displayed on the button that the user can click to select an option from the list. | Yes |
10
+ | sections | Array | An array of [`Warb::Components::Section`](./section.md) instances, each representing a group of options in the list. | Yes |
11
+
12
+ The `ListAction` component also provides a `add_section` method to add a section to the action after its creation.
13
+
14
+ ```ruby
15
+ action = Warb::Components::ListAction.new(button_text: "Select")
16
+ section = action.add_section(title: "Languages") # returns a Warb::Components::Section instance
17
+ ```
18
+
19
+ You can also use a block with the `add_section` method to build the section, which is useful for setting its options:
20
+
21
+ ```ruby
22
+ action = Warb::Components::ListAction.new(button_text: "Select")
23
+ section = action.add_section do |section|
24
+ section.title = "Languages"
25
+ section.add_row(...) # add options here
26
+ end
27
+ ```
28
+
29
+ Check its complete usage in the [interactive list message documentation](../messages/interactive_list.md).
@@ -0,0 +1,49 @@
1
+ # Name
2
+
3
+ Name, `Warb::Components::Name`, is a component used in the `Contact` message type.
4
+
5
+ It represents a name with the following fields:
6
+
7
+ |Attribute | Type | Description | Required |
8
+ |------------------|----------|--------------------------------------------------------|----------|
9
+ | `prefix` | `String` | The prefix used to address the person | *No |
10
+ | `formatted_name` | `String` | The formatted name to be displayed in the contact info | Yes |
11
+ | `first_name` | `String` | The contact's first name | *No |
12
+ | `middle_name` | `String` | The contact's middle name | *No |
13
+ | `last_name` | `String` | The contact's last name | *No |
14
+ | `suffix` | `String` | The contact's suffix, if applicable | *No |
15
+
16
+ **Note**: At least one other attribute **must be provided** along with `formatted_name`.
17
+
18
+ When using the `Warb::Components::Name` component directly, you can set these attributes in the initializer or by assigning them directly to the instance.
19
+
20
+ ```ruby
21
+ name = Warb::Components::Name.new(
22
+ formatted_name: "John Doe",
23
+ prefix: "Mr",
24
+ first_name: "John",
25
+ last_name: "Doe"
26
+ )
27
+ ```
28
+ or
29
+
30
+ ```ruby
31
+ name = Warb::Components::Name.new
32
+ name.formatted_name = "John Doe"
33
+ name.prefix = "Mr"
34
+ name.first_name = "John"
35
+ name.last_name = "Doe"
36
+ ```
37
+
38
+ But it is better to use it in the context of a `Contact` message type, where you can build the name using the `build_name` method:
39
+
40
+ ```ruby
41
+ Warb.contact.dispatch(recipient_number) do |contact|
42
+ contact.build_name do |name|
43
+ name.formatted_name = "John Doe"
44
+ name.prefix = "Mr"
45
+ name.first_name = "John"
46
+ name.last_name = "Doe"
47
+ end
48
+ end
49
+ ```
@@ -0,0 +1,42 @@
1
+ # Org
2
+
3
+ Org, `Warb::Components::Org`, is a component used in the `Contact` message type.
4
+
5
+ It represents an Organization with the following fields:
6
+
7
+ |Attribute | Type | Description | Required |
8
+ |----------------|----------|-----------------------------------------------|----------|
9
+ | `company` | `String` | Name of the company where the contact works | No |
10
+ | `title` | `String` | Contact's job title | No |
11
+ | `department` | `String` | Department within the company | No |
12
+
13
+ When using the `Warb::Components::Org` component directly, you can set these attributes in the initializer or by assigning them directly to the instance.
14
+
15
+ ```ruby
16
+ org = Warb::Components::Org.new(
17
+ company: "Example Corp",
18
+ title: "Software Engineer",
19
+ department: "Engineering"
20
+ )
21
+ ```
22
+
23
+ or
24
+
25
+ ```ruby
26
+ org = Warb::Components::Org.new
27
+ org.company = "Example Corp"
28
+ org.title = "Software Engineer"
29
+ org.department = "Engineering"
30
+ ```
31
+
32
+ But it is better to use it in the context of a `Contact` message type, where you can build the organization using the `build_org` method:
33
+
34
+ ```ruby
35
+ Warb.contact.dispatch(recipient_number) do |contact|
36
+ contact.build_org do |org|
37
+ org.company = "Example Corp"
38
+ org.title = "Software Engineer"
39
+ org.department = "Engineering"
40
+ end
41
+ end
42
+ ```
@@ -0,0 +1,57 @@
1
+ # Phone
2
+
3
+ Phone, `Warb::Components::Phone`, is a component used in the `Contact` message type.
4
+
5
+ It represents a phone with the following fields:
6
+
7
+ |Attribute | Type | Description | Required |
8
+ |----------|----------|-----------------------------------------------|----------|
9
+ | `phone` | `String` | The phone number | No |
10
+ | `type` | `String` | The type of the phone (e.g., "HOME", "WORK" ) | No |
11
+ | `wa_id` | `String` | The WhatsApp ID associated with the phone | No |
12
+
13
+ The `wa_id` is used to identify the WhatsApp account associated with the given phone number. Generally, it is the same as the phone number, without the `+` sign.
14
+
15
+ When used, the sent message will allow the recipient to interact directly with the WhatsApp account associated with the `wa_id`:
16
+
17
+ <img src="../images/contact-with-wa_id.png" width="600">
18
+
19
+
20
+ If omitted, or without account associated to the given `wa_id`, the recipient will be able to send a WhatsApp invitation:
21
+
22
+ <img src="../images/contact-without-wa_id.png" width="600">
23
+
24
+ When using the `Warb::Components::Phone` component directly, you can set these attributes in the initializer or by assigning them directly to the instance.
25
+
26
+ ```ruby
27
+ phone = Warb::Components::Phone.new(
28
+ phone: "+1234567890",
29
+ type: "WORK",
30
+ wa_id: "1234567890"
31
+ )
32
+ ```
33
+
34
+ or
35
+
36
+ ```ruby
37
+ phone = Warb::Components::Phone.new
38
+ phone.phone = "+1234567890"
39
+ phone.type = "WORK"
40
+ phone.wa_id = "1234567890"
41
+ ```
42
+
43
+ But it is better to use it in the context of a `Contact` message type, where you can add phones using the `add_phone` method:
44
+
45
+ ```ruby
46
+ Warb.contact.dispatch(recipient_number) do |contact|
47
+ # Adding a phone using a block
48
+ contact.add_phone do |phone|
49
+ phone.phone = "+1234567890"
50
+ phone.type = "WORK"
51
+ phone.wa_id = "1234567890"
52
+ end
53
+
54
+ # Adding a phone with parameters
55
+ contact.add_phone(phone: "+0987654321", type: "HOME", wa_id: "0987654321")
56
+ end
57
+ ```