whatsapp_sdk 0.2.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.md +21 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +14 -0
- data/.github/workflows/codeql-analysis.yml +72 -0
- data/.rubocop.yml +7 -0
- data/CHANGELOG.md +9 -1
- data/Gemfile +5 -2
- data/Gemfile.lock +18 -8
- data/README.md +43 -17
- data/example.rb +92 -77
- data/lib/version.rb +1 -1
- data/lib/whatsapp_sdk/api/request.rb +2 -2
- data/lib/whatsapp_sdk/configuration.rb +23 -0
- data/lib/whatsapp_sdk.rb +13 -31
- data/whatsapp_sdk.gemspec +10 -7
- metadata +31 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21f67768ad0e420df08a3ba0046968b6576e4d60bf0f601d902c968d3cfa9a29
|
4
|
+
data.tar.gz: 1db186a1de042f4da848587a9c4fd366b52ca28111de7fff63ae93ef776e98d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 933a7f3caa079cb0e551bbb772516c3ab03f0f57bb97ef05934acad663ef600cacfcf1ff0b65c65b87596df2424aaa3e6f293134f9ddce9a55d0bfd0dcb833cd
|
7
|
+
data.tar.gz: 429575992b1728097f53daba070ad74e4622f4ae8e21c73e40ecf06947b8c9697e5fd0272ab105f10f7cb9e023ff2dc2574f6268d5a34b318d7b422fe95c51a5
|
@@ -0,0 +1,21 @@
|
|
1
|
+
---
|
2
|
+
name: Bug report
|
3
|
+
about: Create a report to help us improve
|
4
|
+
title: ''
|
5
|
+
labels: ''
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
**Describe the bug**
|
11
|
+
A clear and concise description of what the bug is.
|
12
|
+
|
13
|
+
**To Reproduce**
|
14
|
+
Steps to reproduce the behavior:
|
15
|
+
1. Go to '...'
|
16
|
+
|
17
|
+
**Expected behavior**
|
18
|
+
A clear and concise description of what you expected to happen.
|
19
|
+
|
20
|
+
**Additional context**
|
21
|
+
Add any other context about the problem here.
|
@@ -0,0 +1,14 @@
|
|
1
|
+
---
|
2
|
+
name: Feature request
|
3
|
+
about: Suggest an idea for this project
|
4
|
+
title: ''
|
5
|
+
labels: ''
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
**Is your feature request related to a problem? Please describe.**
|
11
|
+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
12
|
+
|
13
|
+
**Additional context**
|
14
|
+
Add any other context or screenshots about the feature request here.
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# For most projects, this workflow file will not need changing; you simply need
|
2
|
+
# to commit it to your repository.
|
3
|
+
#
|
4
|
+
# You may wish to alter this file to override the set of languages analyzed,
|
5
|
+
# or to provide custom queries or build logic.
|
6
|
+
#
|
7
|
+
# ******** NOTE ********
|
8
|
+
# We have attempted to detect the languages in your repository. Please check
|
9
|
+
# the `language` matrix defined below to confirm you have the correct set of
|
10
|
+
# supported CodeQL languages.
|
11
|
+
#
|
12
|
+
name: "CodeQL"
|
13
|
+
|
14
|
+
on:
|
15
|
+
push:
|
16
|
+
branches: [ "main" ]
|
17
|
+
pull_request:
|
18
|
+
# The branches below must be a subset of the branches above
|
19
|
+
branches: [ "main" ]
|
20
|
+
schedule:
|
21
|
+
- cron: '20 22 * * 6'
|
22
|
+
|
23
|
+
jobs:
|
24
|
+
analyze:
|
25
|
+
name: Analyze
|
26
|
+
runs-on: ubuntu-latest
|
27
|
+
permissions:
|
28
|
+
actions: read
|
29
|
+
contents: read
|
30
|
+
security-events: write
|
31
|
+
|
32
|
+
strategy:
|
33
|
+
fail-fast: false
|
34
|
+
matrix:
|
35
|
+
language: [ 'ruby' ]
|
36
|
+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
37
|
+
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
|
38
|
+
|
39
|
+
steps:
|
40
|
+
- name: Checkout repository
|
41
|
+
uses: actions/checkout@v3
|
42
|
+
|
43
|
+
# Initializes the CodeQL tools for scanning.
|
44
|
+
- name: Initialize CodeQL
|
45
|
+
uses: github/codeql-action/init@v2
|
46
|
+
with:
|
47
|
+
languages: ${{ matrix.language }}
|
48
|
+
# If you wish to specify custom queries, you can do so here or in a config file.
|
49
|
+
# By default, queries listed here will override any specified in a config file.
|
50
|
+
# Prefix the list here with "+" to use these queries and those in the config file.
|
51
|
+
|
52
|
+
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
|
53
|
+
# queries: security-extended,security-and-quality
|
54
|
+
|
55
|
+
|
56
|
+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
57
|
+
# If this step fails, then you should remove it and run the build manually (see below)
|
58
|
+
- name: Autobuild
|
59
|
+
uses: github/codeql-action/autobuild@v2
|
60
|
+
|
61
|
+
# ℹ️ Command-line programs to run using the OS shell.
|
62
|
+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
|
63
|
+
|
64
|
+
# If the Autobuild fails above, remove it and uncomment the following three lines.
|
65
|
+
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
|
66
|
+
|
67
|
+
# - run: |
|
68
|
+
# echo "Run, Build Application using script"
|
69
|
+
# ./location_of_script_within_repo/buildscript.sh
|
70
|
+
|
71
|
+
- name: Perform CodeQL Analysis
|
72
|
+
uses: github/codeql-action/analyze@v2
|
data/.rubocop.yml
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-minitest
|
3
|
+
- rubocop-performance
|
4
|
+
|
1
5
|
AllCops:
|
2
6
|
NewCops: enable
|
3
7
|
|
@@ -28,3 +32,6 @@ Metrics/AbcSize:
|
|
28
32
|
# Wait until https://github.com/rubocop/rubocop/issues/8761 is fixed
|
29
33
|
Gemspec/RequiredRubyVersion:
|
30
34
|
Enabled: false
|
35
|
+
|
36
|
+
Minitest/MultipleAssertions:
|
37
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,16 @@
|
|
1
1
|
# Unreleased
|
2
2
|
|
3
|
+
# v 0.3.2
|
4
|
+
- Include Zeitwerk
|
5
|
+
|
6
|
+
# v 0.3.1
|
7
|
+
- Update Meta API to v14
|
8
|
+
|
9
|
+
# v 0.3.0
|
10
|
+
- Allow Apps to have a singleton global authentication client.
|
11
|
+
|
3
12
|
# v 0.2.0
|
4
13
|
- Added Media API
|
5
|
-
- Update Facebook API to v14
|
6
14
|
- Added error and sucess responses
|
7
15
|
- Added faraday-multiplart as part of the library
|
8
16
|
|
data/Gemfile
CHANGED
@@ -4,19 +4,22 @@ source "https://rubygems.org"
|
|
4
4
|
|
5
5
|
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
6
6
|
|
7
|
-
# Specify your gem's dependencies in whatsapp_sdk.gemspec
|
8
7
|
gem("faraday")
|
9
8
|
gem("faraday-multipart")
|
10
9
|
gem("oj")
|
10
|
+
gem("rake", ">= 12.3.3")
|
11
|
+
gem("zeitwerk", ">= 2.6.0")
|
11
12
|
|
12
13
|
group(:test) do
|
13
14
|
gem('mocha')
|
15
|
+
gem('rubocop', require: false)
|
16
|
+
gem('rubocop-minitest', require: false)
|
17
|
+
gem('rubocop-performance', require: false)
|
14
18
|
end
|
15
19
|
|
16
20
|
group(:development) do
|
17
21
|
gem('pry')
|
18
22
|
gem('pry-nav')
|
19
|
-
gem('rubocop', require: false)
|
20
23
|
end
|
21
24
|
|
22
25
|
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
whatsapp_sdk (0.2
|
4
|
+
whatsapp_sdk (0.3.2)
|
5
5
|
faraday (~> 2.3.0)
|
6
6
|
faraday-multipart (~> 1.0.4)
|
7
7
|
oj (~> 3.13.13)
|
8
|
+
zeitwerk (~> 2.6.0)
|
8
9
|
|
9
10
|
GEM
|
10
11
|
remote: https://rubygems.org/
|
@@ -18,10 +19,10 @@ GEM
|
|
18
19
|
multipart-post (~> 2)
|
19
20
|
faraday-net_http (2.0.3)
|
20
21
|
method_source (1.0.0)
|
21
|
-
minitest (5.
|
22
|
+
minitest (5.16.1)
|
22
23
|
mocha (1.14.0)
|
23
|
-
multipart-post (2.2.
|
24
|
-
oj (3.13.
|
24
|
+
multipart-post (2.2.3)
|
25
|
+
oj (3.13.14)
|
25
26
|
parallel (1.22.1)
|
26
27
|
parser (3.1.2.0)
|
27
28
|
ast (~> 2.4.1)
|
@@ -31,10 +32,10 @@ GEM
|
|
31
32
|
pry-nav (1.0.0)
|
32
33
|
pry (>= 0.9.10, < 0.15)
|
33
34
|
rainbow (3.1.1)
|
34
|
-
rake (
|
35
|
+
rake (13.0.6)
|
35
36
|
regexp_parser (2.5.0)
|
36
37
|
rexml (3.2.5)
|
37
|
-
rubocop (1.30.
|
38
|
+
rubocop (1.30.1)
|
38
39
|
parallel (~> 1.10)
|
39
40
|
parser (>= 3.1.0.0)
|
40
41
|
rainbow (>= 2.2.2, < 4.0)
|
@@ -45,9 +46,15 @@ GEM
|
|
45
46
|
unicode-display_width (>= 1.4.0, < 3.0)
|
46
47
|
rubocop-ast (1.18.0)
|
47
48
|
parser (>= 3.1.1.0)
|
49
|
+
rubocop-minitest (0.20.1)
|
50
|
+
rubocop (>= 0.90, < 2.0)
|
51
|
+
rubocop-performance (1.14.2)
|
52
|
+
rubocop (>= 1.7.0, < 2.0)
|
53
|
+
rubocop-ast (>= 0.4.0)
|
48
54
|
ruby-progressbar (1.11.0)
|
49
55
|
ruby2_keywords (0.0.5)
|
50
|
-
unicode-display_width (2.
|
56
|
+
unicode-display_width (2.2.0)
|
57
|
+
zeitwerk (2.6.0)
|
51
58
|
|
52
59
|
PLATFORMS
|
53
60
|
x86_64-darwin-21
|
@@ -61,9 +68,12 @@ DEPENDENCIES
|
|
61
68
|
oj
|
62
69
|
pry
|
63
70
|
pry-nav
|
64
|
-
rake (
|
71
|
+
rake (>= 12.3.3)
|
65
72
|
rubocop
|
73
|
+
rubocop-minitest
|
74
|
+
rubocop-performance
|
66
75
|
whatsapp_sdk!
|
76
|
+
zeitwerk (>= 2.6.0)
|
67
77
|
|
68
78
|
BUNDLED WITH
|
69
79
|
2.3.9
|
data/README.md
CHANGED
@@ -1,7 +1,14 @@
|
|
1
1
|
# Ruby Whatsapp SDK
|
2
|
+
[](https://badge.fury.io/rb/whatsapp_sdk)
|
3
|
+
[](https://circleci.com/gh/ignacio-chiazzo/ruby_whatsapp_sdk)
|
4
|
+
<a href="https://codeclimate.com/github/ignacio-chiazzo/ruby_whatsapp_sdk/maintainability"><img src="https://api.codeclimate.com/v1/badges/169cce95450272e4ad7d/maintainability" /></a>
|
2
5
|
|
3
6
|
The SDK provides a set of operations and classes to use the Whatsapp API.
|
4
|
-
Send stickers, messages, audio, videos, locations or just ask for the phone numbers through this library in a few steps!
|
7
|
+
Send stickers, messages, audio, videos, and locations or just ask for the phone numbers through this library in a few steps!
|
8
|
+
|
9
|
+
|
10
|
+
https://user-images.githubusercontent.com/11672878/173238826-6fc0a6f8-d0ee-4eae-8947-7dfd3b8b3446.mov
|
11
|
+
|
5
12
|
|
6
13
|
## Installation
|
7
14
|
|
@@ -21,12 +28,22 @@ Or install it yourself as:
|
|
21
28
|
|
22
29
|
## Quick Start
|
23
30
|
|
24
|
-
There are
|
31
|
+
There are three primary resources, `Messages`, `Media` and `PhoneNumbers`. `Messages` allows users to send any kind of message (text, audio, location, video, image, etc.). `Media` allows users to manage media, and `Phone Numbers` enable clients to query the associated phone numbers.
|
25
32
|
|
26
|
-
To use `Messages` or `PhoneNumbers
|
33
|
+
To use `Messages`, `Media` or `PhoneNumbers`, you need to initialize the `Client` that contains auth information. There are two ways to do it
|
34
|
+
|
35
|
+
1) Using an initializer
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
WhatsappSdk.configure do |config|
|
39
|
+
config.access_token = ACCESS_TOKEN
|
40
|
+
end
|
41
|
+
```
|
42
|
+
OR 2) creating a `Client` instance and pass it to the `Messages`, `Medias` or `PhoneNumbers` instance like this:
|
27
43
|
|
28
44
|
```ruby
|
29
45
|
client = WhatsappSdk::Api::Client.new("<ACCESS TOKEN>") # replace this with a valid access token
|
46
|
+
messages_api = WhatsappSdk::Api::Messages.new(client)
|
30
47
|
```
|
31
48
|
|
32
49
|
Each API operation returns a `WhatsappSdk::Api::Response` that contains `data` and `error` and a couple of helpful functions such as `ok?` and `error?`. There are three types of response `WhatsappSdk::Api::MessageDataResponse`, `WhatsappSdk::Api::PhoneNumberDataResponse` and `WhatsappSdk::Api::PhoneNumbersDataResponse`. Each of them contains different attributes.
|
@@ -35,12 +52,13 @@ Each API operation returns a `WhatsappSdk::Api::Response` that contains `data` a
|
|
35
52
|
First, create the client and then create an instance `WhatsappSdk::Api::Messages` that requires a client as a param like this:
|
36
53
|
|
37
54
|
```ruby
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
medias_api = WhatsappSdk::Api::Medias.new(client)
|
55
|
+
messages_api = WhatsappSdk::Api::Messages.new
|
56
|
+
phone_numbers_api = WhatsappSdk::Api::PhoneNumbers.new
|
57
|
+
medias_api = WhatsappSdk::Api::Medias.new
|
42
58
|
```
|
43
59
|
|
60
|
+
Note: Remember to initialize the client first!
|
61
|
+
|
44
62
|
### Phone numbers API
|
45
63
|
Get the list of phone numbers registered
|
46
64
|
```ruby
|
@@ -82,11 +100,19 @@ medias_api.delete(media_id: MEDIA_ID)
|
|
82
100
|
messages_api.send_text(sender_id: 1234, recipient_number: "112345678", message: "hola")
|
83
101
|
```
|
84
102
|
|
103
|
+
**Read a message**
|
104
|
+
```ruby
|
105
|
+
messages_api.read_message(sender_id: 1234, message_id: "wamid.HBgLMTM0M12345678910=")
|
106
|
+
```
|
107
|
+
|
108
|
+
Note: To get the `message_id` you can set up [Webhooks](https://developers.facebook.com/docs/whatsapp/cloud-api/webhooks/components) that will listen and fire an event when a message is received.
|
109
|
+
|
110
|
+
|
85
111
|
**Send a location message**
|
86
112
|
|
87
113
|
```ruby
|
88
114
|
messages_api.send_location(
|
89
|
-
sender_id: 123123, recipient_number: "56789",
|
115
|
+
sender_id: 123123, recipient_number: "56789",
|
90
116
|
longitude: 45.4215, latitude: 75.6972, name: "nacho", address: "141 cooper street"
|
91
117
|
)
|
92
118
|
```
|
@@ -94,12 +120,12 @@ messages_api.send_location(
|
|
94
120
|
**Send an image message**
|
95
121
|
It could use a link or an image_id.
|
96
122
|
```ruby
|
97
|
-
# with a link
|
123
|
+
# with a link
|
98
124
|
messages_api.send_image(
|
99
125
|
sender_id: 123123, recipient_number: "56789", link: "image_link", caption: "Ignacio Chiazzo Profile"
|
100
126
|
)
|
101
127
|
|
102
|
-
# with an image id
|
128
|
+
# with an image id
|
103
129
|
messages_api.send_image(
|
104
130
|
sender_id: 123123, recipient_number: "56789", image_id: "1234", caption: "Ignacio Chiazzo Profile"
|
105
131
|
)
|
@@ -108,22 +134,22 @@ messages_api.send_image(
|
|
108
134
|
**Send an audio message**
|
109
135
|
It could use a link or an audio_id.
|
110
136
|
```ruby
|
111
|
-
# with a link
|
137
|
+
# with a link
|
112
138
|
messages_api.send_audio(sender_id: 123123, recipient_number: "56789", link: "audio_link")
|
113
139
|
|
114
|
-
# with an audio id
|
140
|
+
# with an audio id
|
115
141
|
messages_api.send_audio(sender_id: 123123, recipient_number: "56789", audio_id: "1234")
|
116
142
|
```
|
117
143
|
|
118
144
|
**Send a document message**
|
119
145
|
It could use a link or a document_id.
|
120
146
|
```ruby
|
121
|
-
# with a link
|
147
|
+
# with a link
|
122
148
|
messages_api.send_document(
|
123
149
|
sender_id: 123123, recipient_number: "56789", link: "document_link", caption: "Ignacio Chiazzo"
|
124
150
|
)
|
125
151
|
|
126
|
-
# with a document id
|
152
|
+
# with a document id
|
127
153
|
messages_api.send_document(
|
128
154
|
sender_id: 123123, recipient_number: "56789", document_id: "1234", caption: "Ignacio Chiazzo"
|
129
155
|
)
|
@@ -132,7 +158,7 @@ messages_api.send_document(
|
|
132
158
|
**Send a sticker message**
|
133
159
|
It could use a link or a sticker_id.
|
134
160
|
```ruby
|
135
|
-
# with a link
|
161
|
+
# with a link
|
136
162
|
messages_api.send_sticker(sender_id: 123123, recipient_number: "56789", link: "link")
|
137
163
|
|
138
164
|
# with a sticker_id
|
@@ -218,7 +244,7 @@ Visit [the example file](/example.rb) with examples to call the API in a single
|
|
218
244
|
|
219
245
|
## Troubleshooting
|
220
246
|
|
221
|
-
- If the API response is success but the message is not delivered, make sure the device you're sending the message to is using a supported Whatsapp version. [Check documentation](https://developers.facebook.com/docs/whatsapp/cloud-api/support/troubleshooting#message-not-delivered)
|
247
|
+
- If the API response is `success` but the message is not delivered, make sure the device you're sending the message to is using a supported Whatsapp version. [Check documentation](https://developers.facebook.com/docs/whatsapp/cloud-api/support/troubleshooting#message-not-delivered)
|
222
248
|
|
223
249
|
## Development
|
224
250
|
|
@@ -228,7 +254,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
228
254
|
|
229
255
|
## Contributing
|
230
256
|
|
231
|
-
Bug reports and pull requests are welcome on GitHub at [https://github.com/ignacio-chiazzo/
|
257
|
+
Bug reports and pull requests are welcome on GitHub at [https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk) This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
232
258
|
|
233
259
|
## License
|
234
260
|
|
data/example.rb
CHANGED
@@ -11,7 +11,7 @@ gemfile(true) do
|
|
11
11
|
|
12
12
|
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
13
13
|
|
14
|
-
gem "whatsapp_sdk",
|
14
|
+
gem "whatsapp_sdk", path: "/Users/ignaciochiazzo/src/whatsapp_sdk"
|
15
15
|
gem "pry"
|
16
16
|
gem "pry-nav"
|
17
17
|
end
|
@@ -22,11 +22,18 @@ require "pry-nav"
|
|
22
22
|
|
23
23
|
################# UPDATE CONSTANTS #################
|
24
24
|
|
25
|
-
ACCESS_TOKEN = "
|
26
|
-
SENDER_ID =
|
27
|
-
RECIPIENT_NUMBER =
|
28
|
-
BUSINESS_ID =
|
29
|
-
IMAGE_LINK = "
|
25
|
+
ACCESS_TOKEN = "EAAHwuHDNkqoBAOtjFZAw1MUOXsFOv4EMP8Hi2mtzvcHSPbYWD4HLLLRapjPIDQWagke3cF2IIZCbtlhMZCluO1sH7C594q0q9UqZAXwufTqBtebRlssZCLwKeC69l6Emdmt2gRYGDnhTJH0mrM7L5ivZAWezhjOvtzdnKJ7xBZALiQRKB6JrEAgAZBcnBMfBZC75xR0ZACXQUPoplhjN1a5FTA" # replace this with a valid access_token # TODO replace
|
26
|
+
SENDER_ID = 107_878_721_936_019
|
27
|
+
RECIPIENT_NUMBER = 13_437_772_910
|
28
|
+
BUSINESS_ID = 114_503_234_599_312
|
29
|
+
IMAGE_LINK = "https://ignaciochiazzo.com/static/4c403819b9750c8ad8b20a75308f2a8a/876d5/profile-pic.avif"
|
30
|
+
binding.pry
|
31
|
+
# message_sent = messages_api.send_text(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, message: "holis")
|
32
|
+
|
33
|
+
################# Initialize Client #################
|
34
|
+
WhatsappSdk.configure do |config|
|
35
|
+
config.access_token = ACCESS_TOKEN
|
36
|
+
end
|
30
37
|
|
31
38
|
################# HELPERS ########################
|
32
39
|
def print_message_sent(message_response)
|
@@ -38,10 +45,9 @@ def print_message_sent(message_response)
|
|
38
45
|
end
|
39
46
|
##################################################
|
40
47
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
phone_numbers_api = WhatsappSdk::Api::PhoneNumbers.new(client)
|
48
|
+
medias_api = WhatsappSdk::Api::Medias.new
|
49
|
+
messages_api = WhatsappSdk::Api::Messages.new
|
50
|
+
phone_numbers_api = WhatsappSdk::Api::PhoneNumbers.new
|
45
51
|
|
46
52
|
############################## Phone Numbers API ##############################
|
47
53
|
phone_numbers_api.registered_number(SENDER_ID)
|
@@ -53,6 +59,7 @@ uploaded_media = medias_api.upload(sender_id: SENDER_ID, file_path: "tmp/whatsap
|
|
53
59
|
puts "Uploaded media id: #{uploaded_media.data&.id}"
|
54
60
|
|
55
61
|
# get a media
|
62
|
+
uploaded_media = medias_api.upload(sender_id: SENDER_ID, file_path: "tmp/whatsapp.png", type: "image/png")
|
56
63
|
media = medias_api.media(media_id: uploaded_media.data&.id).data
|
57
64
|
puts "Media info: #{media.raw_data_response}"
|
58
65
|
|
@@ -60,9 +67,9 @@ puts "Media info: #{media.raw_data_response}"
|
|
60
67
|
download_image = medias_api.download(url: media&.url, file_path: 'tmp/downloaded_whatsapp.png')
|
61
68
|
puts "Downloaded: #{download_image.data.success?}"
|
62
69
|
|
63
|
-
# delete a media
|
64
|
-
deleted_media = medias_api.delete(media_id: media&.id)
|
65
|
-
puts "Deleted: #{deleted_media.data.success?}"
|
70
|
+
# # delete a media
|
71
|
+
# deleted_media = medias_api.delete(media_id: media&.id)
|
72
|
+
# puts "Deleted: #{deleted_media.data.success?}"
|
66
73
|
|
67
74
|
############################## Messages API ##############################
|
68
75
|
|
@@ -77,6 +84,9 @@ location_sent = messages_api.send_location(
|
|
77
84
|
)
|
78
85
|
print_message_sent(location_sent)
|
79
86
|
|
87
|
+
######### READ A MESSAGE
|
88
|
+
# messages_api.read_message(sender_id: SENDER_ID, message_id: msg_id)
|
89
|
+
|
80
90
|
######### SEND AN IMAGE
|
81
91
|
# Send an image with a link
|
82
92
|
image_sent = messages_api.send_image(
|
@@ -91,28 +101,28 @@ messages_api.send_image(
|
|
91
101
|
|
92
102
|
######### SEND AUDIOS
|
93
103
|
## with a link
|
94
|
-
|
104
|
+
messages_api.send_audio(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, link: "audio_link")
|
95
105
|
|
96
106
|
## with an audio id
|
97
|
-
|
107
|
+
messages_api.send_audio(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, audio_id: "1234")
|
98
108
|
|
99
109
|
######### SEND DOCUMENTS
|
100
110
|
## with a link
|
101
|
-
|
102
|
-
|
103
|
-
|
111
|
+
messages_api.send_document(
|
112
|
+
sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, link: "document_link", caption: "Ignacio Chiazzo"
|
113
|
+
)
|
104
114
|
|
105
115
|
## with a document id
|
106
|
-
|
107
|
-
|
108
|
-
|
116
|
+
messages_api.send_document(
|
117
|
+
sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, document_id: "1234", caption: "Ignacio Chiazzo"
|
118
|
+
)
|
109
119
|
|
110
120
|
######### SEND STICKERS
|
111
121
|
## with a link
|
112
|
-
|
122
|
+
messages_api.send_sticker(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, link: "link")
|
113
123
|
|
114
124
|
## with a sticker_id
|
115
|
-
|
125
|
+
messages_api.send_sticker(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, sticker_id: "1234")
|
116
126
|
|
117
127
|
######### SEND A TEMPLATE
|
118
128
|
# Note: The template must have been created previously.
|
@@ -122,49 +132,49 @@ response_with_object = messages_api.send_template(sender_id: SENDER_ID, recipien
|
|
122
132
|
name: "hello_world", language: "en_US", components: [])
|
123
133
|
puts response_with_object
|
124
134
|
|
125
|
-
# Send a template with components.
|
126
|
-
|
127
|
-
|
128
|
-
|
135
|
+
# Send a template with components.Remember to create the template first.
|
136
|
+
header_component = WhatsappSdk::Resource::Component.new(
|
137
|
+
type: WhatsappSdk::Resource::Component::Type::HEADER
|
138
|
+
)
|
129
139
|
|
130
|
-
|
131
|
-
|
132
|
-
|
140
|
+
image = WhatsappSdk::Resource::Media.new(type: "image", link: "http(s)://URL", caption: "caption")
|
141
|
+
document = WhatsappSdk::Resource::Media.new(type: "document", link: "http(s)://URL", filename: "txt.rb")
|
142
|
+
video = WhatsappSdk::Resource::Media.new(type: "video", id: 123)
|
133
143
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
144
|
+
parameter_image = WhatsappSdk::Resource::ParameterObject.new(
|
145
|
+
type: "image",
|
146
|
+
image: image
|
147
|
+
)
|
138
148
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
149
|
+
parameter_document = WhatsappSdk::Resource::ParameterObject.new(
|
150
|
+
type: "document",
|
151
|
+
document: document
|
152
|
+
)
|
143
153
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
154
|
+
parameter_video = WhatsappSdk::Resource::ParameterObject.new(
|
155
|
+
type: "video",
|
156
|
+
video: video
|
157
|
+
)
|
148
158
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
159
|
+
parameter_text = WhatsappSdk::Resource::ParameterObject.new(
|
160
|
+
type: "text",
|
161
|
+
text: "I am a text"
|
162
|
+
)
|
153
163
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
164
|
+
header_component.add_parameter(parameter_text)
|
165
|
+
header_component.add_parameter(parameter_image)
|
166
|
+
header_component.add_parameter(parameter_video)
|
167
|
+
header_component.add_parameter(parameter_document)
|
168
|
+
header_component.to_json
|
159
169
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
170
|
+
body_component = WhatsappSdk::Resource::Component.new(
|
171
|
+
type: WhatsappSdk::Resource::Component::Type::BODY
|
172
|
+
)
|
173
|
+
body_component.add_parameter(parameter_text)
|
174
|
+
body_component.add_parameter(parameter_image)
|
175
|
+
body_component.add_parameter(parameter_video)
|
176
|
+
body_component.add_parameter(parameter_document)
|
177
|
+
body_component.to_json
|
168
178
|
|
169
179
|
# button_component_1 = WhatsappSdk::Resource::Component.new(
|
170
180
|
# type: WhatsappSdk::Resource::Component::Type::BUTTON,
|
@@ -180,21 +190,26 @@ puts response_with_object
|
|
180
190
|
# parameters: [WhatsappSdk::Resource::ButtonParameter.new(type: "payload", payload: "payload")]
|
181
191
|
# )
|
182
192
|
|
183
|
-
#
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
193
|
+
# Send a template with component_json
|
194
|
+
response_with_json = messages_api.send_template(
|
195
|
+
sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, name: "hello_world", language: "en_US",
|
196
|
+
components_json: [
|
197
|
+
{
|
198
|
+
"type" => "header",
|
199
|
+
"parameters" => [
|
200
|
+
{
|
201
|
+
"type" => "image",
|
202
|
+
"image" => {
|
203
|
+
"link" => "https://www.google.com/imgres?imgurl=https%3A%2F%2Fqph.cf2.quoracdn.net%2Fmain-qimg-6d977408fdd90a09a1fee7ba9e2f777c-lq&imgrefurl=https%3A%2F%2Fwww.quora.com%2FHow-can-I-find-my-WhatsApp-ID&tbnid=lDAx1vzXwqCakM&vet=12ahUKEwjKupLviJX4AhVrrHIEHQpGD9MQMygAegUIARC9AQ..i&docid=s-DNQVCrZmhJYM&w=602&h=339&q=example%20whatsapp%20image%20id&ved=2ahUKEwjKupLviJX4AhVrrHIEHQpGD9MQMygAegUIARC9AQ"
|
204
|
+
}
|
205
|
+
}
|
206
|
+
]
|
207
|
+
}
|
208
|
+
]
|
209
|
+
)
|
210
|
+
puts response_with_json
|
211
|
+
|
212
|
+
|
213
|
+
# # delete a media
|
214
|
+
deleted_media = medias_api.delete(media_id: media&.id)
|
215
|
+
puts "Deleted: #{deleted_media.data.success?}"
|
data/lib/version.rb
CHANGED
@@ -3,10 +3,10 @@
|
|
3
3
|
module WhatsappSdk
|
4
4
|
module Api
|
5
5
|
class Request
|
6
|
-
API_VERSION = "
|
6
|
+
API_VERSION = "v14.0"
|
7
7
|
API_CLIENT = "https://graph.facebook.com/#{API_VERSION}/"
|
8
8
|
|
9
|
-
def initialize(client)
|
9
|
+
def initialize(client = WhatsappSdk.configuration.client)
|
10
10
|
@client = client
|
11
11
|
end
|
12
12
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WhatsappSdk
|
4
|
+
# This module allows client instantiating the client as a singleton like the following example:
|
5
|
+
# WhatsappSdk.configure do |config|
|
6
|
+
# config.access_token = ACCESS_TOKEN
|
7
|
+
# end
|
8
|
+
#
|
9
|
+
# The gem have access to the client through WhatsappSdk.configuration.client
|
10
|
+
class Configuration
|
11
|
+
attr_accessor :access_token
|
12
|
+
|
13
|
+
def initialize(access_token = nil)
|
14
|
+
@access_token = access_token
|
15
|
+
end
|
16
|
+
|
17
|
+
def client
|
18
|
+
return unless access_token
|
19
|
+
|
20
|
+
WhatsappSdk::Api::Client.new(access_token)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/whatsapp_sdk.rb
CHANGED
@@ -1,35 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
require_relative "whatsapp_sdk/api/medias"
|
7
|
-
require_relative "whatsapp_sdk/api/client"
|
3
|
+
require "zeitwerk"
|
4
|
+
loader = Zeitwerk::Loader.for_gem
|
5
|
+
loader.setup
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
require_relative "whatsapp_sdk/api/responses/data_response"
|
15
|
-
require_relative "whatsapp_sdk/api/responses/read_message_data_response"
|
16
|
-
require_relative "whatsapp_sdk/api/responses/media_data_response"
|
17
|
-
require_relative "whatsapp_sdk/api/responses/success_response"
|
18
|
-
require_relative "whatsapp_sdk/api/responses/error_response"
|
7
|
+
module WhatsappSdk
|
8
|
+
class << self
|
9
|
+
def configuration
|
10
|
+
@configuration ||= Configuration.new
|
11
|
+
end
|
19
12
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
require_relative "whatsapp_sdk/resource/contact"
|
26
|
-
require_relative "whatsapp_sdk/resource/currency"
|
27
|
-
require_relative "whatsapp_sdk/resource/date_time"
|
28
|
-
require_relative "whatsapp_sdk/resource/email"
|
29
|
-
require_relative "whatsapp_sdk/resource/media"
|
30
|
-
require_relative "whatsapp_sdk/resource/message"
|
31
|
-
require_relative "whatsapp_sdk/resource/name"
|
32
|
-
require_relative "whatsapp_sdk/resource/org"
|
33
|
-
require_relative "whatsapp_sdk/resource/parameter_object"
|
34
|
-
require_relative "whatsapp_sdk/resource/phone_number"
|
35
|
-
require_relative "whatsapp_sdk/resource/url"
|
13
|
+
def configure
|
14
|
+
yield(configuration)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/whatsapp_sdk.gemspec
CHANGED
@@ -9,10 +9,12 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.version = WhatsappSdk::VERSION
|
10
10
|
spec.authors = ["ignacio-chiazzo"]
|
11
11
|
spec.email = ["ignaciochiazzo@gmail.com"]
|
12
|
-
|
13
|
-
spec.
|
14
|
-
|
15
|
-
|
12
|
+
spec.summary = "Use the Ruby Whatsapp SDK to comunicate with Whatsapp API using the Cloud API"
|
13
|
+
spec.description = <<-DESCRIPTION
|
14
|
+
Use the Ruby Whatsapp SDK to comunicate with Whatsapp API using the Cloud API.
|
15
|
+
Create bots to send and receive messages using the Whatsapp SDK in a few minutes.
|
16
|
+
DESCRIPTION
|
17
|
+
spec.homepage = "https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk"
|
16
18
|
spec.license = "MIT"
|
17
19
|
spec.required_ruby_version = '>= 1.8.6'
|
18
20
|
|
@@ -20,8 +22,8 @@ Gem::Specification.new do |spec|
|
|
20
22
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
21
23
|
if spec.respond_to?(:metadata)
|
22
24
|
spec.metadata["homepage_uri"] = spec.homepage
|
23
|
-
spec.metadata["source_code_uri"] = "https://github.com/ignacio-chiazzo/
|
24
|
-
spec.metadata["changelog_uri"] = "https://github.com/ignacio-chiazzo/
|
25
|
+
spec.metadata["source_code_uri"] = "https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk"
|
26
|
+
spec.metadata["changelog_uri"] = "https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/blob/main/CHANGELOG.md"
|
25
27
|
else
|
26
28
|
raise "RubyGems 2.0 or newer is required to protect against " \
|
27
29
|
"public gem pushes."
|
@@ -38,10 +40,11 @@ Gem::Specification.new do |spec|
|
|
38
40
|
|
39
41
|
spec.add_development_dependency "bundler", "~> 2.3"
|
40
42
|
spec.add_development_dependency "minitest", "~> 5.0"
|
41
|
-
spec.add_development_dependency "rake", "~>
|
43
|
+
spec.add_development_dependency "rake", "~> 12.3.3"
|
42
44
|
|
43
45
|
spec.add_dependency("faraday", "~> 2.3.0")
|
44
46
|
spec.add_dependency("faraday-multipart", "~> 1.0.4")
|
45
47
|
spec.add_dependency("oj", "~> 3.13.13")
|
48
|
+
spec.add_dependency("zeitwerk", "~> 2.6.0")
|
46
49
|
spec.metadata['rubygems_mfa_required'] = 'true'
|
47
50
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whatsapp_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ignacio-chiazzo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 12.3.3
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 12.3.3
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: faraday
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,7 +94,23 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 3.13.13
|
97
|
-
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: zeitwerk
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.6.0
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.6.0
|
111
|
+
description: |2
|
112
|
+
Use the Ruby Whatsapp SDK to comunicate with Whatsapp API using the Cloud API.
|
113
|
+
Create bots to send and receive messages using the Whatsapp SDK in a few minutes.
|
98
114
|
email:
|
99
115
|
- ignaciochiazzo@gmail.com
|
100
116
|
executables: []
|
@@ -102,6 +118,9 @@ extensions: []
|
|
102
118
|
extra_rdoc_files: []
|
103
119
|
files:
|
104
120
|
- ".circleci/config.yml"
|
121
|
+
- ".github/ISSUE_TEMPLATE/bug_report.md"
|
122
|
+
- ".github/ISSUE_TEMPLATE/feature_request.md"
|
123
|
+
- ".github/workflows/codeql-analysis.yml"
|
105
124
|
- ".github/workflows/dependency-review.yml"
|
106
125
|
- ".github/workflows/ruby.yml"
|
107
126
|
- ".gitignore"
|
@@ -134,6 +153,7 @@ files:
|
|
134
153
|
- lib/whatsapp_sdk/api/responses/phone_numbers_data_response.rb
|
135
154
|
- lib/whatsapp_sdk/api/responses/read_message_data_response.rb
|
136
155
|
- lib/whatsapp_sdk/api/responses/success_response.rb
|
156
|
+
- lib/whatsapp_sdk/configuration.rb
|
137
157
|
- lib/whatsapp_sdk/error.rb
|
138
158
|
- lib/whatsapp_sdk/resource/address.rb
|
139
159
|
- lib/whatsapp_sdk/resource/button_parameter.rb
|
@@ -152,13 +172,13 @@ files:
|
|
152
172
|
- lib/whatsapp_sdk/resource/url.rb
|
153
173
|
- tmp/whatsapp.png
|
154
174
|
- whatsapp_sdk.gemspec
|
155
|
-
homepage: https://github.com/ignacio-chiazzo/
|
175
|
+
homepage: https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk
|
156
176
|
licenses:
|
157
177
|
- MIT
|
158
178
|
metadata:
|
159
|
-
homepage_uri: https://github.com/ignacio-chiazzo/
|
160
|
-
source_code_uri: https://github.com/ignacio-chiazzo/
|
161
|
-
changelog_uri: https://github.com/ignacio-chiazzo/
|
179
|
+
homepage_uri: https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk
|
180
|
+
source_code_uri: https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk
|
181
|
+
changelog_uri: https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/blob/main/CHANGELOG.md
|
162
182
|
rubygems_mfa_required: 'true'
|
163
183
|
post_install_message:
|
164
184
|
rdoc_options: []
|
@@ -178,5 +198,6 @@ requirements: []
|
|
178
198
|
rubygems_version: 3.2.3
|
179
199
|
signing_key:
|
180
200
|
specification_version: 4
|
181
|
-
summary: Use the Whatsapp SDK to comunicate with Whatsapp API
|
201
|
+
summary: Use the Ruby Whatsapp SDK to comunicate with Whatsapp API using the Cloud
|
202
|
+
API
|
182
203
|
test_files: []
|