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
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Interactive Call to Action URL
|
|
2
|
+
|
|
3
|
+
An interactive call to action URL message allows you to send a message with a button that redirects the user to a specified URL when clicked.
|
|
4
|
+
|
|
5
|
+
It may seem simple, but you can set a `header`, `body`, and `footer`, along with the `url` and `button_text`.
|
|
6
|
+
|
|
7
|
+
While `body` and `footer` are simple text fields, the `header` can be a text, an image, a video or even a document.
|
|
8
|
+
|
|
9
|
+
For all that, the `interactive_call_to_action_url` dispatcher wrapper can be used to facilitate the process of sending this type of message.
|
|
10
|
+
|
|
11
|
+
You can send an interactive call to action URL message like this:
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
header = Warb::Resources::Text.new(content: "Check this out!").build_header
|
|
15
|
+
body = "body"
|
|
16
|
+
footer = "footer"
|
|
17
|
+
action = Warb::Components::CTAAction.new(url: "https://example.com", button_text: "Click here")
|
|
18
|
+
|
|
19
|
+
Warb.interactive_call_to_action_url.dispatch(recipient_number, header: header, body: body, footer: footer, action: action)
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Here, the block building strategy starts to shine. With it, you don't need to create the `header` and `action` objects manually:
|
|
23
|
+
|
|
24
|
+
```ruby
|
|
25
|
+
Warb.interactive_call_to_action_url.dispatch(recipient_number) do |message|
|
|
26
|
+
# as body and footer are simple text fields, you can set them directly
|
|
27
|
+
message.body = "body"
|
|
28
|
+
message.footer = "footer"
|
|
29
|
+
|
|
30
|
+
# for header, there's a helper method to create a text header
|
|
31
|
+
message.set_text_header("Check this out!")
|
|
32
|
+
|
|
33
|
+
# and for action, you can use the build_action method to create a CTA action`
|
|
34
|
+
message.build_action(button_text: "Click Here") do |action|
|
|
35
|
+
action.url = "https://example.com"
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Aside from the text header, you can also set an image, video, or document as header using the respective methods, `set_image_header`, `set_video_header`, and `set_document_header`.
|
|
41
|
+
|
|
42
|
+
Here is an example of using an image as header:
|
|
43
|
+
|
|
44
|
+
```ruby
|
|
45
|
+
Warb.interactive_call_to_action_url.dispatch(recipient_number) do |message|
|
|
46
|
+
message.body = "body"
|
|
47
|
+
message.footer = "footer"
|
|
48
|
+
|
|
49
|
+
# set an image as header
|
|
50
|
+
message.set_image_header(link: "https://example.com/image.jpg")
|
|
51
|
+
|
|
52
|
+
# the build_action method also returns the built action
|
|
53
|
+
action = message.build_action do |action|
|
|
54
|
+
action.url = "https://example.com"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# so you could set any attribute of the action after building it
|
|
58
|
+
action.button_text = "Click here"
|
|
59
|
+
end
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
And here is an example using a document as header:
|
|
63
|
+
|
|
64
|
+
```ruby
|
|
65
|
+
Warb.interactive_call_to_action_url.dispatch(recipient_number) do |message|
|
|
66
|
+
message.body = "body"
|
|
67
|
+
message.footer = "footer"
|
|
68
|
+
|
|
69
|
+
# set a document as header
|
|
70
|
+
# for documents, you can also pass a filename. its extension will be used to determine the MIME type
|
|
71
|
+
message.set_document_header(link: "https://example.com/document.pdf", filename: "document.pdf")
|
|
72
|
+
|
|
73
|
+
message.build_action(url: "https://example.com", button_text: "Click here")
|
|
74
|
+
end
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Here is a summary of the fields you can set in the `dispatch` method of the `interactive_call_to_action_url` message:
|
|
78
|
+
| Field | Type | Description |
|
|
79
|
+
|-----------|------------------------------------------------------------|-----------------------------------------------------------------------------------------------|
|
|
80
|
+
| `header` | Object | The header of the message, can be a text, image, video, or document. |
|
|
81
|
+
| `body` | String | The body of the message, a simple text field. |
|
|
82
|
+
| `footer` | String | The footer of the message, a simple text field. |
|
|
83
|
+
| `action` | [Warb::Components::CTAAction](../components/cta_action.md) | The action of the message, which contains the URL and button text. |
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
For header, as seen above, you can set it using the following instance methods:
|
|
87
|
+
| Method | Named Parameters | Positional Parameters | Respective Resource Class |
|
|
88
|
+
|-----------------------|--------------------|------------------------|-----------------------------|
|
|
89
|
+
| `set_text_header` | - | the content header | `Warb::Resources::Text` |
|
|
90
|
+
| `set_image_header` | `link` | - | `Warb::Resources::Image` |
|
|
91
|
+
| `set_video_header` | `link` | - | `Warb::Resources::Video` |
|
|
92
|
+
| `set_document_header` | `link`, `filename` | - | `Warb::Resources::Document` |
|
|
93
|
+
|
|
94
|
+
Under the hood, the set header methods will create the respective resource object and call its `build_header` method to prepare the header for sending.
|
|
95
|
+
|
|
96
|
+
For the action, the `build_action` instance method will create a `Warb::Components::CTAAction` and return it
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# Interactive List
|
|
2
|
+
|
|
3
|
+
**Note**: It is recommended to read the [interactive reply button message](./interactive_reply_button.md) documentation before reading this one, as it shares many similarities with the interactive list message.
|
|
4
|
+
|
|
5
|
+
An interactive list message allows you to create a list of items that the user can select from.
|
|
6
|
+
|
|
7
|
+
This is useful for scenarios where you want to present multiple options to the user and let them choose one.
|
|
8
|
+
|
|
9
|
+
After the user selects an item from the list, you can handle the selection in your application logic, such as sending a follow-up message or performing an action based on the user's choice.
|
|
10
|
+
|
|
11
|
+
For that, you need to server a webhook on your own. Check the [webhook example](../../examples/webhook.rb) for a simple implementation.
|
|
12
|
+
|
|
13
|
+
It may seem similar to the interactive reply button message, but the list message allows you to present more options and also allows the user to select an item from the list.
|
|
14
|
+
|
|
15
|
+
Based on the one provided in the [interactive reply button message](./interactive_reply_button.md) documentation, let's create a simple interactive list message, step by step.
|
|
16
|
+
|
|
17
|
+
Create the header, body, and footer of the message:
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
header = Warb::Resources::Text.new(content: "Language Selection").build_header
|
|
21
|
+
body = "Choose your preferred language"
|
|
22
|
+
footer = "You can change it latter"
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Until here, nothing new, we just created the header, body, and footer of the message as usual.
|
|
26
|
+
|
|
27
|
+
But as with the interactive reply button message, we need to create the list of items that the user can select from.
|
|
28
|
+
|
|
29
|
+
And in the same way, it is done using the corresponding `action`, which in this case, is the `Warb::Components::ListAction`.
|
|
30
|
+
|
|
31
|
+
For reply buttons, we simply instantiate the corresponding action with the available options, but for the list message, the options go inside another component.
|
|
32
|
+
|
|
33
|
+
Actually, aside from the action itself, there are two more components that we need to create: the `Warb::Components::Section` and the `Warb::Components::Row`.
|
|
34
|
+
|
|
35
|
+
Rows go inside sections, and sections go inside the action. And the available options are the rows.
|
|
36
|
+
|
|
37
|
+
Let's start with a single section:
|
|
38
|
+
```ruby
|
|
39
|
+
portuguese_row = Warb::Components::Row.new(title: "Português")
|
|
40
|
+
english_row = Warb::Components::Row.new(title: "English")
|
|
41
|
+
spanish_row = Warb::Components::Row.new(title: "Español")
|
|
42
|
+
|
|
43
|
+
section = Warb::Components::Section.new title: "Languages", rows: [portuguese_row, english_row, spanish_row]
|
|
44
|
+
|
|
45
|
+
action = Warb::Components::ListAction.new button_text: "Select", sections: [section]
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Then, with everything ready, we can send the message:
|
|
49
|
+
|
|
50
|
+
```ruby
|
|
51
|
+
Warb.interactive_list.dispatch(recipient_number, header: header, body: body, footer: footer, action: action)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Now, let's put everything together in a single code snippet:
|
|
55
|
+
|
|
56
|
+
```ruby
|
|
57
|
+
header = Warb::Resources::Text.new(content: "Language Selection").build_header
|
|
58
|
+
header = nil
|
|
59
|
+
body = "Choose your preferred language"
|
|
60
|
+
footer = "You can change it latter"
|
|
61
|
+
|
|
62
|
+
portuguese_row = Warb::Components::Row.new(title: "Português")
|
|
63
|
+
english_row = Warb::Components::Row.new(title: "English")
|
|
64
|
+
spanish_row = Warb::Components::Row.new(title: "Español")
|
|
65
|
+
|
|
66
|
+
section = Warb::Components::Section.new title: "Languages", rows: [portuguese_row, english_row, spanish_row]
|
|
67
|
+
|
|
68
|
+
action = Warb::Components::ListAction.new button_text: "Select", sections: [section]
|
|
69
|
+
|
|
70
|
+
Warb.interactive_list.dispatch(recipient_number, header: header, body: body, footer: footer, action: action)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Using the block strategy allows you to create the message in a more readable way, as shown below:
|
|
74
|
+
|
|
75
|
+
```ruby
|
|
76
|
+
Warb.interactive_list.dispatch(recipient_number) do |message|
|
|
77
|
+
message.body = "Choose your preferred language"
|
|
78
|
+
message.footer = "You can change it later"
|
|
79
|
+
|
|
80
|
+
message.set_text_header("Language Selection")
|
|
81
|
+
|
|
82
|
+
message.build_action(button_text: "Select") do |action|
|
|
83
|
+
section = action.add_section(title: nil)
|
|
84
|
+
section.add_row(title: "Português")
|
|
85
|
+
section.add_row(title: "English")
|
|
86
|
+
section.add_row(title: "Español")
|
|
87
|
+
section.add_row(title: "Français")
|
|
88
|
+
section.add_row(title: "Deutsch")
|
|
89
|
+
section.add_row(title: "Italiano")
|
|
90
|
+
section.add_row(title: "Nederlands")
|
|
91
|
+
section.add_row(title: "Русский")
|
|
92
|
+
section.add_row(title: "中文")
|
|
93
|
+
section.add_row(title: "日本語")
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
As seen above, one obvious difference from interactive list to interactive reply button is that the list message allows up to 10 options, while the reply button message allows only up to 3 options.
|
|
99
|
+
|
|
100
|
+
One other difference is that the list message only supports text headers, while the reply button message supports both text and media headers.
|
|
101
|
+
|
|
102
|
+
And one side note, is that, the section title is not required, if you're using only one section. You could omit it, it was just added to make it more readable.
|
|
103
|
+
|
|
104
|
+
Now let's see an interactive list message with multiple sections:
|
|
105
|
+
|
|
106
|
+
```ruby
|
|
107
|
+
Warb.interactive_list.dispatch(recipient_number) do |message|
|
|
108
|
+
message.body = "Choose your preferred language"
|
|
109
|
+
message.footer = "You can change it later"
|
|
110
|
+
|
|
111
|
+
message.set_text_header("Language Selection")
|
|
112
|
+
|
|
113
|
+
message.build_action(button_text: "Select") do |action|
|
|
114
|
+
action.add_section(title: "American Languages") do |american_section|
|
|
115
|
+
american_section.add_row(title: "English (USA)")
|
|
116
|
+
american_section.add_row(title: "Português (Brasil)")
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
action.add_section(title: "European Languages") do |european_section|
|
|
120
|
+
european_section.add_row(title: "English (UK)")
|
|
121
|
+
european_section.add_row(title: "Português (Portugal)")
|
|
122
|
+
european_section.add_row(title: "Français")
|
|
123
|
+
european_section.add_row(title: "Deutsch")
|
|
124
|
+
european_section.add_row(title: "Italiano")
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
action.add_section(title: "Asian Languages") do |asian_section|
|
|
128
|
+
asian_section.add_row(title: "中文 (Chinese)")
|
|
129
|
+
asian_section.add_row(title: "日本語 (Japanese)")
|
|
130
|
+
asian_section.add_row(title: "Русский (Central Asia)")
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Here, we keep the same total amount of options, but we split them into three sections, each with its own title.
|
|
137
|
+
|
|
138
|
+
And since we are using more than one section, the title for each section is required, otherwise, it would not be clear what the options are about.
|
|
139
|
+
|
|
140
|
+
Here is a table summarizing the differences between the interactive list and interactive reply button messages:
|
|
141
|
+
| Feature | Interactive List Message | Interactive Reply Button Message |
|
|
142
|
+
|-----------------------------|--------------------------|-----------------------------------|
|
|
143
|
+
| Maximum Options | 10 | 3 |
|
|
144
|
+
| Header Types | Text only | Text and Media |
|
|
145
|
+
| Section Support | Yes | No |
|
|
146
|
+
| Row Support | Yes | No |
|
|
147
|
+
| Action Type | ListAction | ReplyButtonAction |
|
|
148
|
+
| Button Text | Yes | Yes |
|
|
149
|
+
| Footer Support | Yes | Yes |
|
|
150
|
+
| Body Support | Yes | Yes |
|
|
151
|
+
| Customization | High | Medium |
|
|
152
|
+
This table summarizes the key differences between the two types of interactive messages, helping you choose the right one for your use case.
|
|
153
|
+
|
|
154
|
+
And here is a table summarizing the components used in the interactive list message:
|
|
155
|
+
| Component | Description | Named Paremeters |
|
|
156
|
+
|--------------------------------------------------------------|-----------------------------------------------------------------------------------|----------------------------------------------------------------------------------|
|
|
157
|
+
| [Warb::Components::Row](../components/row.md) | Represents a single row in the list, containing a title, and optional description | `title`, `description` |
|
|
158
|
+
| [Warb::Components::Section](../components/section.md) | Contains multiple rows, representing a section in the list | `title`, `rows` (array of `Warb::Components::Row`) |
|
|
159
|
+
| [Warb::Components::ListAction](../components/list_action.md) | Represents the action for the interactive list, containing sections and a button | `button_text`, `sections` (array of `Warb::Components::Section`) |
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Interactive Reply Button
|
|
2
|
+
|
|
3
|
+
An interactive reply button message allows you to send a message with a button that, when clicked, sends a predefined reply back.
|
|
4
|
+
|
|
5
|
+
You can send, at most, 3 buttons in a single message, which the user can select one of them to reply with.
|
|
6
|
+
|
|
7
|
+
After the user selects an item from the list, you can handle the selection in your application logic, such as sending a follow-up message or performing an action based on the user's choice.
|
|
8
|
+
|
|
9
|
+
For that, you need to server a webhook on your own. Check the [webhook example](../../examples/webhook.rb) for a simple implementation.
|
|
10
|
+
|
|
11
|
+
You can send an interactive reply button message like this:
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
header = Warb::Resources::Text.new(content: "Options").build_header
|
|
15
|
+
body = "Select a Language:"
|
|
16
|
+
footer = nil
|
|
17
|
+
action = Warb::Components::ReplyButtonAction.new(buttons_texts: ["Português", "English", "Español"])
|
|
18
|
+
|
|
19
|
+
Warb.interactive_reply_button.dispatch(recipient_number, header: header, body: body, footer: footer, action: action)
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Or you can use the block building strategy to simplify the process:
|
|
23
|
+
|
|
24
|
+
```ruby
|
|
25
|
+
Warb.interactive_reply_button.dispatch(recipient_number) do |message|
|
|
26
|
+
message.set_image_header(media_id: "1341834336894773")
|
|
27
|
+
|
|
28
|
+
message.body = "Select a Language:"
|
|
29
|
+
message.footer = nil
|
|
30
|
+
|
|
31
|
+
message.build_action do |action|
|
|
32
|
+
action.buttons_texts = ["Português", "English", "Español"]
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
or you can build the action with the buttons texts directly, passing them to the `build_action` method, without using the block:
|
|
38
|
+
|
|
39
|
+
```ruby
|
|
40
|
+
Warb.interactive_reply_button.dispatch(recipient_number, action: action) do |message|
|
|
41
|
+
message.set_text_header(content: "Options")
|
|
42
|
+
message.body = "Select a Language:"
|
|
43
|
+
message.footer = nil
|
|
44
|
+
message.build_action(buttons_texts: ["Português", "English", "Español"])
|
|
45
|
+
end
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Aside from text and image headers, you can also set a video or document as header using the respective methods, `set_video_header` and `set_document_header`.
|
|
49
|
+
|
|
50
|
+
For text header, `set_text_header` receives a string, while for image, video, and document headers, you can pass a `media_id` or a `link` to the media file.
|
|
51
|
+
For header, as seen above, you can set it using the following instance methods:
|
|
52
|
+
| Method | Named Parameters | Positional Parameters | Respective Resource Class |
|
|
53
|
+
|-----------------------|--------------------------------|------------------------|-----------------------------|
|
|
54
|
+
| `set_text_header` | - | the content header | `Warb::Resources::Text` |
|
|
55
|
+
| `set_image_header` | `link`, `media_id` | - | `Warb::Resources::Image` |
|
|
56
|
+
| `set_video_header` | `link`, `media_id` | - | `Warb::Resources::Video` |
|
|
57
|
+
| `set_document_header` | `link`, `media_id`, `filename` | - | `Warb::Resources::Document` |
|
|
58
|
+
|
|
59
|
+
Either `link` or `media_id` can be used, but not both at the same time.
|
|
60
|
+
|
|
61
|
+
If you're using a `link`, it will be used to download the media file from the provided URL, so it must not require any authentication or special headers to access the file.
|
|
62
|
+
|
|
63
|
+
If you're using a `media_id`, it must be obtained from a previous upload using the appropriate media upload method — such as `Warb.document.upload`, `Warb.image.upload`, and so on.
|
|
64
|
+
|
|
65
|
+
The `filename` for the document header is optional, but if provided, it will be used to determine the MIME type of the document.
|
|
66
|
+
|
|
67
|
+
For the `action` of the message, you can use the [`Warb::Components::ReplyButtonAction`](../components/reply_button_action.md) class to build the action with the buttons texts.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Location
|
|
2
|
+
|
|
3
|
+
The location dispatcher wrapper is used to send a location, such as a city or a point of interest.
|
|
4
|
+
|
|
5
|
+
It can include details like the name of the location, its coordinates (latitude and longitude), and an optional address.
|
|
6
|
+
|
|
7
|
+
To send a location, you can use the `dispatch` method of the `Warb.location` wrapper:
|
|
8
|
+
```ruby
|
|
9
|
+
Warb.location.dispatch(
|
|
10
|
+
recipient_number,
|
|
11
|
+
name: "Central Park",
|
|
12
|
+
latitude: 40.785091,
|
|
13
|
+
longitude: -73.968285,
|
|
14
|
+
address: "New York, NY, USA"
|
|
15
|
+
)
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
You can also use the `dispatch` method with a block to set the location details:
|
|
19
|
+
```ruby
|
|
20
|
+
Warb.location.dispatch(recipient_number) do |location|
|
|
21
|
+
location.name = "Eiffel Tower"
|
|
22
|
+
location.latitude = 48.858844
|
|
23
|
+
location.longitude = 2.294351
|
|
24
|
+
location.address = "Champ de Mars, 5 Avenue Anatole France, 75007 Paris, France"
|
|
25
|
+
end
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Here is a breakdown of the parameters you can set for the location:
|
|
29
|
+
| Attribute | Type | Description | Required |
|
|
30
|
+
|------------|----------|----------------------------------------------|----------|
|
|
31
|
+
| `name` | `String` | The name of the location | No |
|
|
32
|
+
| `latitude` | `Float` | The latitude coordinate of the location | Yes |
|
|
33
|
+
| `longitude`| `Float` | The longitude coordinate of the location | Yes |
|
|
34
|
+
| `address` | `String` | The address of the location (optional) | No |
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Location Request
|
|
2
|
+
|
|
3
|
+
Location Request Message is an interactive message. That is, the user must interect for a complete flow.
|
|
4
|
+
|
|
5
|
+
It is used to request the user's location, which can be useful for various purposes, such as finding nearby places.
|
|
6
|
+
|
|
7
|
+
When the user receives a Location Request message, they will be able to share a location by clicking on the "Share Location" button, which can be their current location or a different selected one.
|
|
8
|
+
|
|
9
|
+
Once the user shares their location, it will be sent to the webhook configured for the WhatsApp account, allowing you to process the location data as needed.
|
|
10
|
+
|
|
11
|
+
You can check our [`webhook.rb`](../../examples/webhook.rb) example to see how to handle the location request message in your application.
|
|
12
|
+
|
|
13
|
+
For more info, see the [WhatsApp documentation for Location Request](https://developers.facebook.com/docs/whatsapp/cloud-api/guides/send-messages/location-request-messages#:~:text=%2B16505551234-,Webhook%20syntax,-When%20a%20WhatsApp), in the `Webhook syntax` section.
|
|
14
|
+
|
|
15
|
+
Nevertheless, you can send a location request message like this:
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
Warb.location_request.dispatch(recipient_number, body_text: "Please share your location")
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
For Location Request messages, `body_text` is the unique parameter which can be set, is required, and is used to set the text that will be displayed in the message body.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Reaction
|
|
2
|
+
|
|
3
|
+
Reaction messages are used to send reactions to a specific message. They can be used to express emotions or feedback in response to a message.
|
|
4
|
+
|
|
5
|
+
You can send a reaction message like this:
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
Warb.reaction.dispatch(recipient_number, emoji: "✅", reply_to: "message_id")
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
`emoji` is required, is a string, and can be:
|
|
12
|
+
- any emoji supported by Android and iOS devices;
|
|
13
|
+
- rendered-emojis, such as `😀`, `🙃` or `✅`;
|
|
14
|
+
- unicode values, which must be Java- or JavaScript-escape encoded, such as `\uD83D\uDE00`;
|
|
15
|
+
- an empty string to remove a previously sent emoji.
|
|
16
|
+
|
|
17
|
+
> Since ruby doesn't support unicode escape sequences, it is easier to use rendered emojis option.
|
|
18
|
+
|
|
19
|
+
As for the `message_id`, it is the ID of the message you want to react to.
|
|
20
|
+
|
|
21
|
+
You can get this ID from the webhook payload when receiving a message.
|
|
22
|
+
|
|
23
|
+
Check our [`webhook.rb`](../../examples/webhook.rb) example to see how to react to a message in your application.
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# Sticker
|
|
2
|
+
|
|
3
|
+
For starters, not all stickers are supported by WhatsApp. Here is a table of supported stickers:
|
|
4
|
+
|
|
5
|
+
| Sticker Type | Extension | MIME Type | Max Size |
|
|
6
|
+
|-----------------|-----------|--------------|----------|
|
|
7
|
+
| WebP (static) | `.webp` | `image/webp` | 100 KB |
|
|
8
|
+
| WebP (animated) | `.webp` | `image/webp` | 500 KB |
|
|
9
|
+
|
|
10
|
+
To send a sticker message, use the `sticker` dispatch wrapper as follows:
|
|
11
|
+
|
|
12
|
+
```ruby
|
|
13
|
+
recipient_number = "..."
|
|
14
|
+
Warb.sticker.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 sticker message like this:
|
|
20
|
+
|
|
21
|
+
```ruby
|
|
22
|
+
Warb.sticker.dispatch(recipient_number, link: "https://example.com/sticker.webp")
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
You can also use the block building strategy to send a sticker message:
|
|
26
|
+
|
|
27
|
+
```ruby
|
|
28
|
+
Warb.sticker.dispatch(recipient_number) do |sticker|
|
|
29
|
+
sticker.link = "https://example.com/sticker.webp"
|
|
30
|
+
end
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
As seen above, the `link` field is used to set the sticker file URL. This must be a direct link to a file hosted online.
|
|
34
|
+
|
|
35
|
+
Also, if using a link, the sticker 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 sticker by using its ID. For that, you need to have the ID of the sticker file already uploaded to WhatsApp.
|
|
38
|
+
|
|
39
|
+
#### Upload
|
|
40
|
+
|
|
41
|
+
Since our `sticker` 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 sticker file and get its ID:
|
|
44
|
+
|
|
45
|
+
```ruby
|
|
46
|
+
sticker_id = Warb.sticker.upload(file_path: "path/to/sticker.webp", file_type: "image/webp")
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
> `file_type` must be one of the supported sticker types listed [above](#), and `file_path` is the path to the sticker file you want to upload.
|
|
50
|
+
|
|
51
|
+
**Note**: At this point, it is not possible to retrieve the ID of a sticker file that was previously uploaded, so keep the ID returned by the `upload` method for later use.
|
|
52
|
+
|
|
53
|
+
**Note**: Also, note that uploaded stickers 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 Sticker ID
|
|
56
|
+
|
|
57
|
+
With the sticker ID in hand, you can use it to send the sticker message:
|
|
58
|
+
|
|
59
|
+
```ruby
|
|
60
|
+
Warb.sticker.dispatch(recipient_number, media_id: sticker_id)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
You can also use the block building strategy to send a sticker message with an ID:
|
|
64
|
+
|
|
65
|
+
```ruby
|
|
66
|
+
Warb.sticker.dispatch(recipient_number) do |sticker|
|
|
67
|
+
sticker.media_id = sticker_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 Sticker
|
|
74
|
+
|
|
75
|
+
You can also download a sticker file using its ID:
|
|
76
|
+
|
|
77
|
+
```ruby
|
|
78
|
+
Warb.sticker.download(media_id: sticker_id, file_path: "path/to/save/sticker.webp")
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
This will download the sticker 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 sticker file you want to retrieve.
|
|
88
|
+
|
|
89
|
+
```ruby
|
|
90
|
+
Warb.sticker.retrieve(media_id: sticker_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": "image/webp",
|
|
99
|
+
"sha256": "4b4719...",
|
|
100
|
+
"file_size": 1048576,
|
|
101
|
+
"id": "134183...",
|
|
102
|
+
"messaging_product": "whatsapp"
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
#### Deleting Sticker
|
|
107
|
+
|
|
108
|
+
You can delete a sticker file using its ID:
|
|
109
|
+
|
|
110
|
+
```ruby
|
|
111
|
+
Warb.sticker.delete(sticker_id)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
This will delete the sticker 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 sticker file.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Text
|
|
2
|
+
|
|
3
|
+
Send a simple text message using the `text` wrapper:
|
|
4
|
+
|
|
5
|
+
```ruby
|
|
6
|
+
recipient_number = "..."
|
|
7
|
+
Warb.message.dispatch(recipient_number, ...)
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
**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.
|
|
11
|
+
|
|
12
|
+
You can send a simple text message like this:
|
|
13
|
+
|
|
14
|
+
```ruby
|
|
15
|
+
Warb.message.dispatch(recipient_number, content: "Hello, World!")
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
You can also use the block building strategy to send a text message:
|
|
19
|
+
|
|
20
|
+
```ruby
|
|
21
|
+
Warb.message.dispatch(recipient_number) do |text|
|
|
22
|
+
text.content = "Hey, check this out! https://www.google.com"
|
|
23
|
+
text.preview_url = true
|
|
24
|
+
end
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
> If `preview_url` is set to `true`, the recipient WhatsApp phone/computer will try to generate a preview for the URL in the content.
|
|
28
|
+
|
|
29
|
+
| Field | Type | Description | Required |
|
|
30
|
+
|---------------|---------|-----------------------------------------------------------------------------|------------------------------------------|
|
|
31
|
+
| `preview_url` | Boolean | Whether to generate a preview for URLs in the content. Defaults to `false`. | No |
|
|
32
|
+
| `content` | String | The text content of the message. | Yes * |
|
|
33
|
+
| `text` | String | The text content of the message. | Yes * |
|
|
34
|
+
| `message` | String | The text content of the message. | Yes * |
|
|
35
|
+
|
|
36
|
+
> `content`, `text`, and `message` are interchangeable, you can use any of them to set the text content of the message.
|
|
37
|
+
> But if using multiple of them, the priority is: `content` > `text` > `message`.
|
|
38
|
+
|
|
39
|
+
Also, remember that you can use `reply_to` to reply to a previous message:
|
|
40
|
+
|
|
41
|
+
```ruby
|
|
42
|
+
Warb.message.dispatch(recipient_number, content: "Hello, World!", reply_to: "message_id")
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Since text messages are the most common to be sent as replies, we're reforcing the use of `reply_to` here in the `text` wrapper. But keep in mind it can used for any other message type, like `image`, `video`, `document`, etc.
|
|
46
|
+
|
|
47
|
+
**Remember**: it is a param for the `dispatch` method, not a field of the message itself.
|