zapz 0.1.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/README.md +18 -0
- data/lib/zapz/client.rb +100 -0
- data/lib/zapz/resources/contacts_resource.rb +47 -0
- data/lib/zapz/resources/groups_resource.rb +73 -0
- data/lib/zapz/resources/instances_resource.rb +73 -0
- data/lib/zapz/resources/messages_resource.rb +365 -0
- data/lib/zapz/resources/sandbox_resource.rb +27 -0
- data/lib/zapz/resources/webhooks_resource.rb +52 -0
- data/lib/zapz/resources.rb +9 -0
- data/lib/zapz.rb +84 -0
- metadata +54 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 404f1a73677050a48a7850d2966cdfbe5270ea894fc1c4da9d5119adde0cf3bb
|
|
4
|
+
data.tar.gz: 9a4c29ed0ceeff39da044e781fa75f923856ce1ba4c3868a1b70489d5cf002e8
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 94ba6e6fe1439004f25326bd9875f0d13cf14f6eb122e41a1ffb24ade3aa3b007e93ba03e1c51fe0eeb9db2b5af9af043c878ac7690653a7418661ce27cbe54a
|
|
7
|
+
data.tar.gz: 13cc46884886c4b33ced0287ac9dac64b132ad415eacfa77676cc93e695ab3fba9ccd8429b6c63919e3c2c8bac8d1a9cf9942ed7e6588e9935c0398860bd9a4e
|
data/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# zapz (Ruby)
|
|
2
|
+
|
|
3
|
+
SDK oficial da API de WhatsApp da ZapZ para Ruby 3.0+. Só biblioteca padrão.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
gem install zapz
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
require "zapz"
|
|
11
|
+
|
|
12
|
+
zapz = ZapZ::Client.new # lê ZAPZ_API_KEY
|
|
13
|
+
msg = zapz.messages.send_text("INSTANCE_ID", { to: "5511999999999", text: "Olá!" })
|
|
14
|
+
puts msg["status"]
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
- Erros: `ZapZ::Error` (`status`, `code`, `retry_after`) e subclasses `ZapZ::NotFoundError`, `ZapZ::RateLimitError`…
|
|
18
|
+
- Webhooks (Rails): `ZapZ.verify_webhook(request.raw_post, request.headers, ENV["ZAPZ_WEBHOOK_SECRET"])`.
|
data/lib/zapz/client.rb
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "resources"
|
|
4
|
+
|
|
5
|
+
module ZapZ
|
|
6
|
+
# ZapZ API client. Bodies are hashes; responses are parsed JSON (hashes/arrays).
|
|
7
|
+
class Client
|
|
8
|
+
attr_reader :base_url, :instances, :messages, :contacts, :groups, :webhooks, :sandbox
|
|
9
|
+
|
|
10
|
+
# api_key defaults to ZAPZ_API_KEY; base_url to ZAPZ_BASE_URL, then production.
|
|
11
|
+
def initialize(api_key: nil, base_url: nil, timeout: 30, max_retries: 2)
|
|
12
|
+
@api_key = api_key || ENV["ZAPZ_API_KEY"]
|
|
13
|
+
raise Error, "Missing API key: pass api_key: or set ZAPZ_API_KEY." if @api_key.nil? || @api_key.empty?
|
|
14
|
+
|
|
15
|
+
url = (base_url || ENV["ZAPZ_BASE_URL"] || DEFAULT_BASE_URL).sub(%r{/+\z}, "")
|
|
16
|
+
@base_url = url.sub(%r{/v1\z}, "")
|
|
17
|
+
@timeout = timeout
|
|
18
|
+
@max_retries = max_retries
|
|
19
|
+
@instances = InstancesResource.new(self)
|
|
20
|
+
@messages = MessagesResource.new(self)
|
|
21
|
+
@contacts = ContactsResource.new(self)
|
|
22
|
+
@groups = GroupsResource.new(self)
|
|
23
|
+
@webhooks = WebhooksResource.new(self)
|
|
24
|
+
@sandbox = SandboxResource.new(self)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# True for sk_test_ keys (nothing reaches WhatsApp).
|
|
28
|
+
def sandbox?
|
|
29
|
+
@api_key.start_with?("sk_test_")
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def request(method, path, body: nil, query: nil, auto_client_message_id: false)
|
|
33
|
+
if auto_client_message_id && body.is_a?(Hash)
|
|
34
|
+
cid = body[:clientMessageId] || body["clientMessageId"]
|
|
35
|
+
body = body.merge(clientMessageId: SecureRandom.uuid) if cid.nil? || cid.to_s.empty?
|
|
36
|
+
end
|
|
37
|
+
uri = URI("#{@base_url}/v1#{path}")
|
|
38
|
+
q = (query || {}).compact
|
|
39
|
+
uri.query = URI.encode_www_form(q) unless q.empty?
|
|
40
|
+
payload = body.nil? ? nil : JSON.generate(body)
|
|
41
|
+
# a retry is safe when the request is idempotent or carries an idempotency key
|
|
42
|
+
idempotent = %i[get delete].include?(method) || (body.is_a?(Hash) && (body[:clientMessageId] || body["clientMessageId"]))
|
|
43
|
+
|
|
44
|
+
attempt = 0
|
|
45
|
+
loop do
|
|
46
|
+
req = Net::HTTPGenericRequest.new(method.to_s.upcase, !payload.nil?, true, uri.request_uri)
|
|
47
|
+
req["Authorization"] = "Bearer #{@api_key}"
|
|
48
|
+
req["Accept"] = "application/json"
|
|
49
|
+
req["User-Agent"] = "zapz-ruby/#{VERSION}"
|
|
50
|
+
if payload
|
|
51
|
+
req["Content-Type"] = "application/json"
|
|
52
|
+
req.body = payload
|
|
53
|
+
end
|
|
54
|
+
begin
|
|
55
|
+
res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https", open_timeout: [10, @timeout].min, read_timeout: @timeout) { |h| h.request(req) }
|
|
56
|
+
rescue StandardError => e
|
|
57
|
+
raise unless e.is_a?(IOError) || e.is_a?(SystemCallError) || e.is_a?(Timeout::Error) || e.is_a?(SocketError) || e.is_a?(OpenSSL::SSL::SSLError)
|
|
58
|
+
|
|
59
|
+
if idempotent && attempt < @max_retries
|
|
60
|
+
sleep(backoff(attempt))
|
|
61
|
+
attempt += 1
|
|
62
|
+
next
|
|
63
|
+
end
|
|
64
|
+
raise APIConnectionError, "Connection error: #{e.message}"
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
status = res.code.to_i
|
|
68
|
+
data = parse(res.body)
|
|
69
|
+
return data if status.between?(200, 299)
|
|
70
|
+
|
|
71
|
+
err = ZapZ.error_from_response(status, data, res["Retry-After"])
|
|
72
|
+
refused = [429, 503].include?(status)
|
|
73
|
+
transient = [502, 504].include?(status)
|
|
74
|
+
if attempt < @max_retries && (refused || (transient && idempotent))
|
|
75
|
+
wait = err.retry_after || backoff(attempt)
|
|
76
|
+
if wait <= 60
|
|
77
|
+
sleep(wait)
|
|
78
|
+
attempt += 1
|
|
79
|
+
next
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
raise err
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
private
|
|
87
|
+
|
|
88
|
+
def parse(raw)
|
|
89
|
+
return nil if raw.nil? || raw.strip.empty?
|
|
90
|
+
|
|
91
|
+
JSON.parse(raw)
|
|
92
|
+
rescue JSON::ParserError
|
|
93
|
+
raw
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def backoff(attempt)
|
|
97
|
+
[8.0, 0.5 * (2**attempt)].min * (0.75 + rand * 0.5)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Generated by generator/generate.py from openapi.json. Do not edit.
|
|
4
|
+
|
|
5
|
+
module ZapZ
|
|
6
|
+
# Contacts
|
|
7
|
+
class ContactsResource
|
|
8
|
+
def initialize(client)
|
|
9
|
+
@client = client
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# List contacts (+GET /v1/instances/{id}/contacts+).
|
|
13
|
+
def list(instance_id)
|
|
14
|
+
@client.request(:get, "/instances/#{ZapZ.escape(instance_id)}/contacts", body: nil, query: nil, auto_client_message_id: false)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Update a contact (+PATCH /v1/instances/{id}/contacts/{jid}+).
|
|
18
|
+
# - name (string)
|
|
19
|
+
# - notify (string)
|
|
20
|
+
# - imgUrl (string)
|
|
21
|
+
# - status (string)
|
|
22
|
+
def update(instance_id, jid, params = {})
|
|
23
|
+
@client.request(:patch, "/instances/#{ZapZ.escape(instance_id)}/contacts/#{ZapZ.escape(jid)}", body: params, query: nil, auto_client_message_id: false)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Delete a contact (+DELETE /v1/instances/{id}/contacts/{jid}+).
|
|
27
|
+
def delete(instance_id, jid)
|
|
28
|
+
@client.request(:delete, "/instances/#{ZapZ.escape(instance_id)}/contacts/#{ZapZ.escape(jid)}", body: nil, query: nil, auto_client_message_id: false)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Check which numbers have WhatsApp (+POST /v1/instances/{id}/contacts/check-phones+).
|
|
32
|
+
# - phones (list of string, required): Numbers with country code, digits only
|
|
33
|
+
def check_phones(instance_id, params)
|
|
34
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/contacts/check-phones", body: params, query: nil, auto_client_message_id: false)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Profile picture URL (+GET /v1/instances/{id}/contacts/{jid}/profile-picture+).
|
|
38
|
+
def profile_picture(instance_id, jid)
|
|
39
|
+
@client.request(:get, "/instances/#{ZapZ.escape(instance_id)}/contacts/#{ZapZ.escape(jid)}/profile-picture", body: nil, query: nil, auto_client_message_id: false)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Contact "about" text (+GET /v1/instances/{id}/contacts/{jid}/status+).
|
|
43
|
+
def about(instance_id, jid)
|
|
44
|
+
@client.request(:get, "/instances/#{ZapZ.escape(instance_id)}/contacts/#{ZapZ.escape(jid)}/status", body: nil, query: nil, auto_client_message_id: false)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Generated by generator/generate.py from openapi.json. Do not edit.
|
|
4
|
+
|
|
5
|
+
module ZapZ
|
|
6
|
+
# Groups
|
|
7
|
+
class GroupsResource
|
|
8
|
+
def initialize(client)
|
|
9
|
+
@client = client
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# List groups (+GET /v1/instances/{id}/groups+).
|
|
13
|
+
def list(instance_id, participants: nil)
|
|
14
|
+
@client.request(:get, "/instances/#{ZapZ.escape(instance_id)}/groups", body: nil, query: {participants: participants}, auto_client_message_id: false)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Create a group (+POST /v1/instances/{id}/groups+).
|
|
18
|
+
# - subject (string, required)
|
|
19
|
+
# - participants (list of string): Phones (digits, with country code). Optional: the connected number is always the owner.
|
|
20
|
+
def create(instance_id, params)
|
|
21
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/groups", body: params, query: nil, auto_client_message_id: false)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Preview a group from an invite code (+GET /v1/instances/{id}/groups/invite-info+).
|
|
25
|
+
def invite_info(instance_id, code: nil)
|
|
26
|
+
@client.request(:get, "/instances/#{ZapZ.escape(instance_id)}/groups/invite-info", body: nil, query: {code: code}, auto_client_message_id: false)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Join with an invite code (+POST /v1/instances/{id}/groups/join+).
|
|
30
|
+
# - code (string, required): Invite code or full link (https://chat.whatsapp.com/…)
|
|
31
|
+
def join(instance_id, params)
|
|
32
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/groups/join", body: params, query: nil, auto_client_message_id: false)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Get a group (+GET /v1/instances/{id}/groups/{groupId}+).
|
|
36
|
+
def get(instance_id, group_id)
|
|
37
|
+
@client.request(:get, "/instances/#{ZapZ.escape(instance_id)}/groups/#{ZapZ.escape(group_id)}", body: nil, query: nil, auto_client_message_id: false)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Update subject, description, picture or settings (+PATCH /v1/instances/{id}/groups/{groupId}+).
|
|
41
|
+
# - subject (string)
|
|
42
|
+
# - description (string): null or "" removes the description
|
|
43
|
+
# - announce (boolean): true = only admins send messages
|
|
44
|
+
# - locked (boolean): true = only admins edit group info
|
|
45
|
+
# - ephemeralSeconds (0 | 86400 | 604800 | 7776000): Disappearing messages: 0 (off), 86400 (24h), 604800 (7d) or 7776000 (90d)
|
|
46
|
+
# - pictureUrl (string): Image (JPEG, PNG or WebP) for the group picture
|
|
47
|
+
def update(instance_id, group_id, params = {})
|
|
48
|
+
@client.request(:patch, "/instances/#{ZapZ.escape(instance_id)}/groups/#{ZapZ.escape(group_id)}", body: params, query: nil, auto_client_message_id: false)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Add, remove, promote or demote (+POST /v1/instances/{id}/groups/{groupId}/participants+).
|
|
52
|
+
# - action (add | remove | promote | demote, required)
|
|
53
|
+
# - participants (list of string, required)
|
|
54
|
+
def update_participants(instance_id, group_id, params)
|
|
55
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/groups/#{ZapZ.escape(group_id)}/participants", body: params, query: nil, auto_client_message_id: false)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Invite link (+GET /v1/instances/{id}/groups/{groupId}/invite+).
|
|
59
|
+
def invite_link(instance_id, group_id)
|
|
60
|
+
@client.request(:get, "/instances/#{ZapZ.escape(instance_id)}/groups/#{ZapZ.escape(group_id)}/invite", body: nil, query: nil, auto_client_message_id: false)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Revoke the invite link (+POST /v1/instances/{id}/groups/{groupId}/invite/revoke+).
|
|
64
|
+
def revoke_invite(instance_id, group_id)
|
|
65
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/groups/#{ZapZ.escape(group_id)}/invite/revoke", body: nil, query: nil, auto_client_message_id: false)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Leave the group (+POST /v1/instances/{id}/groups/{groupId}/leave+).
|
|
69
|
+
def leave(instance_id, group_id)
|
|
70
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/groups/#{ZapZ.escape(group_id)}/leave", body: nil, query: nil, auto_client_message_id: false)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Generated by generator/generate.py from openapi.json. Do not edit.
|
|
4
|
+
|
|
5
|
+
module ZapZ
|
|
6
|
+
# Instances
|
|
7
|
+
class InstancesResource
|
|
8
|
+
def initialize(client)
|
|
9
|
+
@client = client
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# List instances (+GET /v1/instances+).
|
|
13
|
+
def list(external_id: nil, status: nil)
|
|
14
|
+
@client.request(:get, "/instances", body: nil, query: {externalId: external_id, status: status}, auto_client_message_id: false)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Create an instance (+POST /v1/instances+).
|
|
18
|
+
# - name (string, required)
|
|
19
|
+
# - externalId (string): Your id for this instance (unique per account). Creating again with the same externalId returns the existing instance.
|
|
20
|
+
# - metadata (object): Free-form JSON object (max 4 KB).
|
|
21
|
+
def create(params)
|
|
22
|
+
@client.request(:post, "/instances", body: params, query: nil, auto_client_message_id: false)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Get an instance (+GET /v1/instances/{id}+).
|
|
26
|
+
def get(instance_id)
|
|
27
|
+
@client.request(:get, "/instances/#{ZapZ.escape(instance_id)}", body: nil, query: nil, auto_client_message_id: false)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Rename or update an instance (+PATCH /v1/instances/{id}+).
|
|
31
|
+
# - name (string)
|
|
32
|
+
# - metadata (object)
|
|
33
|
+
def update(instance_id, params = {})
|
|
34
|
+
@client.request(:patch, "/instances/#{ZapZ.escape(instance_id)}", body: params, query: nil, auto_client_message_id: false)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Delete an instance (+DELETE /v1/instances/{id}+).
|
|
38
|
+
def delete(instance_id)
|
|
39
|
+
@client.request(:delete, "/instances/#{ZapZ.escape(instance_id)}", body: nil, query: nil, auto_client_message_id: false)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Connection status (+GET /v1/instances/{id}/status+).
|
|
43
|
+
def status(instance_id)
|
|
44
|
+
@client.request(:get, "/instances/#{ZapZ.escape(instance_id)}/status", body: nil, query: nil, auto_client_message_id: false)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# QR code to pair the phone (+GET /v1/instances/{id}/qr+).
|
|
48
|
+
def qr(instance_id)
|
|
49
|
+
@client.request(:get, "/instances/#{ZapZ.escape(instance_id)}/qr", body: nil, query: nil, auto_client_message_id: false)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Pair with a code instead of QR (+POST /v1/instances/{id}/pairing-code+).
|
|
53
|
+
# - phone (string, required): Phone number of the WhatsApp account to link: country code + number, digits only.
|
|
54
|
+
def request_pairing_code(instance_id, params)
|
|
55
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/pairing-code", body: params, query: nil, auto_client_message_id: false)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Log out and clear the session (+POST /v1/instances/{id}/session/clear+).
|
|
59
|
+
def clear_session(instance_id)
|
|
60
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/session/clear", body: nil, query: nil, auto_client_message_id: false)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Sending health and anti-ban state (+GET /v1/instances/{id}/health+).
|
|
64
|
+
def health(instance_id)
|
|
65
|
+
@client.request(:get, "/instances/#{ZapZ.escape(instance_id)}/health", body: nil, query: nil, auto_client_message_id: false)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Reconnect the session (+POST /v1/instances/{id}/resume+).
|
|
69
|
+
def resume(instance_id)
|
|
70
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/resume", body: nil, query: nil, auto_client_message_id: false)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Generated by generator/generate.py from openapi.json. Do not edit.
|
|
4
|
+
|
|
5
|
+
module ZapZ
|
|
6
|
+
# Messages
|
|
7
|
+
class MessagesResource
|
|
8
|
+
def initialize(client)
|
|
9
|
+
@client = client
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Send text (+POST /v1/instances/{id}/send/text+).
|
|
13
|
+
# - to (string, required)
|
|
14
|
+
# - text (string, required)
|
|
15
|
+
# - linkPreview (boolean): Card with title/image for the first URL in the text (default true).
|
|
16
|
+
# - clientMessageId (string): Optional id chosen by the client — idempotency key and correlation id in webhooks.
|
|
17
|
+
# - replyTo (string): WhatsApp id of a message (sent or received in the last 3 days) to reply to.
|
|
18
|
+
# - mentions (list of string): Phones to @mention (country code + number). Put "@<phone>" in the text where it should appear.
|
|
19
|
+
def send_text(instance_id, params)
|
|
20
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/send/text", body: params, query: nil, auto_client_message_id: true)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Send image, video, audio or document (+POST /v1/instances/{id}/send/media+).
|
|
24
|
+
# - to (string, required)
|
|
25
|
+
# - mediaType (image | video | audio | voice | document | gif | ptv, required): voice = voice note (PTT), gif = looping muted MP4, ptv = round video note
|
|
26
|
+
# - mediaUrl (string, required): Public http(s) URL. `mediaPath` is intentionally NOT accepted (it would read files on the engine host).
|
|
27
|
+
# - caption (string)
|
|
28
|
+
# - fileName (string)
|
|
29
|
+
# - viewOnce (boolean): Disappears after opened once (image, video and voice).
|
|
30
|
+
# - clientMessageId (string)
|
|
31
|
+
# - replyTo (string): WhatsApp id of a message (sent or received in the last 3 days) to reply to.
|
|
32
|
+
# - mentions (list of string): Phones to @mention (country code + number). Put "@<phone>" in the text where it should appear.
|
|
33
|
+
def send_media(instance_id, params)
|
|
34
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/send/media", body: params, query: nil, auto_client_message_id: true)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Send a list menu (+POST /v1/instances/{id}/send/list+).
|
|
38
|
+
# - text (string, required)
|
|
39
|
+
# - buttonText (string, required)
|
|
40
|
+
# - title (string)
|
|
41
|
+
# - footer (string)
|
|
42
|
+
# - sections (list of ListSection, required)
|
|
43
|
+
# - to (string, required)
|
|
44
|
+
# - clientMessageId (string): Optional id chosen by the client — idempotency key and correlation id in webhooks.
|
|
45
|
+
# - replyTo (string): WhatsApp id of a message (sent or received in the last 3 days) to reply to.
|
|
46
|
+
# - mentions (list of string): Phones to @mention (country code + number). Put "@<phone>" in the text where it should appear.
|
|
47
|
+
def send_list(instance_id, params)
|
|
48
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/send/list", body: params, query: nil, auto_client_message_id: true)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Send buttons (+POST /v1/instances/{id}/send/interactive+).
|
|
52
|
+
# - text (string, required)
|
|
53
|
+
# - title (string)
|
|
54
|
+
# - subtitle (string)
|
|
55
|
+
# - footer (string)
|
|
56
|
+
# - buttons (list of InteractiveButton, required)
|
|
57
|
+
# - image (MediaRef)
|
|
58
|
+
# - video (MediaRef)
|
|
59
|
+
# - to (string, required)
|
|
60
|
+
# - clientMessageId (string): Optional id chosen by the client — idempotency key and correlation id in webhooks.
|
|
61
|
+
# - replyTo (string): WhatsApp id of a message (sent or received in the last 3 days) to reply to.
|
|
62
|
+
# - mentions (list of string): Phones to @mention (country code + number). Put "@<phone>" in the text where it should appear.
|
|
63
|
+
def send_interactive(instance_id, params)
|
|
64
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/send/interactive", body: params, query: nil, auto_client_message_id: true)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Send a sticker (+POST /v1/instances/{id}/send/sticker+).
|
|
68
|
+
# - stickerUrl (string, required): Public http(s) URL of a WebP sticker
|
|
69
|
+
# - to (string, required)
|
|
70
|
+
# - clientMessageId (string): Optional id chosen by the client — idempotency key and correlation id in webhooks.
|
|
71
|
+
# - replyTo (string): WhatsApp id of a message (sent or received in the last 3 days) to reply to.
|
|
72
|
+
# - mentions (list of string): Phones to @mention (country code + number). Put "@<phone>" in the text where it should appear.
|
|
73
|
+
def send_sticker(instance_id, params)
|
|
74
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/send/sticker", body: params, query: nil, auto_client_message_id: true)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Send a location (+POST /v1/instances/{id}/send/location+).
|
|
78
|
+
# - latitude (number, required)
|
|
79
|
+
# - longitude (number, required)
|
|
80
|
+
# - name (string)
|
|
81
|
+
# - address (string)
|
|
82
|
+
# - live (boolean): Live location (shown as "sharing live location")
|
|
83
|
+
# - caption (string)
|
|
84
|
+
# - to (string, required)
|
|
85
|
+
# - clientMessageId (string): Optional id chosen by the client — idempotency key and correlation id in webhooks.
|
|
86
|
+
# - replyTo (string): WhatsApp id of a message (sent or received in the last 3 days) to reply to.
|
|
87
|
+
# - mentions (list of string): Phones to @mention (country code + number). Put "@<phone>" in the text where it should appear.
|
|
88
|
+
def send_location(instance_id, params)
|
|
89
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/send/location", body: params, query: nil, auto_client_message_id: true)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# Send a contact card (+POST /v1/instances/{id}/send/contact+).
|
|
93
|
+
# - displayName (string, required)
|
|
94
|
+
# - vcard (string, required)
|
|
95
|
+
# - to (string, required)
|
|
96
|
+
# - clientMessageId (string): Optional id chosen by the client — idempotency key and correlation id in webhooks.
|
|
97
|
+
# - replyTo (string): WhatsApp id of a message (sent or received in the last 3 days) to reply to.
|
|
98
|
+
# - mentions (list of string): Phones to @mention (country code + number). Put "@<phone>" in the text where it should appear.
|
|
99
|
+
def send_contact(instance_id, params)
|
|
100
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/send/contact", body: params, query: nil, auto_client_message_id: true)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# React to a message (+POST /v1/instances/{id}/send/reaction+).
|
|
104
|
+
# - messageId (string, required): WhatsApp id of the message being reacted to (externalId in our webhooks)
|
|
105
|
+
# - emoji (string, required): Emoji; empty string removes the reaction
|
|
106
|
+
# - fromMe (boolean): true when reacting to a message sent by this number
|
|
107
|
+
# - to (string, required)
|
|
108
|
+
# - clientMessageId (string): Optional id chosen by the client — idempotency key and correlation id in webhooks.
|
|
109
|
+
# - replyTo (string): WhatsApp id of a message (sent or received in the last 3 days) to reply to.
|
|
110
|
+
# - mentions (list of string): Phones to @mention (country code + number). Put "@<phone>" in the text where it should appear.
|
|
111
|
+
def send_reaction(instance_id, params)
|
|
112
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/send/reaction", body: params, query: nil, auto_client_message_id: true)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Send a poll (+POST /v1/instances/{id}/send/poll+).
|
|
116
|
+
# - name (string, required)
|
|
117
|
+
# - options (list of string, required)
|
|
118
|
+
# - selectableCount (number)
|
|
119
|
+
# - to (string, required)
|
|
120
|
+
# - clientMessageId (string): Optional id chosen by the client — idempotency key and correlation id in webhooks.
|
|
121
|
+
# - replyTo (string): WhatsApp id of a message (sent or received in the last 3 days) to reply to.
|
|
122
|
+
# - mentions (list of string): Phones to @mention (country code + number). Put "@<phone>" in the text where it should appear.
|
|
123
|
+
def send_poll(instance_id, params)
|
|
124
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/send/poll", body: params, query: nil, auto_client_message_id: true)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# Send a Pix charge (+POST /v1/instances/{id}/send/pix+).
|
|
128
|
+
# - text (string)
|
|
129
|
+
# - title (string)
|
|
130
|
+
# - footer (string)
|
|
131
|
+
# - merchantName (string, required): Name shown as the receiver
|
|
132
|
+
# - key (string, required): Pix key
|
|
133
|
+
# - keyType (CPF | CNPJ | EMAIL | PHONE | EVP, required): EVP = random key
|
|
134
|
+
# - amount (number): Amount in BRL shown on the card (optional)
|
|
135
|
+
# - description (string)
|
|
136
|
+
# - referenceId (string)
|
|
137
|
+
# - to (string, required)
|
|
138
|
+
# - clientMessageId (string): Optional id chosen by the client — idempotency key and correlation id in webhooks.
|
|
139
|
+
# - replyTo (string): WhatsApp id of a message (sent or received in the last 3 days) to reply to.
|
|
140
|
+
# - mentions (list of string): Phones to @mention (country code + number). Put "@<phone>" in the text where it should appear.
|
|
141
|
+
def send_pix(instance_id, params)
|
|
142
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/send/pix", body: params, query: nil, auto_client_message_id: true)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Send a payment request (+POST /v1/instances/{id}/send/payment+).
|
|
146
|
+
# - text (string)
|
|
147
|
+
# - currency (BRL)
|
|
148
|
+
# - referenceId (string, required)
|
|
149
|
+
# - items (list of PaymentItem, required)
|
|
150
|
+
# - note (string)
|
|
151
|
+
# - to (string, required)
|
|
152
|
+
# - clientMessageId (string): Optional id chosen by the client — idempotency key and correlation id in webhooks.
|
|
153
|
+
# - replyTo (string): WhatsApp id of a message (sent or received in the last 3 days) to reply to.
|
|
154
|
+
# - mentions (list of string): Phones to @mention (country code + number). Put "@<phone>" in the text where it should appear.
|
|
155
|
+
def send_payment(instance_id, params)
|
|
156
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/send/payment", body: params, query: nil, auto_client_message_id: true)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
# Send a carousel (+POST /v1/instances/{id}/send/carousel+).
|
|
160
|
+
# - text (string, required)
|
|
161
|
+
# - title (string)
|
|
162
|
+
# - subtitle (string)
|
|
163
|
+
# - footer (string)
|
|
164
|
+
# - cards (list of CarouselCard, required)
|
|
165
|
+
# - to (string, required)
|
|
166
|
+
# - clientMessageId (string): Optional id chosen by the client — idempotency key and correlation id in webhooks.
|
|
167
|
+
# - replyTo (string): WhatsApp id of a message (sent or received in the last 3 days) to reply to.
|
|
168
|
+
# - mentions (list of string): Phones to @mention (country code + number). Put "@<phone>" in the text where it should appear.
|
|
169
|
+
def send_carousel(instance_id, params)
|
|
170
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/send/carousel", body: params, query: nil, auto_client_message_id: true)
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
# Send an album (+POST /v1/instances/{id}/send/album+).
|
|
174
|
+
# - items (list of AlbumItem, required)
|
|
175
|
+
# - to (string, required)
|
|
176
|
+
# - clientMessageId (string): Optional id chosen by the client — idempotency key and correlation id in webhooks.
|
|
177
|
+
# - replyTo (string): WhatsApp id of a message (sent or received in the last 3 days) to reply to.
|
|
178
|
+
# - mentions (list of string): Phones to @mention (country code + number). Put "@<phone>" in the text where it should appear.
|
|
179
|
+
def send_album(instance_id, params)
|
|
180
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/send/album", body: params, query: nil, auto_client_message_id: true)
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
# Send an event invite (+POST /v1/instances/{id}/send/event+).
|
|
184
|
+
# - name (string, required)
|
|
185
|
+
# - description (string)
|
|
186
|
+
# - startTime (string, required)
|
|
187
|
+
# - endTime (string)
|
|
188
|
+
# - location (EventLocation)
|
|
189
|
+
# - call (audio | video): Adds a WhatsApp call link to the event
|
|
190
|
+
# - extraGuestsAllowed (boolean)
|
|
191
|
+
# - canceled (boolean)
|
|
192
|
+
# - to (string, required)
|
|
193
|
+
# - clientMessageId (string): Optional id chosen by the client — idempotency key and correlation id in webhooks.
|
|
194
|
+
# - replyTo (string): WhatsApp id of a message (sent or received in the last 3 days) to reply to.
|
|
195
|
+
# - mentions (list of string): Phones to @mention (country code + number). Put "@<phone>" in the text where it should appear.
|
|
196
|
+
def send_event(instance_id, params)
|
|
197
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/send/event", body: params, query: nil, auto_client_message_id: true)
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
# Send a group invite card (+POST /v1/instances/{id}/send/group-invite+).
|
|
201
|
+
# - groupJid (string, required)
|
|
202
|
+
# - inviteCode (string, required)
|
|
203
|
+
# - groupName (string, required)
|
|
204
|
+
# - caption (string)
|
|
205
|
+
# - expiration (number): Unix seconds; default 3 days
|
|
206
|
+
# - to (string, required)
|
|
207
|
+
# - clientMessageId (string): Optional id chosen by the client — idempotency key and correlation id in webhooks.
|
|
208
|
+
# - replyTo (string): WhatsApp id of a message (sent or received in the last 3 days) to reply to.
|
|
209
|
+
# - mentions (list of string): Phones to @mention (country code + number). Put "@<phone>" in the text where it should appear.
|
|
210
|
+
def send_group_invite(instance_id, params)
|
|
211
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/send/group-invite", body: params, query: nil, auto_client_message_id: true)
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
# Ask for the phone number (+POST /v1/instances/{id}/send/request-phone+).
|
|
215
|
+
# - to (string, required)
|
|
216
|
+
# - clientMessageId (string): Optional id chosen by the client — idempotency key and correlation id in webhooks.
|
|
217
|
+
# - replyTo (string): WhatsApp id of a message (sent or received in the last 3 days) to reply to.
|
|
218
|
+
# - mentions (list of string): Phones to @mention (country code + number). Put "@<phone>" in the text where it should appear.
|
|
219
|
+
def send_request_phone(instance_id, params)
|
|
220
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/send/request-phone", body: params, query: nil, auto_client_message_id: true)
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
# Share your phone number (+POST /v1/instances/{id}/send/share-phone+).
|
|
224
|
+
# - to (string, required)
|
|
225
|
+
# - clientMessageId (string): Optional id chosen by the client — idempotency key and correlation id in webhooks.
|
|
226
|
+
# - replyTo (string): WhatsApp id of a message (sent or received in the last 3 days) to reply to.
|
|
227
|
+
# - mentions (list of string): Phones to @mention (country code + number). Put "@<phone>" in the text where it should appear.
|
|
228
|
+
def send_share_phone(instance_id, params)
|
|
229
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/send/share-phone", body: params, query: nil, auto_client_message_id: true)
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
# Send a catalog product (+POST /v1/instances/{id}/send/product+).
|
|
233
|
+
# - imageUrl (string, required)
|
|
234
|
+
# - productId (string, required)
|
|
235
|
+
# - title (string, required)
|
|
236
|
+
# - description (string)
|
|
237
|
+
# - price (number, required)
|
|
238
|
+
# - salePrice (number)
|
|
239
|
+
# - currency (BRL)
|
|
240
|
+
# - retailerId (string)
|
|
241
|
+
# - url (string)
|
|
242
|
+
# - businessOwnerJid (string, required): Phone of the WhatsApp Business account that owns the catalog
|
|
243
|
+
# - text (string)
|
|
244
|
+
# - footer (string)
|
|
245
|
+
# - to (string, required)
|
|
246
|
+
# - clientMessageId (string): Optional id chosen by the client — idempotency key and correlation id in webhooks.
|
|
247
|
+
# - replyTo (string): WhatsApp id of a message (sent or received in the last 3 days) to reply to.
|
|
248
|
+
# - mentions (list of string): Phones to @mention (country code + number). Put "@<phone>" in the text where it should appear.
|
|
249
|
+
def send_product(instance_id, params)
|
|
250
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/send/product", body: params, query: nil, auto_client_message_id: true)
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
# Send an order (+POST /v1/instances/{id}/send/order+).
|
|
254
|
+
# - orderId (string, required)
|
|
255
|
+
# - token (string, required)
|
|
256
|
+
# - sellerJid (string, required)
|
|
257
|
+
# - title (string)
|
|
258
|
+
# - text (string)
|
|
259
|
+
# - itemCount (number)
|
|
260
|
+
# - total (number)
|
|
261
|
+
# - currency (BRL)
|
|
262
|
+
# - status (INQUIRY | ACCEPTED | DECLINED)
|
|
263
|
+
# - thumbnailUrl (string)
|
|
264
|
+
# - to (string, required)
|
|
265
|
+
# - clientMessageId (string): Optional id chosen by the client — idempotency key and correlation id in webhooks.
|
|
266
|
+
# - replyTo (string): WhatsApp id of a message (sent or received in the last 3 days) to reply to.
|
|
267
|
+
# - mentions (list of string): Phones to @mention (country code + number). Put "@<phone>" in the text where it should appear.
|
|
268
|
+
def send_order(instance_id, params)
|
|
269
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/send/order", body: params, query: nil, auto_client_message_id: true)
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
# Send the catalog link (+POST /v1/instances/{id}/send/catalog+).
|
|
273
|
+
# - text (string)
|
|
274
|
+
# - title (string)
|
|
275
|
+
# - subtitle (string)
|
|
276
|
+
# - footer (string)
|
|
277
|
+
# - imageUrl (string)
|
|
278
|
+
# - shopId (string): Storefront id (shop) — or use collection
|
|
279
|
+
# - surface (number)
|
|
280
|
+
# - collection (CollectionRef)
|
|
281
|
+
# - to (string, required)
|
|
282
|
+
# - clientMessageId (string): Optional id chosen by the client — idempotency key and correlation id in webhooks.
|
|
283
|
+
# - replyTo (string): WhatsApp id of a message (sent or received in the last 3 days) to reply to.
|
|
284
|
+
# - mentions (list of string): Phones to @mention (country code + number). Put "@<phone>" in the text where it should appear.
|
|
285
|
+
def send_catalog(instance_id, params)
|
|
286
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/send/catalog", body: params, query: nil, auto_client_message_id: true)
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
# Forward a message (+POST /v1/instances/{id}/send/forward+).
|
|
290
|
+
# - messageId (string, required): WhatsApp id of a message sent or received by this number in the last 3 days
|
|
291
|
+
# - to (string, required)
|
|
292
|
+
# - clientMessageId (string): Optional id chosen by the client — idempotency key and correlation id in webhooks.
|
|
293
|
+
# - replyTo (string): WhatsApp id of a message (sent or received in the last 3 days) to reply to.
|
|
294
|
+
# - mentions (list of string): Phones to @mention (country code + number). Put "@<phone>" in the text where it should appear.
|
|
295
|
+
def forward(instance_id, params)
|
|
296
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/send/forward", body: params, query: nil, auto_client_message_id: true)
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
# Pin or unpin a message (+POST /v1/instances/{id}/send/pin+).
|
|
300
|
+
# - messageId (string, required)
|
|
301
|
+
# - duration (24h | 7d | 30d)
|
|
302
|
+
# - unpin (boolean)
|
|
303
|
+
# - to (string, required)
|
|
304
|
+
# - clientMessageId (string): Optional id chosen by the client — idempotency key and correlation id in webhooks.
|
|
305
|
+
# - replyTo (string): WhatsApp id of a message (sent or received in the last 3 days) to reply to.
|
|
306
|
+
# - mentions (list of string): Phones to @mention (country code + number). Put "@<phone>" in the text where it should appear.
|
|
307
|
+
def pin(instance_id, params)
|
|
308
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/send/pin", body: params, query: nil, auto_client_message_id: true)
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
# Post a status (story) (+POST /v1/instances/{id}/send/status+).
|
|
312
|
+
# - type (text | image | video, required)
|
|
313
|
+
# - text (string)
|
|
314
|
+
# - url (string)
|
|
315
|
+
# - caption (string)
|
|
316
|
+
# - backgroundColor (string): Hex color for text statuses, e.g. #128C7E
|
|
317
|
+
# - font (number)
|
|
318
|
+
# - audience (list of string, required): Phones that will see the status (WhatsApp only shows it to contacts who have your number saved)
|
|
319
|
+
# - clientMessageId (string)
|
|
320
|
+
def send_status(instance_id, params)
|
|
321
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/send/status", body: params, query: nil, auto_client_message_id: true)
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
# List sent messages (+GET /v1/instances/{id}/messages+).
|
|
325
|
+
def list(instance_id, limit: nil)
|
|
326
|
+
@client.request(:get, "/instances/#{ZapZ.escape(instance_id)}/messages", body: nil, query: {limit: limit}, auto_client_message_id: false)
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
# List received messages (newest first) (+GET /v1/instances/{id}/messages/received+).
|
|
330
|
+
def list_received(instance_id, limit: nil, before: nil, since: nil, chat: nil, q: nil)
|
|
331
|
+
@client.request(:get, "/instances/#{ZapZ.escape(instance_id)}/messages/received", body: nil, query: {limit: limit, before: before, since: since, chat: chat, q: q}, auto_client_message_id: false)
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
# Get a message and its status (+GET /v1/instances/{id}/messages/{messageId}+).
|
|
335
|
+
def get(instance_id, message_id)
|
|
336
|
+
@client.request(:get, "/instances/#{ZapZ.escape(instance_id)}/messages/#{ZapZ.escape(message_id)}", body: nil, query: nil, auto_client_message_id: false)
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
# Edit a sent message (+PATCH /v1/instances/{id}/messages/{messageId}+).
|
|
340
|
+
# - text (string, required)
|
|
341
|
+
def edit(instance_id, message_id, params)
|
|
342
|
+
@client.request(:patch, "/instances/#{ZapZ.escape(instance_id)}/messages/#{ZapZ.escape(message_id)}", body: params, query: nil, auto_client_message_id: false)
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
# Delete a message for everyone (+DELETE /v1/instances/{id}/messages/{messageId}+).
|
|
346
|
+
def delete(instance_id, message_id)
|
|
347
|
+
@client.request(:delete, "/instances/#{ZapZ.escape(instance_id)}/messages/#{ZapZ.escape(message_id)}", body: nil, query: nil, auto_client_message_id: false)
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
# Mark messages as read (+POST /v1/instances/{id}/messages/read+).
|
|
351
|
+
# - chatId (string, required): Chat the messages belong to: phone (country code + number) or group jid.
|
|
352
|
+
# - messageIds (list of string, required): WhatsApp ids of the received messages (`data.id` / `key.id` of the incoming webhook).
|
|
353
|
+
# - participant (string): In groups: who sent the messages (phone).
|
|
354
|
+
def mark_read(instance_id, params)
|
|
355
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/messages/read", body: params, query: nil, auto_client_message_id: false)
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
# Typing / recording / online (+POST /v1/instances/{id}/presence+).
|
|
359
|
+
# - to (string, required)
|
|
360
|
+
# - presence (composing | recording | paused, required): composing = "digitando…", recording = "gravando áudio…", paused = stop.
|
|
361
|
+
def send_presence(instance_id, params)
|
|
362
|
+
@client.request(:post, "/instances/#{ZapZ.escape(instance_id)}/presence", body: params, query: nil, auto_client_message_id: false)
|
|
363
|
+
end
|
|
364
|
+
end
|
|
365
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Generated by generator/generate.py from openapi.json. Do not edit.
|
|
4
|
+
|
|
5
|
+
module ZapZ
|
|
6
|
+
# Sandbox
|
|
7
|
+
class SandboxResource
|
|
8
|
+
def initialize(client)
|
|
9
|
+
@client = client
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Simulate a received message (+POST /v1/sandbox/inbound+).
|
|
13
|
+
def inbound(params = {})
|
|
14
|
+
@client.request(:post, "/sandbox/inbound", body: params, query: nil, auto_client_message_id: false)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Fire any webhook event (+POST /v1/sandbox/events+).
|
|
18
|
+
def event(params = {})
|
|
19
|
+
@client.request(:post, "/sandbox/events", body: params, query: nil, auto_client_message_id: false)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Move a test message to a status (+POST /v1/sandbox/messages/{messageId}/status+).
|
|
23
|
+
def set_message_status(message_id, params = {})
|
|
24
|
+
@client.request(:post, "/sandbox/messages/#{ZapZ.escape(message_id)}/status", body: params, query: nil, auto_client_message_id: false)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Generated by generator/generate.py from openapi.json. Do not edit.
|
|
4
|
+
|
|
5
|
+
module ZapZ
|
|
6
|
+
# Webhooks
|
|
7
|
+
class WebhooksResource
|
|
8
|
+
def initialize(client)
|
|
9
|
+
@client = client
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# List webhooks (+GET /v1/webhooks+).
|
|
13
|
+
def list()
|
|
14
|
+
@client.request(:get, "/webhooks", body: nil, query: nil, auto_client_message_id: false)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Create a webhook (+POST /v1/webhooks+).
|
|
18
|
+
# - instance_id (string)
|
|
19
|
+
# - url (string, required)
|
|
20
|
+
# - events (list of string, required)
|
|
21
|
+
# - secret (string, required)
|
|
22
|
+
def create(params)
|
|
23
|
+
@client.request(:post, "/webhooks", body: params, query: nil, auto_client_message_id: false)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Update a webhook (+PATCH /v1/webhooks/{id}+).
|
|
27
|
+
# - url (string)
|
|
28
|
+
# - events (list of string)
|
|
29
|
+
# - secret (string)
|
|
30
|
+
# - active (boolean): true also lifts an automatic pause
|
|
31
|
+
# - instance_id (string)
|
|
32
|
+
def update(webhook_id, params = {})
|
|
33
|
+
@client.request(:patch, "/webhooks/#{ZapZ.escape(webhook_id)}", body: params, query: nil, auto_client_message_id: false)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Delete a webhook (+DELETE /v1/webhooks/{id}+).
|
|
37
|
+
def delete(webhook_id)
|
|
38
|
+
@client.request(:delete, "/webhooks/#{ZapZ.escape(webhook_id)}", body: nil, query: nil, auto_client_message_id: false)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Recent deliveries (+GET /v1/webhooks/{id}/logs+).
|
|
42
|
+
def deliveries(webhook_id)
|
|
43
|
+
@client.request(:get, "/webhooks/#{ZapZ.escape(webhook_id)}/logs", body: nil, query: nil, auto_client_message_id: false)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Send a test event (+POST /v1/webhooks/{id}/test+).
|
|
47
|
+
# - event (string): Event to simulate (default: the first subscribed event)
|
|
48
|
+
def test(webhook_id, params = {})
|
|
49
|
+
@client.request(:post, "/webhooks/#{ZapZ.escape(webhook_id)}/test", body: params, query: nil, auto_client_message_id: false)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Generated by generator/generate.py. Do not edit.
|
|
4
|
+
require_relative "resources/instances_resource"
|
|
5
|
+
require_relative "resources/messages_resource"
|
|
6
|
+
require_relative "resources/contacts_resource"
|
|
7
|
+
require_relative "resources/groups_resource"
|
|
8
|
+
require_relative "resources/webhooks_resource"
|
|
9
|
+
require_relative "resources/sandbox_resource"
|
data/lib/zapz.rb
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "net/http"
|
|
5
|
+
require "openssl"
|
|
6
|
+
require "securerandom"
|
|
7
|
+
require "uri"
|
|
8
|
+
|
|
9
|
+
# Official Ruby SDK for the ZapZ WhatsApp API (stdlib only).
|
|
10
|
+
#
|
|
11
|
+
# zapz = ZapZ::Client.new(api_key: "sk_live_...")
|
|
12
|
+
# zapz.messages.send_text("INSTANCE_ID", { to: "5511999999999", text: "Olá!" })
|
|
13
|
+
module ZapZ
|
|
14
|
+
VERSION = "0.1.0"
|
|
15
|
+
DEFAULT_BASE_URL = "https://api.zapz.dev"
|
|
16
|
+
|
|
17
|
+
def self.escape(value)
|
|
18
|
+
URI.encode_www_form_component(value.to_s).gsub("+", "%20")
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Base class for every error raised by the SDK.
|
|
22
|
+
class Error < StandardError
|
|
23
|
+
attr_reader :status, :code, :retry_after, :body
|
|
24
|
+
|
|
25
|
+
def initialize(message, status: nil, code: nil, retry_after: nil, body: nil)
|
|
26
|
+
super(message)
|
|
27
|
+
@status = status
|
|
28
|
+
@code = code
|
|
29
|
+
@retry_after = retry_after
|
|
30
|
+
@body = body
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
class APIConnectionError < Error; end
|
|
35
|
+
class ValidationError < Error; end
|
|
36
|
+
class AuthenticationError < Error; end
|
|
37
|
+
class PermissionDeniedError < Error; end
|
|
38
|
+
class NotFoundError < Error; end
|
|
39
|
+
class ConflictError < Error; end
|
|
40
|
+
class RateLimitError < Error; end
|
|
41
|
+
class InternalServerError < Error; end
|
|
42
|
+
class WebhookVerificationError < Error; end
|
|
43
|
+
|
|
44
|
+
def self.error_from_response(status, body, retry_header)
|
|
45
|
+
data = body.is_a?(Hash) ? body : {}
|
|
46
|
+
msg = data["message"]
|
|
47
|
+
msg = msg.join("; ") if msg.is_a?(Array)
|
|
48
|
+
message = msg ? msg.to_s : "HTTP #{status}"
|
|
49
|
+
retry_after = data["retryAfter"] || (retry_header && Float(retry_header, exception: false))
|
|
50
|
+
code = data["error"].is_a?(String) ? data["error"] : nil
|
|
51
|
+
klass = case status
|
|
52
|
+
when 400, 422 then ValidationError
|
|
53
|
+
when 401 then AuthenticationError
|
|
54
|
+
when 403 then PermissionDeniedError
|
|
55
|
+
when 404 then NotFoundError
|
|
56
|
+
when 409 then ConflictError
|
|
57
|
+
when 429 then RateLimitError
|
|
58
|
+
else status >= 500 ? InternalServerError : Error
|
|
59
|
+
end
|
|
60
|
+
klass.new(message, status: status, code: code, retry_after: retry_after&.to_f, body: body)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Verifies X-Webhook-Signature-V2 against the RAW body and returns the parsed event.
|
|
64
|
+
# event = ZapZ.verify_webhook(request.raw_post, request.headers, ENV["ZAPZ_WEBHOOK_SECRET"])
|
|
65
|
+
def self.verify_webhook(raw_body, headers, secret, tolerance: 300)
|
|
66
|
+
find = lambda do |name|
|
|
67
|
+
pair = headers.to_h.find { |k, _| k.to_s.downcase.tr("_", "-").sub(/\Ahttp-/, "") == name }
|
|
68
|
+
pair && (pair[1].is_a?(Array) ? pair[1].first : pair[1])
|
|
69
|
+
end
|
|
70
|
+
ts = find.call("x-webhook-timestamp")
|
|
71
|
+
sig = find.call("x-webhook-signature-v2")
|
|
72
|
+
raise WebhookVerificationError, "Missing X-Webhook-Timestamp or X-Webhook-Signature-V2 header" unless ts && sig && ts.to_s.match?(/\A\d+\z/)
|
|
73
|
+
raise WebhookVerificationError, "Webhook timestamp outside the tolerance window" if (Time.now.to_i - ts.to_i).abs > tolerance
|
|
74
|
+
|
|
75
|
+
expected = "sha256=" + OpenSSL::HMAC.hexdigest("SHA256", secret, "#{ts}.#{raw_body}")
|
|
76
|
+
raise WebhookVerificationError, "Invalid webhook signature" unless expected.bytesize == sig.bytesize && OpenSSL.fixed_length_secure_compare(expected, sig)
|
|
77
|
+
|
|
78
|
+
JSON.parse(raw_body)
|
|
79
|
+
rescue JSON::ParserError
|
|
80
|
+
raise WebhookVerificationError, "Webhook body is not valid JSON"
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
require_relative "zapz/client"
|
metadata
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: zapz
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- ZapZ
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-11-25 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description:
|
|
14
|
+
email:
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- README.md
|
|
20
|
+
- lib/zapz.rb
|
|
21
|
+
- lib/zapz/client.rb
|
|
22
|
+
- lib/zapz/resources.rb
|
|
23
|
+
- lib/zapz/resources/contacts_resource.rb
|
|
24
|
+
- lib/zapz/resources/groups_resource.rb
|
|
25
|
+
- lib/zapz/resources/instances_resource.rb
|
|
26
|
+
- lib/zapz/resources/messages_resource.rb
|
|
27
|
+
- lib/zapz/resources/sandbox_resource.rb
|
|
28
|
+
- lib/zapz/resources/webhooks_resource.rb
|
|
29
|
+
homepage: https://zapz.dev
|
|
30
|
+
licenses:
|
|
31
|
+
- MIT
|
|
32
|
+
metadata:
|
|
33
|
+
source_code_uri: https://github.com/zapz-api/zapz-sdk/tree/main/ruby
|
|
34
|
+
bug_tracker_uri: https://github.com/zapz-api/zapz-sdk/issues
|
|
35
|
+
post_install_message:
|
|
36
|
+
rdoc_options: []
|
|
37
|
+
require_paths:
|
|
38
|
+
- lib
|
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: '3.0'
|
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - ">="
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: '0'
|
|
49
|
+
requirements: []
|
|
50
|
+
rubygems_version: 3.5.22
|
|
51
|
+
signing_key:
|
|
52
|
+
specification_version: 4
|
|
53
|
+
summary: Official Ruby SDK for the ZapZ WhatsApp API
|
|
54
|
+
test_files: []
|