whatsapp_sdk 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +22 -0
- data/.github/workflows/dependency-review.yml +20 -0
- data/.github/workflows/ruby.yml +38 -0
- data/.gitignore +23 -0
- data/.rubocop.yml +24 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +0 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +21 -0
- data/Gemfile.lock +64 -0
- data/LICENSE.txt +21 -0
- data/README.md +225 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/version.rb +5 -0
- data/lib/whatsapp_sdk/api/client.rb +30 -0
- data/lib/whatsapp_sdk/api/messages.rb +200 -0
- data/lib/whatsapp_sdk/api/phone_numbers.rb +30 -0
- data/lib/whatsapp_sdk/api/request.rb +18 -0
- data/lib/whatsapp_sdk/api/response.rb +33 -0
- data/lib/whatsapp_sdk/api/responses/data_response.rb +19 -0
- data/lib/whatsapp_sdk/api/responses/error_response.rb +34 -0
- data/lib/whatsapp_sdk/api/responses/message_data_response.rb +38 -0
- data/lib/whatsapp_sdk/api/responses/phone_number_data_response.rb +27 -0
- data/lib/whatsapp_sdk/api/responses/phone_numbers_data_response.rb +31 -0
- data/lib/whatsapp_sdk/error.rb +5 -0
- data/lib/whatsapp_sdk/resource/address.rb +36 -0
- data/lib/whatsapp_sdk/resource/contact.rb +31 -0
- data/lib/whatsapp_sdk/resource/contact_response.rb +14 -0
- data/lib/whatsapp_sdk/resource/email.rb +26 -0
- data/lib/whatsapp_sdk/resource/message.rb +13 -0
- data/lib/whatsapp_sdk/resource/name.rb +32 -0
- data/lib/whatsapp_sdk/resource/org.rb +23 -0
- data/lib/whatsapp_sdk/resource/phone_number.rb +28 -0
- data/lib/whatsapp_sdk/resource/url.rb +26 -0
- data/lib/whatsapp_sdk.rb +24 -0
- data/whatsapp_sdk.gemspec +45 -0
- metadata +154 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f270a981b63f318f63b07d8d7812e27a925ce5b96e8b46cec457b11647d531e2
|
4
|
+
data.tar.gz: ca9c1316ae6e4df8c01e809bee3693512cafba6840aff6b1ff6d471acc75b63c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9dd7789b53c1c5b570698a4b03da3726acc899330aa2b123625ef833c410e1d21abe1ed35415abbcd79626b5698b80e64d71dfc98212a4cb4325ddbc555b729a
|
7
|
+
data.tar.gz: adb2fd6df0007660d4e88edc455cc3bf540407820212b4b7b6c7a7d5303da654430e8b29a7bc805e350bdb334e87d72a6d13c0b15c7408ecd094f4450b915a9f
|
@@ -0,0 +1,22 @@
|
|
1
|
+
version: 2.1
|
2
|
+
orbs:
|
3
|
+
ruby: circleci/ruby@1.0.4
|
4
|
+
jobs:
|
5
|
+
test:
|
6
|
+
docker:
|
7
|
+
- image: cimg/ruby:2.7.5
|
8
|
+
steps:
|
9
|
+
- checkout
|
10
|
+
- ruby/install-deps
|
11
|
+
- run:
|
12
|
+
name: Run tests
|
13
|
+
command: bundle exec rake
|
14
|
+
- run:
|
15
|
+
name: Run Styling
|
16
|
+
command: bundle exec rubocop
|
17
|
+
|
18
|
+
workflows:
|
19
|
+
version: 2
|
20
|
+
deploy:
|
21
|
+
jobs:
|
22
|
+
- test
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Dependency Review Action
|
2
|
+
#
|
3
|
+
# This Action will scan dependency manifest files that change as part of a Pull Request, surfacing known-vulnerable versions of the packages declared or updated in the PR. Once installed, if the workflow run is marked as required, PRs introducing known-vulnerable packages will be blocked from merging.
|
4
|
+
#
|
5
|
+
# Source repository: https://github.com/actions/dependency-review-action
|
6
|
+
# Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement
|
7
|
+
name: 'Dependency Review'
|
8
|
+
on: [pull_request]
|
9
|
+
|
10
|
+
permissions:
|
11
|
+
contents: read
|
12
|
+
|
13
|
+
jobs:
|
14
|
+
dependency-review:
|
15
|
+
runs-on: ubuntu-latest
|
16
|
+
steps:
|
17
|
+
- name: 'Checkout Repository'
|
18
|
+
uses: actions/checkout@v3
|
19
|
+
- name: 'Dependency Review'
|
20
|
+
uses: actions/dependency-review-action@v1
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ main ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ main ]
|
15
|
+
|
16
|
+
permissions:
|
17
|
+
contents: read
|
18
|
+
|
19
|
+
jobs:
|
20
|
+
test:
|
21
|
+
|
22
|
+
runs-on: ubuntu-latest
|
23
|
+
strategy:
|
24
|
+
matrix:
|
25
|
+
ruby-version: ['2.6', '2.7', '3.0']
|
26
|
+
|
27
|
+
steps:
|
28
|
+
- uses: actions/checkout@v3
|
29
|
+
- name: Set up Ruby
|
30
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
31
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
32
|
+
# uses: ruby/setup-ruby@v1
|
33
|
+
uses: ruby/setup-ruby@2b019609e2b0f1ea1a2bc8ca11cb82ab46ada124
|
34
|
+
with:
|
35
|
+
ruby-version: ${{ matrix.ruby-version }}
|
36
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
37
|
+
- name: Run tests
|
38
|
+
run: bundle exec rake
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Style/StringLiterals:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
Metrics/ParameterLists:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
Style/Documentation:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Layout/LineLength:
|
11
|
+
Max: 120
|
12
|
+
|
13
|
+
Metrics/MethodLength:
|
14
|
+
Max: 30
|
15
|
+
|
16
|
+
Metrics/ClassLength:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Metrics/AbcSize:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
# Wait until https://github.com/rubocop/rubocop/issues/8761 is fixed
|
23
|
+
Gemspec/RequiredRubyVersion:
|
24
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
File without changes
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at ignaciochiazzo@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
6
|
+
|
7
|
+
# Specify your gem's dependencies in whatsapp_sdk.gemspec
|
8
|
+
gem("faraday")
|
9
|
+
gem("oj")
|
10
|
+
|
11
|
+
group(:test) do
|
12
|
+
gem('mocha')
|
13
|
+
end
|
14
|
+
|
15
|
+
group(:development) do
|
16
|
+
gem('pry')
|
17
|
+
gem('pry-nav')
|
18
|
+
gem('rubocop', require: false)
|
19
|
+
end
|
20
|
+
|
21
|
+
gemspec
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
whatsapp_sdk (0.0.1)
|
5
|
+
faraday (~> 2.3.0)
|
6
|
+
oj (~> 3.13.13)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ast (2.4.2)
|
12
|
+
coderay (1.1.3)
|
13
|
+
faraday (2.3.0)
|
14
|
+
faraday-net_http (~> 2.0)
|
15
|
+
ruby2_keywords (>= 0.0.4)
|
16
|
+
faraday-net_http (2.0.3)
|
17
|
+
method_source (1.0.0)
|
18
|
+
minitest (5.15.0)
|
19
|
+
mocha (1.14.0)
|
20
|
+
oj (3.13.13)
|
21
|
+
parallel (1.22.1)
|
22
|
+
parser (3.1.2.0)
|
23
|
+
ast (~> 2.4.1)
|
24
|
+
pry (0.14.1)
|
25
|
+
coderay (~> 1.1)
|
26
|
+
method_source (~> 1.0)
|
27
|
+
pry-nav (1.0.0)
|
28
|
+
pry (>= 0.9.10, < 0.15)
|
29
|
+
rainbow (3.1.1)
|
30
|
+
rake (10.5.0)
|
31
|
+
regexp_parser (2.5.0)
|
32
|
+
rexml (3.2.5)
|
33
|
+
rubocop (1.30.0)
|
34
|
+
parallel (~> 1.10)
|
35
|
+
parser (>= 3.1.0.0)
|
36
|
+
rainbow (>= 2.2.2, < 4.0)
|
37
|
+
regexp_parser (>= 1.8, < 3.0)
|
38
|
+
rexml (>= 3.2.5, < 4.0)
|
39
|
+
rubocop-ast (>= 1.18.0, < 2.0)
|
40
|
+
ruby-progressbar (~> 1.7)
|
41
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
42
|
+
rubocop-ast (1.18.0)
|
43
|
+
parser (>= 3.1.1.0)
|
44
|
+
ruby-progressbar (1.11.0)
|
45
|
+
ruby2_keywords (0.0.5)
|
46
|
+
unicode-display_width (2.1.0)
|
47
|
+
|
48
|
+
PLATFORMS
|
49
|
+
x86_64-darwin-21
|
50
|
+
|
51
|
+
DEPENDENCIES
|
52
|
+
bundler (~> 2.3)
|
53
|
+
faraday
|
54
|
+
minitest (~> 5.0)
|
55
|
+
mocha
|
56
|
+
oj
|
57
|
+
pry
|
58
|
+
pry-nav
|
59
|
+
rake (~> 10.0)
|
60
|
+
rubocop
|
61
|
+
whatsapp_sdk!
|
62
|
+
|
63
|
+
BUNDLED WITH
|
64
|
+
2.3.9
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 ignacio-chiazzo
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,225 @@
|
|
1
|
+
# Ruby Whatsapp SDK
|
2
|
+
|
3
|
+
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!
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'ruby-whatsapp-sdk'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install ruby-whatsapp-sdk
|
21
|
+
|
22
|
+
## Quick Start
|
23
|
+
|
24
|
+
There are two primary resources, `Messages` and `PhoneNumbers`. The first one allows clients to send any kind of message (text, audio, location, video, image, etc.), and the latter will enable clients to query the phone numbers associated.
|
25
|
+
|
26
|
+
To use `Messages` or `PhoneNumbers` you need to create a `Client` instance by passing the `access_token` like this:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
client = WhatsappSdk::Api::Client.new("<ACCESS TOKEN>") # replace this with a valid access token
|
30
|
+
```
|
31
|
+
|
32
|
+
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.
|
33
|
+
|
34
|
+
## Operations
|
35
|
+
First, create the client and then create an instance `WhatsappSdk::Api::Messages` that requires a client as a param like this:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
client = WhatsappSdk::Api::Client.new("<ACCESS TOKEN>") # replace this with a valid access_token
|
39
|
+
messages_api = WhatsappSdk::Api::Messages.new(client)
|
40
|
+
phone_numbers_api = WhatsappSdk::Api::PhoneNumbers.new(client)
|
41
|
+
```
|
42
|
+
|
43
|
+
### Phone numbers API
|
44
|
+
Get the list of phone numbers registered
|
45
|
+
```ruby
|
46
|
+
phone_numbers_api.registered_numbers("123456") # accepts a business_id
|
47
|
+
```
|
48
|
+
|
49
|
+
Get the a phone number by id
|
50
|
+
```ruby
|
51
|
+
phone_numbers_api.registered_numbers("123456") # accepts a phone_number_id
|
52
|
+
```
|
53
|
+
|
54
|
+
### Messages API
|
55
|
+
|
56
|
+
**Send a text message**
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
messages_api.send_text(sender_id: 1234, recipient_number: "112345678", message: "hola")
|
60
|
+
```
|
61
|
+
|
62
|
+
**Send a location message**
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
messages_api.send_location(
|
66
|
+
sender_id: 123123, recipient_number: "56789",
|
67
|
+
longitude: 45.4215, latitude: 75.6972, name: "nacho", address: "141 cooper street"
|
68
|
+
)
|
69
|
+
```
|
70
|
+
|
71
|
+
**Send an image message**
|
72
|
+
It could use a link or an image_id.
|
73
|
+
```ruby
|
74
|
+
# with a link
|
75
|
+
messages_api.send_image(
|
76
|
+
sender_id: 123123, recipient_number: "56789", link: "image_link", caption: "Ignacio Chiazzo Profile"
|
77
|
+
)
|
78
|
+
|
79
|
+
# with an image id
|
80
|
+
messages_api.send_image(
|
81
|
+
sender_id: 123123, recipient_number: "56789", image_id: "1234", caption: "Ignacio Chiazzo Profile"
|
82
|
+
)
|
83
|
+
```
|
84
|
+
|
85
|
+
**Send an audio message**
|
86
|
+
It could use a link or an audio_id.
|
87
|
+
```ruby
|
88
|
+
# with a link
|
89
|
+
messages_api.send_audio(sender_id: 123123, recipient_number: "56789", link: "audio_link")
|
90
|
+
|
91
|
+
# with an audio id
|
92
|
+
messages_api.send_audio(sender_id: 123123, recipient_number: "56789", audio_id: "1234")
|
93
|
+
```
|
94
|
+
|
95
|
+
**Send a document message**
|
96
|
+
It could use a link or a document_id.
|
97
|
+
```ruby
|
98
|
+
# with a link
|
99
|
+
messages_api.send_document(
|
100
|
+
sender_id: 123123, recipient_number: "56789", link: "document_link", caption: "Ignacio Chiazzo"
|
101
|
+
)
|
102
|
+
|
103
|
+
# with a document id
|
104
|
+
messages_api.send_document(
|
105
|
+
sender_id: 123123, recipient_number: "56789", document_id: "1234", caption: "Ignacio Chiazzo"
|
106
|
+
)
|
107
|
+
```
|
108
|
+
|
109
|
+
**Send a sticker message**
|
110
|
+
It could use a link or a sticker_id.
|
111
|
+
```ruby
|
112
|
+
# with a link
|
113
|
+
messages_api.send_sticker(sender_id: 123123, recipient_number: "56789", link: "link")
|
114
|
+
|
115
|
+
# with a sticker_id
|
116
|
+
messages_api.send_sticker(sender_id: 123123, recipient_number: "56789", sticker_id: "1234")
|
117
|
+
```
|
118
|
+
|
119
|
+
**Send contacts message**
|
120
|
+
To send a contact, you need to create a Contact instance object that contain objects embedded like
|
121
|
+
`addresses`, `birthday`, `emails`, `name`, `org`. See this [guide](/test/contact_helper.rb) to learn how to create contacts objects.
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
contacts = [create_contact(params)]
|
125
|
+
messages_api.send_contacts(sender_id: 123123, recipient_number: "56789", contacts: contacts)
|
126
|
+
```
|
127
|
+
|
128
|
+
## Example
|
129
|
+
|
130
|
+
<details><summary>Example in a single file. </summary>
|
131
|
+
|
132
|
+
1) Copy this code into a file and save it `example.rb`
|
133
|
+
2) Replace the `ACCESS_TOKEN` constant with a valid `access_token`.
|
134
|
+
3) Run the file with the command `ruby example.rb`
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
# frozen_string_literal: true
|
138
|
+
|
139
|
+
require 'bundler/inline'
|
140
|
+
|
141
|
+
gemfile(true) do
|
142
|
+
source 'https://rubygems.org'
|
143
|
+
|
144
|
+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
145
|
+
|
146
|
+
gem "whatsapp_sdk", path: "/Users/ignaciochiazzo/src/whatsapp_sdk"
|
147
|
+
gem "pry"
|
148
|
+
gem "pry-nav"
|
149
|
+
end
|
150
|
+
|
151
|
+
require 'whatsapp_sdk'
|
152
|
+
require "pry"
|
153
|
+
require "pry-nav"
|
154
|
+
|
155
|
+
ACCESS_TOKEN = "12345" # replace this with a valid access_token
|
156
|
+
SENDER_ID = 107878721936019
|
157
|
+
RECEIPIENT_NUMBER = "1234"
|
158
|
+
|
159
|
+
client = WhatsappSdk::Api::Client.new(ACCESS_TOKEN) # replace this with a valid access_token
|
160
|
+
messages_api = WhatsappSdk::Api::Messages.new(client)
|
161
|
+
phone_numbers_api = WhatsappSdk::Api::PhoneNumbers.new(client)
|
162
|
+
|
163
|
+
phone_numbers_api.registered_number("107878721936019")
|
164
|
+
phone_numbers_api.registered_numbers("114503234599312")
|
165
|
+
|
166
|
+
messages_api.send_text(sender_id: SENDER_ID, recipient_number: RECEIPIENT_NUMBER, message: "hola")
|
167
|
+
messages_api.send_location(
|
168
|
+
sender_id: SENDER_ID, recipient_number: RECEIPIENT_NUMBER,
|
169
|
+
longitude: 45.4215, latitude: 75.6972, name: "nacho", address: "141 cooper street"
|
170
|
+
)
|
171
|
+
|
172
|
+
# Send images
|
173
|
+
|
174
|
+
## with a link
|
175
|
+
messages_api.send_image(
|
176
|
+
sender_id: SENDER_ID, recipient_number: RECEIPIENT_NUMBER, link: "image_link", caption: "Ignacio Chiazzo Profile"
|
177
|
+
)
|
178
|
+
|
179
|
+
## with an image id
|
180
|
+
messages_api.send_image(
|
181
|
+
sender_id: SENDER_ID, recipient_number: RECEIPIENT_NUMBER, image_id: "1234", caption: "Ignacio Chiazzo Profile"
|
182
|
+
)
|
183
|
+
|
184
|
+
# Send audios
|
185
|
+
## with a link
|
186
|
+
messages_api.send_audio(sender_id: SENDER_ID, recipient_number: RECEIPIENT_NUMBER, link: "audio_link")
|
187
|
+
|
188
|
+
## with an audio id
|
189
|
+
messages_api.send_audio(sender_id: SENDER_ID, recipient_number: RECEIPIENT_NUMBER, audio_id: "1234")
|
190
|
+
|
191
|
+
# Send documents
|
192
|
+
## with a link
|
193
|
+
messages_api.send_document(
|
194
|
+
sender_id: SENDER_ID, recipient_number: RECEIPIENT_NUMBER, link: "document_link", caption: "Ignacio Chiazzo"
|
195
|
+
)
|
196
|
+
|
197
|
+
## with a document id
|
198
|
+
messages_api.send_document(
|
199
|
+
sender_id: SENDER_ID, recipient_number: RECEIPIENT_NUMBER, document_id: "1234", caption: "Ignacio Chiazzo"
|
200
|
+
)
|
201
|
+
|
202
|
+
# send stickers
|
203
|
+
## with a link
|
204
|
+
messages_api.send_sticker(sender_id: SENDER_ID, recipient_number: RECEIPIENT_NUMBER, link: "link")
|
205
|
+
|
206
|
+
## with a sticker_id
|
207
|
+
messages_api.send_sticker(sender_id: SENDER_ID, recipient_number: RECEIPIENT_NUMBER, sticker_id: "1234")
|
208
|
+
binding.pry
|
209
|
+
|
210
|
+
```
|
211
|
+
</details>
|
212
|
+
|
213
|
+
## Development
|
214
|
+
|
215
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests.
|
216
|
+
|
217
|
+
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
218
|
+
|
219
|
+
## Contributing
|
220
|
+
|
221
|
+
Bug reports and pull requests are welcome on GitHub at [https://github.com/ignacio-chiazzo/whatsapp_sdk](https://github.com/ignacio-chiazzo/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.
|
222
|
+
|
223
|
+
## License
|
224
|
+
|
225
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "whatsapp_sdk"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/version.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "faraday"
|
4
|
+
require "oj"
|
5
|
+
|
6
|
+
module WhatsappSdk
|
7
|
+
module Api
|
8
|
+
class Client
|
9
|
+
API_VERSION = "v13.0"
|
10
|
+
API_CLIENT = "https://graph.facebook.com/#{API_VERSION}/"
|
11
|
+
|
12
|
+
def initialize(access_token)
|
13
|
+
@access_token = access_token
|
14
|
+
end
|
15
|
+
|
16
|
+
def client
|
17
|
+
@client ||= ::Faraday.new(API_CLIENT) do |client|
|
18
|
+
client.request :url_encoded
|
19
|
+
client.adapter ::Faraday.default_adapter
|
20
|
+
client.headers['Authorization'] = "Bearer #{@access_token}" unless @access_token.nil?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def send_request(endpoint:, http_method: "post", params: {})
|
25
|
+
response = client.public_send(http_method, endpoint, params)
|
26
|
+
Oj.load(response.body)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|