blueticks 1.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/CHANGELOG.md +21 -0
- data/LICENSE +21 -0
- data/README.md +85 -0
- data/lib/blueticks/base_resource.rb +12 -0
- data/lib/blueticks/client.rb +107 -0
- data/lib/blueticks/errors.rb +108 -0
- data/lib/blueticks/resources/account.rb +18 -0
- data/lib/blueticks/resources/audiences.rb +69 -0
- data/lib/blueticks/resources/campaigns.rb +52 -0
- data/lib/blueticks/resources/chats.rb +95 -0
- data/lib/blueticks/resources/contacts.rb +27 -0
- data/lib/blueticks/resources/engines.rb +32 -0
- data/lib/blueticks/resources/groups.rb +58 -0
- data/lib/blueticks/resources/messages.rb +48 -0
- data/lib/blueticks/resources/ping.rb +16 -0
- data/lib/blueticks/resources/scheduled_messages.rb +51 -0
- data/lib/blueticks/resources/utils.rb +23 -0
- data/lib/blueticks/resources/webhooks.rb +52 -0
- data/lib/blueticks/transport.rb +161 -0
- data/lib/blueticks/types/account.rb +15 -0
- data/lib/blueticks/types/audiences.rb +29 -0
- data/lib/blueticks/types/base.rb +158 -0
- data/lib/blueticks/types/campaigns.rb +28 -0
- data/lib/blueticks/types/chats.rb +51 -0
- data/lib/blueticks/types/contacts.rb +17 -0
- data/lib/blueticks/types/engines.rb +20 -0
- data/lib/blueticks/types/groups.rb +27 -0
- data/lib/blueticks/types/messages.rb +25 -0
- data/lib/blueticks/types/page.rb +45 -0
- data/lib/blueticks/types/ping.rb +14 -0
- data/lib/blueticks/types/scheduled_messages.rb +23 -0
- data/lib/blueticks/types/utils.rb +19 -0
- data/lib/blueticks/types/webhooks.rb +41 -0
- data/lib/blueticks/version.rb +5 -0
- data/lib/blueticks/webhooks.rb +112 -0
- data/lib/blueticks.rb +35 -0
- metadata +124 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: c36b093b9a84f49a90a4879b8c804dfbcbaef3facbce8e8e6d55d1a14977d9f7
|
|
4
|
+
data.tar.gz: befdb19cf0c64e60eec29804a03b202987e28d26c9ca3502e1ec96591eca7ac2
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e5004e9c6a34d01463d01d2e094ed9a86b18cd3b464ad8ca1796336fdb4d60b0f195fbdc976a69be862f672ce90c755f4a2f56231e86f633300e719ff20e4f6b
|
|
7
|
+
data.tar.gz: 731a42669ae6dc5dd916edb3a12c6939ea5a3ab9dff35e269c622e25cd2c8e420b2d41d91854bafbf2fd2f743bab0eea52f2de68b1daf8502fd22c07c87d1667
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to the Blueticks Ruby SDK are documented here. The format
|
|
4
|
+
follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and this
|
|
5
|
+
project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## 1.0.0 — 2026-04-30
|
|
8
|
+
|
|
9
|
+
Initial release.
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `Blueticks::Client` with explicit-arg / `BLUETICKS_API_KEY` /
|
|
14
|
+
`BLUETICKS_BASE_URL` configuration.
|
|
15
|
+
- Resources: `account`, `ping`, `messages`, `webhooks`, `chats`, `audiences`,
|
|
16
|
+
`campaigns`, `groups`, `engines`, `contacts`, `utils`.
|
|
17
|
+
- Typed response DTOs under `Blueticks::Types::*` with shape validation.
|
|
18
|
+
- `Blueticks::Webhooks.verify` for HMAC-SHA256 signature verification of
|
|
19
|
+
Blueticks webhooks (raises `Blueticks::Errors::WebhookVerificationError`).
|
|
20
|
+
- Automatic retry with exponential backoff for idempotent requests on 429 / 5xx.
|
|
21
|
+
- Stdlib-only implementation (uses `net/http`, `openssl`, `json`).
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Blueticks
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Blueticks Ruby SDK
|
|
2
|
+
|
|
3
|
+
Official Ruby client for the [Blueticks API](https://dev.blueticks.co/docs/api).
|
|
4
|
+
Send WhatsApp messages, manage audiences, run campaigns, and verify webhooks.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```ruby
|
|
9
|
+
# Gemfile
|
|
10
|
+
gem "blueticks"
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
bundle install
|
|
15
|
+
# or:
|
|
16
|
+
gem install blueticks
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Requires Ruby 3.0 or later. No runtime dependencies — only stdlib.
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```ruby
|
|
24
|
+
require "blueticks"
|
|
25
|
+
|
|
26
|
+
client = Blueticks::Client.new(api_key: ENV["BLUETICKS_API_KEY"])
|
|
27
|
+
|
|
28
|
+
message = client.messages.send(to: "12025550100", text: "Hello from Ruby!")
|
|
29
|
+
puts message.id
|
|
30
|
+
puts message.status
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The client falls back to `ENV["BLUETICKS_API_KEY"]` and `ENV["BLUETICKS_BASE_URL"]`
|
|
34
|
+
if you don't pass them explicitly.
|
|
35
|
+
|
|
36
|
+
### Resources
|
|
37
|
+
|
|
38
|
+
- `client.account`
|
|
39
|
+
- `client.ping`
|
|
40
|
+
- `client.messages`
|
|
41
|
+
- `client.webhooks`
|
|
42
|
+
- `client.chats`
|
|
43
|
+
- `client.audiences`
|
|
44
|
+
- `client.campaigns`
|
|
45
|
+
- `client.groups`
|
|
46
|
+
- `client.engines`
|
|
47
|
+
- `client.contacts`
|
|
48
|
+
- `client.utils`
|
|
49
|
+
|
|
50
|
+
### Webhook signature verification
|
|
51
|
+
|
|
52
|
+
```ruby
|
|
53
|
+
event = Blueticks::Webhooks.verify(
|
|
54
|
+
payload: request.raw_post,
|
|
55
|
+
headers: request.headers,
|
|
56
|
+
secret: ENV["BLUETICKS_WEBHOOK_SECRET"]
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
puts event.type # "message.delivered"
|
|
60
|
+
puts event.data # Hash with the event payload
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Raises `Blueticks::Errors::WebhookVerificationError` if the signature, timestamp,
|
|
64
|
+
or payload doesn't match.
|
|
65
|
+
|
|
66
|
+
### Errors
|
|
67
|
+
|
|
68
|
+
All API failures raise subclasses of `Blueticks::Errors::BluetickError`:
|
|
69
|
+
|
|
70
|
+
- `AuthenticationError` (401)
|
|
71
|
+
- `PermissionDeniedError` (403)
|
|
72
|
+
- `NotFoundError` (404)
|
|
73
|
+
- `BadRequestError` (400 / 422)
|
|
74
|
+
- `RateLimitError` (429)
|
|
75
|
+
- `APIError` (5xx and other unrecognized statuses)
|
|
76
|
+
- `APIConnectionError` (network failures)
|
|
77
|
+
- `ValidationError` (response payload didn't match the expected shape)
|
|
78
|
+
|
|
79
|
+
## Documentation
|
|
80
|
+
|
|
81
|
+
Full API reference: <https://dev.blueticks.co/docs/api>
|
|
82
|
+
|
|
83
|
+
## License
|
|
84
|
+
|
|
85
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "errors"
|
|
4
|
+
require_relative "transport"
|
|
5
|
+
require_relative "resources/scheduled_messages"
|
|
6
|
+
|
|
7
|
+
module Blueticks
|
|
8
|
+
# Top-level entry point. Construct one and access resources via accessor methods:
|
|
9
|
+
#
|
|
10
|
+
# client = Blueticks::Client.new(api_key: "bt_live_...")
|
|
11
|
+
# client.messages.send(to: "12025550100", text: "Hello!")
|
|
12
|
+
#
|
|
13
|
+
# Configuration order of precedence:
|
|
14
|
+
# 1. Explicit keyword args.
|
|
15
|
+
# 2. Environment variables: BLUETICKS_API_KEY, BLUETICKS_BASE_URL.
|
|
16
|
+
# 3. Defaults (base_url => https://api.blueticks.co).
|
|
17
|
+
class Client
|
|
18
|
+
DEFAULT_BASE_URL = "https://api.blueticks.co"
|
|
19
|
+
|
|
20
|
+
attr_reader :transport
|
|
21
|
+
|
|
22
|
+
def initialize(api_key: nil, base_url: nil, timeout: 30.0, max_retries: 3,
|
|
23
|
+
user_agent: nil, http: nil)
|
|
24
|
+
api_key = resolve_api_key(api_key)
|
|
25
|
+
base_url = resolve_base_url(base_url)
|
|
26
|
+
|
|
27
|
+
@transport = Transport.new(
|
|
28
|
+
api_key: api_key,
|
|
29
|
+
base_url: base_url,
|
|
30
|
+
timeout: timeout,
|
|
31
|
+
max_retries: max_retries,
|
|
32
|
+
user_agent: user_agent,
|
|
33
|
+
http: http
|
|
34
|
+
)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Issue a raw request. Used internally by resource classes.
|
|
38
|
+
def request(method, path, params: nil, body: nil, idempotency_key: nil)
|
|
39
|
+
@transport.request(method, path, params: params, body: body, idempotency_key: idempotency_key)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def account
|
|
43
|
+
@account ||= Resources::AccountResource.new(self)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def ping
|
|
47
|
+
@ping ||= Resources::PingResource.new(self)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def messages
|
|
51
|
+
@messages ||= Resources::MessagesResource.new(self)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def scheduled_messages
|
|
55
|
+
@scheduled_messages ||= Resources::ScheduledMessagesResource.new(self)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def webhooks
|
|
59
|
+
@webhooks ||= Resources::WebhooksResource.new(self)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def chats
|
|
63
|
+
@chats ||= Resources::ChatsResource.new(self)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def audiences
|
|
67
|
+
@audiences ||= Resources::AudiencesResource.new(self)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def campaigns
|
|
71
|
+
@campaigns ||= Resources::CampaignsResource.new(self)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def groups
|
|
75
|
+
@groups ||= Resources::GroupsResource.new(self)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def engines
|
|
79
|
+
@engines ||= Resources::EnginesResource.new(self)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def contacts
|
|
83
|
+
@contacts ||= Resources::ContactsResource.new(self)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def utils
|
|
87
|
+
@utils ||= Resources::UtilsResource.new(self)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
private
|
|
91
|
+
|
|
92
|
+
def resolve_api_key(api_key)
|
|
93
|
+
key = api_key || ENV.fetch("BLUETICKS_API_KEY", nil)
|
|
94
|
+
if key.nil? || key.to_s.empty?
|
|
95
|
+
raise Errors::BluetickError.new(
|
|
96
|
+
message: "api_key is required (pass api_key: or set BLUETICKS_API_KEY)"
|
|
97
|
+
)
|
|
98
|
+
end
|
|
99
|
+
key
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def resolve_base_url(base_url)
|
|
103
|
+
url = base_url || ENV.fetch("BLUETICKS_BASE_URL", nil) || DEFAULT_BASE_URL
|
|
104
|
+
url.to_s
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Blueticks
|
|
4
|
+
module Errors
|
|
5
|
+
# Base class for all Blueticks SDK errors.
|
|
6
|
+
class BluetickError < StandardError
|
|
7
|
+
attr_reader :status_code, :code, :request_id, :response
|
|
8
|
+
|
|
9
|
+
def initialize(message: "", status_code: nil, code: nil, request_id: nil, response: nil)
|
|
10
|
+
@status_code = status_code
|
|
11
|
+
@code = code
|
|
12
|
+
@request_id = request_id
|
|
13
|
+
@response = response
|
|
14
|
+
super(format_message(message))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def format_message(message)
|
|
20
|
+
"#{status_code} #{code}: #{message} (request_id=#{request_id})"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# 401 — missing or invalid API key.
|
|
25
|
+
class AuthenticationError < BluetickError; end
|
|
26
|
+
|
|
27
|
+
# 403 — the key lacks the required scope or workspace access.
|
|
28
|
+
class PermissionDeniedError < BluetickError; end
|
|
29
|
+
|
|
30
|
+
# 404 — the resource does not exist.
|
|
31
|
+
class NotFoundError < BluetickError; end
|
|
32
|
+
|
|
33
|
+
# 400 / 422 — the request was malformed or failed validation.
|
|
34
|
+
class BadRequestError < BluetickError; end
|
|
35
|
+
|
|
36
|
+
# 429 — the client is being throttled.
|
|
37
|
+
class RateLimitError < BluetickError
|
|
38
|
+
attr_reader :retry_after
|
|
39
|
+
|
|
40
|
+
def initialize(retry_after: nil, **kwargs)
|
|
41
|
+
super(**kwargs)
|
|
42
|
+
@retry_after = retry_after
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# 5xx or otherwise-unparseable error response from the API.
|
|
47
|
+
class APIError < BluetickError; end
|
|
48
|
+
|
|
49
|
+
# Network failure: DNS, TLS, timeout, connection reset.
|
|
50
|
+
class APIConnectionError < BluetickError; end
|
|
51
|
+
|
|
52
|
+
# Raised when a response payload fails type/shape validation.
|
|
53
|
+
class ValidationError < BluetickError; end
|
|
54
|
+
|
|
55
|
+
# Raised when a webhook signature cannot be verified.
|
|
56
|
+
class WebhookVerificationError < BluetickError
|
|
57
|
+
def initialize(reason)
|
|
58
|
+
super(
|
|
59
|
+
message: reason,
|
|
60
|
+
status_code: nil,
|
|
61
|
+
code: "webhook_verification_failed",
|
|
62
|
+
request_id: nil
|
|
63
|
+
)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
STATUS_TO_CLASS = {
|
|
68
|
+
400 => BadRequestError,
|
|
69
|
+
401 => AuthenticationError,
|
|
70
|
+
403 => PermissionDeniedError,
|
|
71
|
+
404 => NotFoundError,
|
|
72
|
+
422 => BadRequestError,
|
|
73
|
+
429 => RateLimitError
|
|
74
|
+
}.freeze
|
|
75
|
+
|
|
76
|
+
module_function
|
|
77
|
+
|
|
78
|
+
# Map a non-2xx response body to a typed Blueticks exception.
|
|
79
|
+
def from_envelope(status_code:, body:, response: nil, retry_after: nil)
|
|
80
|
+
cls = STATUS_TO_CLASS.fetch(status_code, APIError)
|
|
81
|
+
err = body.is_a?(Hash) ? body["error"] : nil
|
|
82
|
+
|
|
83
|
+
if err.is_a?(Hash) && err["code"].is_a?(String)
|
|
84
|
+
kwargs = {
|
|
85
|
+
status_code: status_code,
|
|
86
|
+
code: err["code"],
|
|
87
|
+
message: err["message"].to_s,
|
|
88
|
+
request_id: err["request_id"],
|
|
89
|
+
response: response
|
|
90
|
+
}
|
|
91
|
+
kwargs[:retry_after] = retry_after if cls == RateLimitError
|
|
92
|
+
return cls.new(**kwargs)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
raw = body.is_a?(String) ? body : body.inspect
|
|
96
|
+
truncated = raw.length > 200 ? "#{raw[0, 200]}..." : raw
|
|
97
|
+
kwargs = {
|
|
98
|
+
status_code: status_code,
|
|
99
|
+
code: nil,
|
|
100
|
+
message: truncated,
|
|
101
|
+
request_id: nil,
|
|
102
|
+
response: response
|
|
103
|
+
}
|
|
104
|
+
kwargs[:retry_after] = retry_after if cls == RateLimitError
|
|
105
|
+
cls.new(**kwargs)
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../base_resource"
|
|
4
|
+
require_relative "../types/account"
|
|
5
|
+
|
|
6
|
+
module Blueticks
|
|
7
|
+
module Resources
|
|
8
|
+
class AccountResource < BaseResource
|
|
9
|
+
# Retrieve the authenticated account.
|
|
10
|
+
#
|
|
11
|
+
# Returns the account associated with the API key used for this request.
|
|
12
|
+
def retrieve
|
|
13
|
+
data = client.request("GET", "/v1/account")
|
|
14
|
+
Types::Account.from_hash(data)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../base_resource"
|
|
4
|
+
require_relative "../types/audiences"
|
|
5
|
+
require_relative "../types/page"
|
|
6
|
+
|
|
7
|
+
module Blueticks
|
|
8
|
+
module Resources
|
|
9
|
+
class AudiencesResource < BaseResource
|
|
10
|
+
def create(name:, contacts: nil)
|
|
11
|
+
body = { "name" => name }
|
|
12
|
+
body["contacts"] = contacts unless contacts.nil?
|
|
13
|
+
data = client.request("POST", "/v1/audiences", body: body)
|
|
14
|
+
Types::Audience.from_hash(data)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# List audiences, newest first. Cursor-paginated.
|
|
18
|
+
def list(limit: nil, cursor: nil)
|
|
19
|
+
params = {}
|
|
20
|
+
params["limit"] = limit unless limit.nil?
|
|
21
|
+
params["cursor"] = cursor unless cursor.nil?
|
|
22
|
+
data = client.request("GET", "/v1/audiences", params: params.empty? ? nil : params)
|
|
23
|
+
Types::Page.from_hash(data, item_type: Types::Audience)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def get(audience_id, page: nil)
|
|
27
|
+
params = page.nil? ? nil : { "page" => page }
|
|
28
|
+
data = client.request("GET", "/v1/audiences/#{audience_id}", params: params)
|
|
29
|
+
Types::Audience.from_hash(data)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def update(audience_id, name:)
|
|
33
|
+
data = client.request("PATCH", "/v1/audiences/#{audience_id}", body: { "name" => name })
|
|
34
|
+
Types::Audience.from_hash(data)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def delete(audience_id)
|
|
38
|
+
client.request("DELETE", "/v1/audiences/#{audience_id}")
|
|
39
|
+
nil
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def append_contacts(audience_id, contacts:)
|
|
43
|
+
data = client.request(
|
|
44
|
+
"POST",
|
|
45
|
+
"/v1/audiences/#{audience_id}/contacts",
|
|
46
|
+
body: { "contacts" => contacts }
|
|
47
|
+
)
|
|
48
|
+
Types::AppendContactsResult.from_hash(data)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def update_contact(audience_id, contact_id, to: nil, variables: nil)
|
|
52
|
+
body = {}
|
|
53
|
+
body["to"] = to unless to.nil?
|
|
54
|
+
body["variables"] = variables unless variables.nil?
|
|
55
|
+
data = client.request(
|
|
56
|
+
"PATCH",
|
|
57
|
+
"/v1/audiences/#{audience_id}/contacts/#{contact_id}",
|
|
58
|
+
body: body
|
|
59
|
+
)
|
|
60
|
+
Types::Contact.from_hash(data)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def delete_contact(audience_id, contact_id)
|
|
64
|
+
client.request("DELETE", "/v1/audiences/#{audience_id}/contacts/#{contact_id}")
|
|
65
|
+
nil
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../base_resource"
|
|
4
|
+
require_relative "../types/campaigns"
|
|
5
|
+
require_relative "../types/page"
|
|
6
|
+
|
|
7
|
+
module Blueticks
|
|
8
|
+
module Resources
|
|
9
|
+
class CampaignsResource < BaseResource
|
|
10
|
+
def create(name:, audience_id:, text: nil, media_url: nil, media_caption: nil,
|
|
11
|
+
from: nil, on_missing_variable: nil)
|
|
12
|
+
body = { "name" => name, "audience_id" => audience_id }
|
|
13
|
+
body["text"] = text unless text.nil?
|
|
14
|
+
body["media_url"] = media_url unless media_url.nil?
|
|
15
|
+
body["media_caption"] = media_caption unless media_caption.nil?
|
|
16
|
+
body["from"] = from unless from.nil?
|
|
17
|
+
body["on_missing_variable"] = on_missing_variable unless on_missing_variable.nil?
|
|
18
|
+
data = client.request("POST", "/v1/campaigns", body: body)
|
|
19
|
+
Types::Campaign.from_hash(data)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# List campaigns, newest first. Cursor-paginated.
|
|
23
|
+
def list(limit: nil, cursor: nil)
|
|
24
|
+
params = {}
|
|
25
|
+
params["limit"] = limit unless limit.nil?
|
|
26
|
+
params["cursor"] = cursor unless cursor.nil?
|
|
27
|
+
data = client.request("GET", "/v1/campaigns", params: params.empty? ? nil : params)
|
|
28
|
+
Types::Page.from_hash(data, item_type: Types::Campaign)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def get(campaign_id)
|
|
32
|
+
data = client.request("GET", "/v1/campaigns/#{campaign_id}")
|
|
33
|
+
Types::Campaign.from_hash(data)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def pause(campaign_id)
|
|
37
|
+
data = client.request("POST", "/v1/campaigns/#{campaign_id}/pause")
|
|
38
|
+
Types::Campaign.from_hash(data)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def resume(campaign_id)
|
|
42
|
+
data = client.request("POST", "/v1/campaigns/#{campaign_id}/resume")
|
|
43
|
+
Types::Campaign.from_hash(data)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def cancel(campaign_id)
|
|
47
|
+
data = client.request("POST", "/v1/campaigns/#{campaign_id}/cancel")
|
|
48
|
+
Types::Campaign.from_hash(data)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../base_resource"
|
|
4
|
+
require_relative "../types/chats"
|
|
5
|
+
require_relative "../types/page"
|
|
6
|
+
|
|
7
|
+
module Blueticks
|
|
8
|
+
module Resources
|
|
9
|
+
class ChatsResource < BaseResource
|
|
10
|
+
# List/search chats, newest first. Cursor-paginated.
|
|
11
|
+
def list(query: nil, limit: nil, cursor: nil)
|
|
12
|
+
params = {}
|
|
13
|
+
params["query"] = query unless query.nil?
|
|
14
|
+
params["limit"] = limit unless limit.nil?
|
|
15
|
+
params["cursor"] = cursor unless cursor.nil?
|
|
16
|
+
data = client.request("GET", "/v1/chats", params: params.empty? ? nil : params)
|
|
17
|
+
Types::Page.from_hash(data, item_type: Types::Chat)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Retrieve a chat by its JID.
|
|
21
|
+
def get(chat_id)
|
|
22
|
+
data = client.request("GET", "/v1/chats/#{chat_id}")
|
|
23
|
+
Types::Chat.from_hash(data)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# List participants in a group chat. Cursor-paginated.
|
|
27
|
+
def list_participants(chat_id, limit: nil, cursor: nil)
|
|
28
|
+
params = {}
|
|
29
|
+
params["limit"] = limit unless limit.nil?
|
|
30
|
+
params["cursor"] = cursor unless cursor.nil?
|
|
31
|
+
data = client.request("GET", "/v1/chats/#{chat_id}/participants",
|
|
32
|
+
params: params.empty? ? nil : params)
|
|
33
|
+
Types::Page.from_hash(data, item_type: Types::Participant)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Mark a chat as read (sends read receipts if enabled).
|
|
37
|
+
def mark_read(chat_id)
|
|
38
|
+
client.request("POST", "/v1/chats/#{chat_id}/mark_read")
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Open a chat on the engine (useful for UI-assisted workflows).
|
|
42
|
+
def open(chat_id)
|
|
43
|
+
client.request("POST", "/v1/chats/#{chat_id}/open")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# List messages in a chat. `mode` is "latest" or "history".
|
|
47
|
+
def list_messages(chat_id, mode: "latest", query: nil, since: nil, until_: nil,
|
|
48
|
+
message_types: nil, limit: nil, cursor: nil)
|
|
49
|
+
params = { "mode" => mode }
|
|
50
|
+
params["query"] = query unless query.nil?
|
|
51
|
+
params["since"] = since unless since.nil?
|
|
52
|
+
params["until"] = until_ unless until_.nil?
|
|
53
|
+
params["message_types"] = message_types.join(",") if message_types && !message_types.empty?
|
|
54
|
+
params["limit"] = limit unless limit.nil?
|
|
55
|
+
params["cursor"] = cursor unless cursor.nil?
|
|
56
|
+
data = client.request("GET", "/v1/chats/#{chat_id}/messages", params: params)
|
|
57
|
+
Types::Page.from_hash(data, item_type: Types::ChatMessage)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def get_message(chat_id, key)
|
|
61
|
+
data = client.request("GET", "/v1/chats/#{chat_id}/messages/#{key}")
|
|
62
|
+
Types::ChatMessage.from_hash(data)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def get_message_ack(chat_id, key)
|
|
66
|
+
client.request("GET", "/v1/chats/#{chat_id}/messages/#{key}/ack")
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def react(chat_id, key, emoji:)
|
|
70
|
+
client.request(
|
|
71
|
+
"POST",
|
|
72
|
+
"/v1/chats/#{chat_id}/messages/#{key}/reactions",
|
|
73
|
+
body: { "emoji" => emoji }
|
|
74
|
+
)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def load_older_messages(chat_id)
|
|
78
|
+
client.request("POST", "/v1/chats/#{chat_id}/messages/load_older")
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def get_media(chat_id, key)
|
|
82
|
+
data = client.request("GET", "/v1/chats/#{chat_id}/messages/#{key}/media")
|
|
83
|
+
Types::ChatMedia.from_hash(data)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def batch_message_acks(message_keys:)
|
|
87
|
+
client.request(
|
|
88
|
+
"POST",
|
|
89
|
+
"/v1/chats/message_acks",
|
|
90
|
+
body: { "message_keys" => message_keys }
|
|
91
|
+
)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../base_resource"
|
|
4
|
+
require_relative "../types/contacts"
|
|
5
|
+
require_relative "../types/page"
|
|
6
|
+
|
|
7
|
+
module Blueticks
|
|
8
|
+
module Resources
|
|
9
|
+
class ContactsResource < BaseResource
|
|
10
|
+
# Search the user's WhatsApp contacts. Cursor-paginated.
|
|
11
|
+
def list(query: nil, limit: nil, cursor: nil)
|
|
12
|
+
params = {}
|
|
13
|
+
params["query"] = query unless query.nil?
|
|
14
|
+
params["limit"] = limit unless limit.nil?
|
|
15
|
+
params["cursor"] = cursor unless cursor.nil?
|
|
16
|
+
data = client.request("GET", "/v1/contacts", params: params.empty? ? nil : params)
|
|
17
|
+
Types::Page.from_hash(data, item_type: Types::WhatsAppContact)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Retrieve the CDN URL for a contact's profile picture.
|
|
21
|
+
def get_profile_picture(chat_id)
|
|
22
|
+
data = client.request("GET", "/v1/contacts/#{chat_id}/profile_picture")
|
|
23
|
+
Types::ProfilePicture.from_hash(data)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../base_resource"
|
|
4
|
+
require_relative "../types/engines"
|
|
5
|
+
|
|
6
|
+
module Blueticks
|
|
7
|
+
module Resources
|
|
8
|
+
class EnginesResource < BaseResource
|
|
9
|
+
# Current connection status of the user's WhatsApp engine.
|
|
10
|
+
def status
|
|
11
|
+
data = client.request("GET", "/v1/engines")
|
|
12
|
+
Types::EngineStatus.from_hash(data)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Authenticated WhatsApp account profile (phone, pushname, platform).
|
|
16
|
+
def me
|
|
17
|
+
data = client.request("GET", "/v1/engines/me")
|
|
18
|
+
Types::WhatsAppMe.from_hash(data)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Force the engine to log out of WhatsApp Web.
|
|
22
|
+
def logout
|
|
23
|
+
client.request("POST", "/v1/engines/logout")
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Force the engine's WhatsApp Web tab to reload.
|
|
27
|
+
def reload
|
|
28
|
+
client.request("POST", "/v1/engines/reload")
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|