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.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +8 -0
- data/CHANGELOG.md +25 -0
- data/README.md +120 -0
- data/Rakefile +12 -0
- data/docs/README.md +13 -0
- data/docs/components/README.md +21 -0
- data/docs/components/address.md +68 -0
- data/docs/components/cta_action.md +13 -0
- data/docs/components/email.md +40 -0
- data/docs/components/list_action.md +29 -0
- data/docs/components/name.md +49 -0
- data/docs/components/org.md +42 -0
- data/docs/components/phone.md +57 -0
- data/docs/components/reply_button_action.md +32 -0
- data/docs/components/row.md +13 -0
- data/docs/components/section.md +30 -0
- data/docs/components/url.md +40 -0
- data/docs/images/contact-with-wa_id.png +0 -0
- data/docs/images/contact-without-wa_id.png +0 -0
- data/docs/messages/README.md +79 -0
- data/docs/messages/audio.md +119 -0
- data/docs/messages/contact.md +134 -0
- data/docs/messages/document.md +122 -0
- data/docs/messages/flow.md +12 -0
- data/docs/messages/image.md +116 -0
- data/docs/messages/indicator.md +39 -0
- data/docs/messages/interactive_call_to_action_url.md +96 -0
- data/docs/messages/interactive_list.md +159 -0
- data/docs/messages/interactive_reply_button.md +67 -0
- data/docs/messages/location.md +34 -0
- data/docs/messages/location_request.md +21 -0
- data/docs/messages/reaction.md +23 -0
- data/docs/messages/sticker.md +116 -0
- data/docs/messages/text.md +47 -0
- data/docs/messages/video.md +116 -0
- data/docs/setup.md +46 -0
- data/docs/webhook.md +24 -0
- data/examples/audio.rb +86 -0
- data/examples/document.rb +116 -0
- data/examples/image.rb +97 -0
- data/examples/interactive_call_to_action_url.rb +177 -0
- data/examples/interactive_list.rb +201 -0
- data/examples/interactive_reply_button.rb +174 -0
- data/examples/location.rb +85 -0
- data/examples/location_request.rb +55 -0
- data/examples/message.rb +61 -0
- data/examples/sticker.rb +86 -0
- data/examples/video.rb +96 -0
- data/examples/webhook.rb +144 -0
- data/lib/warb/client.rb +46 -0
- data/lib/warb/components/action.rb +121 -0
- data/lib/warb/components/address.rb +31 -0
- data/lib/warb/components/email.rb +21 -0
- data/lib/warb/components/name.rb +29 -0
- data/lib/warb/components/org.rb +23 -0
- data/lib/warb/components/phone.rb +23 -0
- data/lib/warb/components/url.rb +21 -0
- data/lib/warb/configuration.rb +13 -0
- data/lib/warb/connection.rb +47 -0
- data/lib/warb/dispatcher.rb +16 -0
- data/lib/warb/dispatcher_concern.rb +69 -0
- data/lib/warb/indicator_dispatcher.rb +31 -0
- data/lib/warb/media_dispatcher.rb +46 -0
- data/lib/warb/resources/audio.rb +19 -0
- data/lib/warb/resources/contact.rb +89 -0
- data/lib/warb/resources/document.rb +32 -0
- data/lib/warb/resources/flow.rb +34 -0
- data/lib/warb/resources/image.rb +31 -0
- data/lib/warb/resources/interactive_call_to_action_url.rb +48 -0
- data/lib/warb/resources/interactive_list.rb +36 -0
- data/lib/warb/resources/interactive_reply_button.rb +48 -0
- data/lib/warb/resources/location.rb +21 -0
- data/lib/warb/resources/location_request.rb +24 -0
- data/lib/warb/resources/reaction.rb +19 -0
- data/lib/warb/resources/resource.rb +51 -0
- data/lib/warb/resources/sticker.rb +19 -0
- data/lib/warb/resources/text.rb +29 -0
- data/lib/warb/resources/video.rb +31 -0
- data/lib/warb/utils.rb +5 -0
- data/lib/warb/version.rb +5 -0
- data/lib/warb.rb +58 -0
- data/sig/warb.rbs +4 -0
- metadata +153 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 58ff4cfa4904a9a820c4b5906b947b6f5dcbd3e5a3afa76a9e88ed3f83488bb8
|
|
4
|
+
data.tar.gz: 1edcbcef65fd5f128cb0cf475f4b5c6ae8e4e285a4b57335b80818e0487f874a
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 43cabbb2bcd395dbbc32eacf0f170e00c5fa913f9edbe4543b9b19f81278648ccae955ac64601182fc468ab02ae81cdb81ae1c07d4601f793dd1645cad28a698
|
|
7
|
+
data.tar.gz: f7ef031988f7c39be607047ebab9e56d627b848527fce0baa5043f1108a93e378e4e7b6d7df853240bcdba9ccb46b0c0c8ba135833fc31fbccaf01175dab9ba6
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
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,120 @@
|
|
|
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
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
|
13
|
+
|
|
14
|
+
Install the gem and add to the application's Gemfile by executing:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Configuration
|
|
27
|
+
|
|
28
|
+
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.
|
|
29
|
+
|
|
30
|
+
### Rails
|
|
31
|
+
|
|
32
|
+
To use Warb in your Rails application first you will need to initialize it in `config/initializers/warb.rb`:
|
|
33
|
+
|
|
34
|
+
```ruby
|
|
35
|
+
Warb.setup do |config|
|
|
36
|
+
config.access_token = <YOUR_WHATSAPP_BUSINESS_ACCESS_TOKEN>
|
|
37
|
+
config.business_id = <YOUR_WHATSAPP_BUSINESS_ID>
|
|
38
|
+
config.sender_id = <YOUR_WHATSAPP_BUSINESS_PHONE_ID>
|
|
39
|
+
config.adapter = <YOUR_ADAPTER_CHOICE> # defaults to Faraday.default_adapter (which is "":net_http" at the moment)
|
|
40
|
+
config.logger = <YOUR_PERSONALIZED_LOGGER> # defaults to Logger.new($stdout)
|
|
41
|
+
end
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
If you would like a more direct way to use it, you can always instanciate it directly:
|
|
45
|
+
|
|
46
|
+
```ruby
|
|
47
|
+
warb = Warb.new(
|
|
48
|
+
access_token: <YOUR_WHATSAPP_BUSINESS_ACCESS_TOKEN>,
|
|
49
|
+
business_id: <YOUR_WHATSAPP_BUSINESS_ID>,
|
|
50
|
+
sender_id: <YOUR_WHATSAPP_BUSINESS_PHONE_ID>
|
|
51
|
+
adapter: <YOUR_ADAPTER_CHOICE> # defaults to Faraday.default_adapter (which is "":net_http" at the moment)
|
|
52
|
+
logger: <YOUR_PERSONALIZED_LOGGER> # defaults to Logger.new($stdout)
|
|
53
|
+
)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Usage
|
|
57
|
+
|
|
58
|
+
### Initial Steps
|
|
59
|
+
|
|
60
|
+
Warb is simple to use — either directly from the module or via an instance.
|
|
61
|
+
|
|
62
|
+
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.
|
|
63
|
+
|
|
64
|
+
1. From the Warb module:
|
|
65
|
+
```ruby
|
|
66
|
+
Warb.message.dispatch(recipient_number, message: "Hello from warb!")
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
2. From the Warb instance returned from `.setup`:
|
|
70
|
+
```ruby
|
|
71
|
+
warb = Warb.setup { |config| ... }
|
|
72
|
+
|
|
73
|
+
warb.message.dispatch(recipient_number, message: "Hello from warb!")
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
3. From the Warb instance return from `.new`:
|
|
77
|
+
```ruby
|
|
78
|
+
warb = Warb.new(...)
|
|
79
|
+
|
|
80
|
+
warb.message.dispatch(recipient_number, message: "Hello from warb!")
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### What more can we do?
|
|
84
|
+
|
|
85
|
+
You can also pass a block to the `dispatch` method, which look like this:
|
|
86
|
+
|
|
87
|
+
```ruby
|
|
88
|
+
Warb.message.dispatch(recipient_number) do |builder|
|
|
89
|
+
builder.message = "Hello from warb!"
|
|
90
|
+
end
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Find all usage examples
|
|
94
|
+
|
|
95
|
+
We suggest heading to the `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).
|
|
96
|
+
|
|
97
|
+
You can also check the [`docs`](docs/README.md) for a more structured overview of the available resources and their usage.
|
|
98
|
+
|
|
99
|
+
### Webhook Support
|
|
100
|
+
|
|
101
|
+
You might want to take action in response to messages users send. For example:
|
|
102
|
+
|
|
103
|
+
1. A user sends a message like: “generate an image based on...”
|
|
104
|
+
2. You receive the message, so you mark it as read to let the user know their request was acknowledged.
|
|
105
|
+
3. Since the operation might take some time, you send a typing indicator to show that the request is being processed.
|
|
106
|
+
|
|
107
|
+
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.
|
|
108
|
+
|
|
109
|
+
> ⚠️ **Note:** This gem **does not** provide built-in support for webhooks.
|
|
110
|
+
> 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.
|
|
111
|
+
|
|
112
|
+
## Development
|
|
113
|
+
|
|
114
|
+
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.
|
|
115
|
+
|
|
116
|
+
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).
|
|
117
|
+
|
|
118
|
+
## Contributing
|
|
119
|
+
|
|
120
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/warb.
|
data/Rakefile
ADDED
data/docs/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
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.
|
|
@@ -0,0 +1,21 @@
|
|
|
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) |
|
|
@@ -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,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
|
+
```
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Interactive Reply Button Action
|
|
2
|
+
|
|
3
|
+
An interactive reply button action allows you to create a set of buttons that, when clicked, send a predefined reply back to the sender.
|
|
4
|
+
|
|
5
|
+
You don't need to create the buttons manually, as the `Warb::Resources::InteractiveReplyButton` class provides a convenient way to build the action with the buttons texts.
|
|
6
|
+
|
|
7
|
+
The only `parameter` possible to be set is `buttons_texts`, which is an array of strings representing the texts for each button:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
action = Warb::Components::ReplyButtonAction.new(buttons_texts: ["Português", "English", "Español"])
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
and could be used like this:
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
Warb.interactive_reply_button.dispatch(recipient_number, action: action) do |message|
|
|
17
|
+
# Set the header, body, and footer as needed
|
|
18
|
+
end
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
You can also use the `add_button_text` method to add buttons one by one:
|
|
22
|
+
|
|
23
|
+
```ruby
|
|
24
|
+
action = Warb::Components::ReplyButtonAction.new
|
|
25
|
+
action.add_button_text("Português")
|
|
26
|
+
action.add_button_text("English")
|
|
27
|
+
action.add_button_text("Español")
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Also, note that you can only add up to 3 buttons in a single action
|
|
31
|
+
|
|
32
|
+
Check the [Interactive Reply Button Message](../messages/interactive_reply_button.md) documentation for more details on how to use this action in a message.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Row
|
|
2
|
+
|
|
3
|
+
Row is a component that represents a single item in a section of an interactive list message. It is used to display an option or choice to the user.
|
|
4
|
+
|
|
5
|
+
You don't need to create a row by youself, as the `Warb::Components::Section` will handle that for you.
|
|
6
|
+
|
|
7
|
+
Here are its attributes:
|
|
8
|
+
| Attribute | Type | Required | Max Length | Description |
|
|
9
|
+
|-------------|--------|----------|------------|-----------------------------------------------------------------------------|
|
|
10
|
+
| title | String | Yes | 24 | The title of the row, which is displayed to the user |
|
|
11
|
+
| description | String | No | 72 | A brief description of the row, providing additional context or information |
|
|
12
|
+
|
|
13
|
+
Check its usage in the [section component documentation](./section.md) or a more complete guide in the [interactive list message documentation](../messages/interactive_list.md)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Section
|
|
2
|
+
|
|
3
|
+
`Warb::Components::Section` is a component that represents a group of items of an interactive list message. It is used to display multiple options, grouped under a common title.
|
|
4
|
+
|
|
5
|
+
You don't need to create a section by yourself, as the `Warb::Components::ListAction` will handle that for you.
|
|
6
|
+
|
|
7
|
+
Here are its attributes:
|
|
8
|
+
| Attribute | Type | Required | Max Length | Description |
|
|
9
|
+
|-----------|--------|----------|--------------------------------------------------------|------------------------------------------------|
|
|
10
|
+
| title | String | Yes | 24 | The title of the section |
|
|
11
|
+
| rows | Array | Yes | 10 (combining all sections within the message) | The available options the user can choose from |
|
|
12
|
+
|
|
13
|
+
The section component instance also offers a `add_row` method to add a row to the section after its creation.
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
section = Warb::Components::Section.new(title: "Languages")
|
|
17
|
+
|
|
18
|
+
section.add_row(title: "Português")
|
|
19
|
+
section.add_row(title: "English")
|
|
20
|
+
|
|
21
|
+
# or using a block
|
|
22
|
+
section.add_row do |row|
|
|
23
|
+
row.title = "Español"
|
|
24
|
+
row.description = "Spanish language"
|
|
25
|
+
end
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Under the hood, it will create a [`Warb::Components::Row`](./row.md) for each item added to the section.
|
|
29
|
+
|
|
30
|
+
Check its complete usage in the [interactive list message documentation](../messages/interactive_list.md)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# URL
|
|
2
|
+
|
|
3
|
+
URL, `Warb::Components::URL`, 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
|
+
| `url` | `String` | Website URL associated with the contact or their company | No |
|
|
10
|
+
| `type` | `String` | Type of website. For example, company, work, personal, Facebook Page, Instagram, etc | No |
|
|
11
|
+
|
|
12
|
+
When using the `Warb::Components::URL` component directly, you can set these attributes in the initializer or by assigning them directly to the instance.
|
|
13
|
+
|
|
14
|
+
```ruby
|
|
15
|
+
url = Warb::Components::URL.new(
|
|
16
|
+
url: "https://example.com",
|
|
17
|
+
type: "company"
|
|
18
|
+
)
|
|
19
|
+
```
|
|
20
|
+
or
|
|
21
|
+
|
|
22
|
+
```ruby
|
|
23
|
+
url = Warb::Components::URL.new
|
|
24
|
+
url.url = "https://example.com"
|
|
25
|
+
url.type = "company"
|
|
26
|
+
```
|
|
27
|
+
But it is better to use it in the context of a `Contact` message type, where you can build the URL using the `add_url` method:
|
|
28
|
+
|
|
29
|
+
```ruby
|
|
30
|
+
Warb.contact.dispatch(recipient_number) do |contact|
|
|
31
|
+
# Adding a URL using a block
|
|
32
|
+
contact.add_url do |url|
|
|
33
|
+
url.url = "https://example.com"
|
|
34
|
+
url.type = "company"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Adding a URL with parameters
|
|
38
|
+
contact.add_url(url: "https://personal.example.com", type: "personal")
|
|
39
|
+
end
|
|
40
|
+
```
|
|
Binary file
|
|
Binary file
|