whatsapp_sdk 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- 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/.gitignore +1 -0
- data/.rubocop.yml +14 -0
- data/CHANGELOG.md +8 -1
- data/Gemfile +6 -0
- data/Gemfile.lock +48 -1
- data/README.md +107 -33
- data/Rakefile +1 -0
- data/bin/tapioca +30 -0
- data/example.rb +23 -20
- data/lib/version.rb +2 -1
- data/lib/whatsapp_sdk/api/client.rb +14 -3
- data/lib/whatsapp_sdk/api/medias.rb +12 -3
- data/lib/whatsapp_sdk/api/messages.rb +72 -14
- data/lib/whatsapp_sdk/api/phone_numbers.rb +3 -0
- data/lib/whatsapp_sdk/api/request.rb +2 -2
- data/lib/whatsapp_sdk/api/response.rb +17 -1
- data/lib/whatsapp_sdk/api/responses/data_response.rb +10 -3
- data/lib/whatsapp_sdk/api/responses/error_response.rb +8 -1
- data/lib/whatsapp_sdk/api/responses/media_data_response.rb +26 -7
- data/lib/whatsapp_sdk/api/responses/message_data_response.rb +20 -3
- data/lib/whatsapp_sdk/api/responses/message_error_response.rb +26 -7
- data/lib/whatsapp_sdk/api/responses/phone_number_data_response.rb +18 -5
- data/lib/whatsapp_sdk/api/responses/phone_numbers_data_response.rb +9 -1
- data/lib/whatsapp_sdk/api/responses/read_message_data_response.rb +10 -3
- data/lib/whatsapp_sdk/api/responses/success_response.rb +5 -1
- data/lib/whatsapp_sdk/configuration.rb +7 -14
- data/lib/whatsapp_sdk/error.rb +1 -0
- data/lib/whatsapp_sdk/resource/address.rb +30 -6
- data/lib/whatsapp_sdk/resource/address_type.rb +15 -0
- data/lib/whatsapp_sdk/resource/button_parameter.rb +19 -23
- data/lib/whatsapp_sdk/resource/component.rb +45 -13
- data/lib/whatsapp_sdk/resource/contact.rb +30 -1
- data/lib/whatsapp_sdk/resource/contact_response.rb +9 -1
- data/lib/whatsapp_sdk/resource/currency.rb +9 -1
- data/lib/whatsapp_sdk/resource/date_time.rb +7 -1
- data/lib/whatsapp_sdk/resource/email.rb +9 -5
- data/lib/whatsapp_sdk/resource/media.rb +44 -15
- data/lib/whatsapp_sdk/resource/message.rb +5 -0
- data/lib/whatsapp_sdk/resource/name.rb +28 -1
- data/lib/whatsapp_sdk/resource/org.rb +13 -1
- data/lib/whatsapp_sdk/resource/parameter_object.rb +82 -39
- data/lib/whatsapp_sdk/resource/phone_number.rb +12 -5
- data/lib/whatsapp_sdk/resource/url.rb +9 -5
- data/lib/whatsapp_sdk.rb +19 -33
- data/sorbet/config +6 -0
- data/sorbet/rbi/annotations/faraday.rbi +17 -0
- data/sorbet/rbi/annotations/mocha.rbi +34 -0
- data/sorbet/rbi/annotations/rainbow.rbi +269 -0
- data/sorbet/rbi/gems/faraday-multipart@1.0.4.rbi +270 -0
- data/sorbet/rbi/gems/faraday-net_http@2.0.3.rbi +182 -0
- data/sorbet/rbi/gems/faraday@2.3.0.rbi +2494 -0
- data/sorbet/rbi/gems/method_source@1.0.0.rbi +272 -0
- data/sorbet/rbi/gems/minitest@5.16.1.rbi +1459 -0
- data/sorbet/rbi/gems/mocha@1.14.0.rbi +60 -0
- data/sorbet/rbi/gems/multipart-post@2.2.3.rbi +239 -0
- data/sorbet/rbi/gems/netrc@0.11.0.rbi +150 -0
- data/sorbet/rbi/gems/oj@3.13.14.rbi +589 -0
- data/sorbet/rbi/gems/zeitwerk@2.6.0.rbi +867 -0
- data/sorbet/rbi/todo.rbi +8 -0
- data/sorbet/shims/request.rbi +10 -0
- data/sorbet/tapioca/config.yml +13 -0
- data/sorbet/tapioca/require.rb +5 -0
- data/whatsapp_sdk.gemspec +5 -1
- metadata +67 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c511dc642ddf1e541454117ebb5e08df060b166b47e7905bfd9e8e989e394e1
|
4
|
+
data.tar.gz: 49f4b2fd988d44d6cdac186a47b3553fb78203ceffb1675c80c6bd176f59d68f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbcebfa04a24c570cbd28dae1410de7c5d2f95280f4f06129beb7aecdda13cc4d0b218a6c3815b5ecfefbe97c8ddc19c423ce55fb1ac3e4a6cfe535b42a6a4e1
|
7
|
+
data.tar.gz: 8e84e6f855f6383e1a0b56edeb804f72c8519b521bbf1d174c40ac659e8b244c23268cf87ad7df7ef77cbb753420e64b4910914ea80e9cd80bee1675ec38f4cf
|
@@ -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/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -4,6 +4,13 @@ require:
|
|
4
4
|
|
5
5
|
AllCops:
|
6
6
|
NewCops: enable
|
7
|
+
Exclude:
|
8
|
+
- 'example.rb'
|
9
|
+
- 'tmp/*'
|
10
|
+
- 'vendor/**/*'
|
11
|
+
|
12
|
+
Lint/ToJSON:
|
13
|
+
Enabled: false
|
7
14
|
|
8
15
|
Style/StringLiterals:
|
9
16
|
Enabled: false
|
@@ -29,9 +36,16 @@ Metrics/ClassLength:
|
|
29
36
|
Metrics/AbcSize:
|
30
37
|
Enabled: false
|
31
38
|
|
39
|
+
Lint/MissingSuper:
|
40
|
+
Enabled: false
|
41
|
+
|
32
42
|
# Wait until https://github.com/rubocop/rubocop/issues/8761 is fixed
|
33
43
|
Gemspec/RequiredRubyVersion:
|
34
44
|
Enabled: false
|
35
45
|
|
36
46
|
Minitest/MultipleAssertions:
|
37
47
|
Enabled: false
|
48
|
+
|
49
|
+
Style/AccessorGrouping: # disabled so that we can use sorbet signatures for each attr
|
50
|
+
Enabled: false
|
51
|
+
|
data/CHANGELOG.md
CHANGED
@@ -1,11 +1,18 @@
|
|
1
1
|
# Unreleased
|
2
|
+
- Make the gem stricly typed using Sorbet [#34](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/34), [#35](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/35), [#37](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/37)
|
3
|
+
- Object IDs are Strings in development [#37](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/37)
|
4
|
+
|
5
|
+
# v 0.3.2
|
6
|
+
- Include Zeitwerk
|
7
|
+
|
8
|
+
# v 0.3.1
|
9
|
+
- Update Meta API to v14
|
2
10
|
|
3
11
|
# v 0.3.0
|
4
12
|
- Allow Apps to have a singleton global authentication client.
|
5
13
|
|
6
14
|
# v 0.2.0
|
7
15
|
- Added Media API
|
8
|
-
- Update Facebook API to v14
|
9
16
|
- Added error and sucess responses
|
10
17
|
- Added faraday-multiplart as part of the library
|
11
18
|
|
data/Gemfile
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
# typed: true
|
2
3
|
|
3
4
|
source "https://rubygems.org"
|
4
5
|
|
@@ -8,6 +9,8 @@ gem("faraday")
|
|
8
9
|
gem("faraday-multipart")
|
9
10
|
gem("oj")
|
10
11
|
gem("rake", ">= 12.3.3")
|
12
|
+
gem('sorbet-runtime')
|
13
|
+
gem("zeitwerk", ">= 2.6.0")
|
11
14
|
|
12
15
|
group(:test) do
|
13
16
|
gem('mocha')
|
@@ -19,6 +22,9 @@ end
|
|
19
22
|
group(:development) do
|
20
23
|
gem('pry')
|
21
24
|
gem('pry-nav')
|
25
|
+
gem('sorbet')
|
26
|
+
gem('spoom')
|
27
|
+
gem('tapioca', require: false)
|
22
28
|
end
|
23
29
|
|
24
30
|
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,16 +1,20 @@
|
|
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
|
+
sorbet
|
9
|
+
sorbet-runtime
|
10
|
+
zeitwerk (~> 2.6.0)
|
8
11
|
|
9
12
|
GEM
|
10
13
|
remote: https://rubygems.org/
|
11
14
|
specs:
|
12
15
|
ast (2.4.2)
|
13
16
|
coderay (1.1.3)
|
17
|
+
diff-lcs (1.5.0)
|
14
18
|
faraday (2.3.0)
|
15
19
|
faraday-net_http (~> 2.0)
|
16
20
|
ruby2_keywords (>= 0.0.4)
|
@@ -21,6 +25,7 @@ GEM
|
|
21
25
|
minitest (5.16.1)
|
22
26
|
mocha (1.14.0)
|
23
27
|
multipart-post (2.2.3)
|
28
|
+
netrc (0.11.0)
|
24
29
|
oj (3.13.14)
|
25
30
|
parallel (1.22.1)
|
26
31
|
parser (3.1.2.0)
|
@@ -32,6 +37,11 @@ GEM
|
|
32
37
|
pry (>= 0.9.10, < 0.15)
|
33
38
|
rainbow (3.1.1)
|
34
39
|
rake (13.0.6)
|
40
|
+
rbi (0.0.15)
|
41
|
+
ast
|
42
|
+
parser (>= 2.6.4.0)
|
43
|
+
sorbet-runtime (>= 0.5.9204)
|
44
|
+
unparser
|
35
45
|
regexp_parser (2.5.0)
|
36
46
|
rexml (3.2.5)
|
37
47
|
rubocop (1.30.1)
|
@@ -52,7 +62,39 @@ GEM
|
|
52
62
|
rubocop-ast (>= 0.4.0)
|
53
63
|
ruby-progressbar (1.11.0)
|
54
64
|
ruby2_keywords (0.0.5)
|
65
|
+
sorbet (0.5.10346)
|
66
|
+
sorbet-static (= 0.5.10346)
|
67
|
+
sorbet-runtime (0.5.10346)
|
68
|
+
sorbet-static (0.5.10346-universal-darwin-21)
|
69
|
+
sorbet-static-and-runtime (0.5.10346)
|
70
|
+
sorbet (= 0.5.10346)
|
71
|
+
sorbet-runtime (= 0.5.10346)
|
72
|
+
spoom (1.1.12)
|
73
|
+
sorbet (>= 0.5.9204)
|
74
|
+
sorbet-runtime (>= 0.5.9204)
|
75
|
+
thor (>= 0.19.2)
|
76
|
+
tapioca (0.9.4)
|
77
|
+
bundler (>= 1.17.3)
|
78
|
+
netrc (>= 0.11.0)
|
79
|
+
parallel (>= 1.21.0)
|
80
|
+
pry (>= 0.12.2)
|
81
|
+
rbi (~> 0.0.0, >= 0.0.14)
|
82
|
+
sorbet-static-and-runtime (>= 0.5.9204)
|
83
|
+
spoom (~> 1.1.0, >= 1.1.11)
|
84
|
+
thor (>= 1.2.0)
|
85
|
+
yard-sorbet
|
86
|
+
thor (1.2.1)
|
55
87
|
unicode-display_width (2.2.0)
|
88
|
+
unparser (0.6.5)
|
89
|
+
diff-lcs (~> 1.3)
|
90
|
+
parser (>= 3.1.0)
|
91
|
+
webrick (1.7.0)
|
92
|
+
yard (0.9.28)
|
93
|
+
webrick (~> 1.7.0)
|
94
|
+
yard-sorbet (0.7.0)
|
95
|
+
sorbet-runtime (>= 0.5)
|
96
|
+
yard (>= 0.9)
|
97
|
+
zeitwerk (2.6.0)
|
56
98
|
|
57
99
|
PLATFORMS
|
58
100
|
x86_64-darwin-21
|
@@ -70,7 +112,12 @@ DEPENDENCIES
|
|
70
112
|
rubocop
|
71
113
|
rubocop-minitest
|
72
114
|
rubocop-performance
|
115
|
+
sorbet
|
116
|
+
sorbet-runtime
|
117
|
+
spoom
|
118
|
+
tapioca
|
73
119
|
whatsapp_sdk!
|
120
|
+
zeitwerk (>= 2.6.0)
|
74
121
|
|
75
122
|
BUNDLED WITH
|
76
123
|
2.3.9
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
<a href="https://codeclimate.com/github/ignacio-chiazzo/ruby_whatsapp_sdk/maintainability"><img src="https://api.codeclimate.com/v1/badges/169cce95450272e4ad7d/maintainability" /></a>
|
5
5
|
|
6
6
|
The SDK provides a set of operations and classes to use the Whatsapp API.
|
7
|
-
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
8
|
|
9
9
|
|
10
10
|
https://user-images.githubusercontent.com/11672878/173238826-6fc0a6f8-d0ee-4eae-8947-7dfd3b8b3446.mov
|
@@ -28,9 +28,9 @@ Or install it yourself as:
|
|
28
28
|
|
29
29
|
## Quick Start
|
30
30
|
|
31
|
-
There are three primary resources, `Messages`, `Media` and `PhoneNumbers`.
|
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.
|
32
32
|
|
33
|
-
To use `Messages`, `Media` 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
34
|
|
35
35
|
1) Using an initializer
|
36
36
|
|
@@ -39,7 +39,7 @@ WhatsappSdk.configure do |config|
|
|
39
39
|
config.access_token = ACCESS_TOKEN
|
40
40
|
end
|
41
41
|
```
|
42
|
-
OR creating
|
42
|
+
OR 2) creating a `Client` instance and pass it to the `Messages`, `Medias` or `PhoneNumbers` instance like this:
|
43
43
|
|
44
44
|
```ruby
|
45
45
|
client = WhatsappSdk::Api::Client.new("<ACCESS TOKEN>") # replace this with a valid access token
|
@@ -59,15 +59,82 @@ medias_api = WhatsappSdk::Api::Medias.new
|
|
59
59
|
|
60
60
|
Note: Remember to initialize the client first!
|
61
61
|
|
62
|
+
## Set up a Meta app
|
63
|
+
|
64
|
+
<details><summary>1) Create a Meta Business app </summary>
|
65
|
+
<img width="1063" alt="Screen Shot 2022-09-05 at 11 03 47 AM" src="https://user-images.githubusercontent.com/11672878/188477795-4745a71a-a4b5-41e2-bef1-e41d3060e02b.png">
|
66
|
+
</details>
|
67
|
+
|
68
|
+
<details><summary>2) Add Whatsapp to your Application</summary>
|
69
|
+
<img width="1087" alt="Screen Shot 2022-09-05 at 11 05 43 AM" src="https://user-images.githubusercontent.com/11672878/188478100-98b3bf0a-fec7-4ea1-a492-aeb90a6b06bd.png">
|
70
|
+
</details>
|
71
|
+
|
72
|
+
<details><summary>3) Add a phone number to your account</summary>
|
73
|
+
<img width="972" alt="Screen Shot 2022-09-05 at 11 09 22 AM" src="https://user-images.githubusercontent.com/11672878/188478741-8a6105e8-2776-4493-bba9-05a62082a5aa.png">
|
74
|
+
</details>
|
75
|
+
|
76
|
+
Try sending a message to your phone in the UI.
|
77
|
+
|
78
|
+
<details><summary>4) Copy the ACCESS_TOKEN, the SENDER_ID, the BUSINESS_ID and the RECEIPIENT_NUMBER</summary>
|
79
|
+
<img width="1010" alt="Screen Shot 2022-09-05 at 11 13 24 AM" src="https://user-images.githubusercontent.com/11672878/188480634-369f8de1-b851-4735-86de-f49e96f78d8c.png">
|
80
|
+
</details>
|
81
|
+
|
82
|
+
</details>
|
83
|
+
|
84
|
+
<details><summary>5) Use the GEM to interact with Whatsapp</summary>
|
85
|
+
|
86
|
+
Example:
|
87
|
+
1) Install the gem by running `gem install whatsapp_sdk` in the gem.
|
88
|
+
2) Open the irb terminal by running `irb`
|
89
|
+
3) `require "whatsapp_sdk"`
|
90
|
+
4) Set up the `ACCESS_TOKEN`, the `SENDER_ID`, the `BUSINESS_ID` and the `RECEIPIENT_NUMBER` in variables.
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
ACCESS_TOKEN = "EAAZAvvr0DZBs0BABRLF8zohP5Epc6pyNu"
|
94
|
+
BUSINESS_ID = 1213141516171819
|
95
|
+
SENDER_ID = 1234567891011
|
96
|
+
RECIPIENT_NUMBER = 12398765432
|
97
|
+
```
|
98
|
+
|
99
|
+
5) Configure the Client by running
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
WhatsappSdk.configure do |config|
|
103
|
+
config.access_token = ACCESS_TOKEN
|
104
|
+
end
|
105
|
+
```
|
106
|
+
|
107
|
+
6) Try the Medias or Messages API
|
108
|
+
|
109
|
+
Medias API
|
110
|
+
```ruby
|
111
|
+
phone_numbers_api = WhatsappSdk::Api::PhoneNumbers.new
|
112
|
+
registered_number = phone_numbers_api.registered_number(SENDER_ID)
|
113
|
+
```
|
114
|
+
|
115
|
+
Messages API
|
116
|
+
```ruby
|
117
|
+
messages_api = WhatsappSdk::Api::Messages.new
|
118
|
+
message_sent = messages_api.send_text(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER,
|
119
|
+
message: "Hey there! it's Whatsapp Ruby SDK")
|
120
|
+
```
|
121
|
+
|
122
|
+
Check the [example.rb file](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/blob/main/example.rb) for more examples.
|
123
|
+
|
124
|
+
</details>
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
|
62
129
|
### Phone numbers API
|
63
130
|
Get the list of phone numbers registered
|
64
131
|
```ruby
|
65
|
-
phone_numbers_api.registered_numbers(
|
132
|
+
phone_numbers_api.registered_numbers(123456) # accepts a business_id
|
66
133
|
```
|
67
134
|
|
68
135
|
Get the a phone number by id
|
69
136
|
```ruby
|
70
|
-
phone_numbers_api.registered_numbers(
|
137
|
+
phone_numbers_api.registered_numbers(123456) # accepts a phone_number_id
|
71
138
|
```
|
72
139
|
|
73
140
|
### Media API
|
@@ -97,7 +164,7 @@ medias_api.delete(media_id: MEDIA_ID)
|
|
97
164
|
**Send a text message**
|
98
165
|
|
99
166
|
```ruby
|
100
|
-
messages_api.send_text(sender_id: 1234, recipient_number:
|
167
|
+
messages_api.send_text(sender_id: 1234, recipient_number: 112345678, message: "hola")
|
101
168
|
```
|
102
169
|
|
103
170
|
**Read a message**
|
@@ -112,7 +179,7 @@ Note: To get the `message_id` you can set up [Webhooks](https://developers.faceb
|
|
112
179
|
|
113
180
|
```ruby
|
114
181
|
messages_api.send_location(
|
115
|
-
sender_id: 123123, recipient_number:
|
182
|
+
sender_id: 123123, recipient_number: 56789,
|
116
183
|
longitude: 45.4215, latitude: 75.6972, name: "nacho", address: "141 cooper street"
|
117
184
|
)
|
118
185
|
```
|
@@ -122,12 +189,12 @@ It could use a link or an image_id.
|
|
122
189
|
```ruby
|
123
190
|
# with a link
|
124
191
|
messages_api.send_image(
|
125
|
-
sender_id: 123123, recipient_number:
|
192
|
+
sender_id: 123123, recipient_number: 56789, link: "image_link", caption: "Ignacio Chiazzo Profile"
|
126
193
|
)
|
127
194
|
|
128
195
|
# with an image id
|
129
196
|
messages_api.send_image(
|
130
|
-
sender_id: 123123, recipient_number:
|
197
|
+
sender_id: 123123, recipient_number: 56789, image_id: "1234", caption: "Ignacio Chiazzo Profile"
|
131
198
|
)
|
132
199
|
```
|
133
200
|
|
@@ -135,10 +202,10 @@ messages_api.send_image(
|
|
135
202
|
It could use a link or an audio_id.
|
136
203
|
```ruby
|
137
204
|
# with a link
|
138
|
-
messages_api.send_audio(sender_id: 123123, recipient_number:
|
205
|
+
messages_api.send_audio(sender_id: 123123, recipient_number: 56789, link: "audio_link")
|
139
206
|
|
140
207
|
# with an audio id
|
141
|
-
messages_api.send_audio(sender_id: 123123, recipient_number:
|
208
|
+
messages_api.send_audio(sender_id: 123123, recipient_number: 56789, audio_id: "1234")
|
142
209
|
```
|
143
210
|
|
144
211
|
**Send a document message**
|
@@ -146,12 +213,12 @@ It could use a link or a document_id.
|
|
146
213
|
```ruby
|
147
214
|
# with a link
|
148
215
|
messages_api.send_document(
|
149
|
-
sender_id: 123123, recipient_number:
|
216
|
+
sender_id: 123123, recipient_number: 56789, link: "document_link", caption: "Ignacio Chiazzo"
|
150
217
|
)
|
151
218
|
|
152
219
|
# with a document id
|
153
220
|
messages_api.send_document(
|
154
|
-
sender_id: 123123, recipient_number:
|
221
|
+
sender_id: 123123, recipient_number: 56789, document_id: "1234", caption: "Ignacio Chiazzo"
|
155
222
|
)
|
156
223
|
```
|
157
224
|
|
@@ -159,10 +226,10 @@ messages_api.send_document(
|
|
159
226
|
It could use a link or a sticker_id.
|
160
227
|
```ruby
|
161
228
|
# with a link
|
162
|
-
messages_api.send_sticker(sender_id: 123123, recipient_number:
|
229
|
+
messages_api.send_sticker(sender_id: 123123, recipient_number: 56789, link: "link")
|
163
230
|
|
164
231
|
# with a sticker_id
|
165
|
-
messages_api.send_sticker(sender_id: 123123, recipient_number:
|
232
|
+
messages_api.send_sticker(sender_id: 123123, recipient_number: 56789, sticker_id: "1234")
|
166
233
|
```
|
167
234
|
|
168
235
|
**Send contacts message**
|
@@ -170,12 +237,12 @@ To send a contact, you need to create a Contact instance object that contain obj
|
|
170
237
|
|
171
238
|
```ruby
|
172
239
|
contacts = [create_contact(params)]
|
173
|
-
messages_api.send_contacts(sender_id: 123123, recipient_number:
|
240
|
+
messages_api.send_contacts(sender_id: 123123, recipient_number: 56789, contacts: contacts)
|
174
241
|
```
|
175
242
|
|
176
243
|
Alernative, you could pass a plain json like this:
|
177
244
|
```ruby
|
178
|
-
messages_api.send_contacts(sender_id: 123123, recipient_number:
|
245
|
+
messages_api.send_contacts(sender_id: 123123, recipient_number: 56789, contacts_json: {...})
|
179
246
|
```
|
180
247
|
|
181
248
|
**Send a template message**
|
@@ -190,46 +257,48 @@ currency = WhatsappSdk::Resource::Currency.new(code: "USD", amount: 1000, fallba
|
|
190
257
|
date_time = WhatsappSdk::Resource::DateTime.new(fallback_value: "2020-01-01T00:00:00Z")
|
191
258
|
image = WhatsappSdk::Resource::Media.new(type: "image", link: "http(s)://URL")
|
192
259
|
|
193
|
-
parameter_image = WhatsappSdk::Resource::ParameterObject.new(type:
|
194
|
-
|
195
|
-
|
196
|
-
|
260
|
+
parameter_image = WhatsappSdk::Resource::ParameterObject.new(type: WhatsappSdk::Resource::ParameterObject::Type::Image, image: image)
|
261
|
+
# You can also use a plain string as type e.g.
|
262
|
+
# parameter_image = WhatsappSdk::Resource::ParameterObject.new(type: "image", image: image)
|
263
|
+
parameter_text = WhatsappSdk::Resource::ParameterObject.new(type: WhatsappSdk::Resource::ParameterObject::Type::Text, text: "TEXT_STRING")
|
264
|
+
parameter_currency = WhatsappSdk::Resource::ParameterObject.new(type: WhatsappSdk::Resource::ParameterObject::Type::Currency, currency: currency)
|
265
|
+
parameter_date_time = WhatsappSdk::Resource::ParameterObject.new(type: WhatsappSdk::Resource::ParameterObject::Type::DateTime, date_time: date_time)
|
197
266
|
|
198
267
|
header_component = WhatsappSdk::Resource::Component.new(
|
199
|
-
type: WhatsappSdk::Resource::Component::Type::
|
268
|
+
type: WhatsappSdk::Resource::Component::Type::Header,
|
200
269
|
parameters: [parameter_image]
|
201
270
|
)
|
202
271
|
|
203
272
|
body_component = WhatsappSdk::Resource::Component.new(
|
204
|
-
type: WhatsappSdk::Resource::Component::Type::
|
273
|
+
type: WhatsappSdk::Resource::Component::Type::Body,
|
205
274
|
parameters: [parameter_text, parameter_currency, parameter_date_time]
|
206
275
|
)
|
207
276
|
|
208
277
|
button_component1 = WhatsappSdk::Resource::Component.new(
|
209
|
-
type: WhatsappSdk::Resource::Component::Type::
|
278
|
+
type: WhatsappSdk::Resource::Component::Type::Button,
|
210
279
|
index: 0,
|
211
|
-
sub_type: WhatsappSdk::Resource::Component::Subtype::
|
280
|
+
sub_type: WhatsappSdk::Resource::Component::Subtype::QuickReply,
|
212
281
|
parameters: [
|
213
|
-
WhatsappSdk::Resource::ButtonParameter.new(type:
|
282
|
+
WhatsappSdk::Resource::ButtonParameter.new(type: WhatsappSdk::Resource::ButtonParameter::Type::Payload, payload: "PAYLOAD")
|
214
283
|
]
|
215
284
|
)
|
216
285
|
|
217
286
|
button_component2 = WhatsappSdk::Resource::Component.new(
|
218
|
-
type: WhatsappSdk::Resource::Component::Type::
|
287
|
+
type: WhatsappSdk::Resource::Component::Type::Button,
|
219
288
|
index: 1,
|
220
|
-
sub_type: WhatsappSdk::Resource::Component::Subtype::
|
289
|
+
sub_type: WhatsappSdk::Resource::Component::Subtype::QuickReply,
|
221
290
|
parameters: [
|
222
|
-
WhatsappSdk::Resource::ButtonParameter.new(type:
|
291
|
+
WhatsappSdk::Resource::ButtonParameter.new(type: WhatsappSdk::Resource::ButtonParameter::Type::Payload, payload: "PAYLOAD")
|
223
292
|
]
|
224
293
|
)
|
225
|
-
@messages_api.send_template(sender_id: 12_345, recipient_number:
|
294
|
+
@messages_api.send_template(sender_id: 12_345, recipient_number: 12345678, name: "hello_world", language: "en_US", components_json: [component_1])
|
226
295
|
```
|
227
296
|
|
228
297
|
</details>
|
229
298
|
|
230
299
|
Alernative, you could pass a plain json like this:
|
231
300
|
```ruby
|
232
|
-
@messages_api.send_template(sender_id: 12_345, recipient_number:
|
301
|
+
@messages_api.send_template(sender_id: 12_345, recipient_number: 12345678, name: "hello_world", language: "en_US", components_json: [{...}])
|
233
302
|
```
|
234
303
|
|
235
304
|
## Example
|
@@ -244,7 +313,7 @@ Visit [the example file](/example.rb) with examples to call the API in a single
|
|
244
313
|
|
245
314
|
## Troubleshooting
|
246
315
|
|
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)
|
316
|
+
- 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)
|
248
317
|
|
249
318
|
## Development
|
250
319
|
|
@@ -256,6 +325,11 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
256
325
|
|
257
326
|
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.
|
258
327
|
|
328
|
+
### Run all the tests
|
329
|
+
- **Unit tests:** Run `rake test`
|
330
|
+
- **Sorbet Typecheck:** run `srb tc`
|
331
|
+
- **Linters:** `bundle exec rubocop`
|
332
|
+
|
259
333
|
## License
|
260
334
|
|
261
335
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
data/bin/tapioca
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
# typed: true
|
4
|
+
|
5
|
+
#
|
6
|
+
# This file was generated by Bundler.
|
7
|
+
#
|
8
|
+
# The application 'tapioca' is installed as part of a gem, and
|
9
|
+
# this file is here to facilitate running it.
|
10
|
+
#
|
11
|
+
|
12
|
+
require "pathname"
|
13
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
14
|
+
Pathname.new(__FILE__).realpath)
|
15
|
+
|
16
|
+
bundle_binstub = File.expand_path('bundle', __dir__)
|
17
|
+
|
18
|
+
if File.file?(bundle_binstub)
|
19
|
+
if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300))
|
20
|
+
load(bundle_binstub)
|
21
|
+
else
|
22
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
23
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
require "rubygems"
|
28
|
+
require "bundler/setup"
|
29
|
+
|
30
|
+
load Gem.bin_path("tapioca", "tapioca")
|