whatsapp_notifier 0.6.0 → 0.8.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 +4 -4
- data/README.md +20 -3
- data/lib/generators/whatsapp_notifier/install_service_generator.rb +3 -0
- data/lib/whatsapp_notifier/client.rb +20 -0
- data/lib/whatsapp_notifier/providers/web_automation.rb +54 -0
- data/lib/whatsapp_notifier/services/web_automation/history.test.ts +695 -0
- data/lib/whatsapp_notifier/services/web_automation/history.ts +323 -0
- data/lib/whatsapp_notifier/services/web_automation/inbound.test.ts +357 -2
- data/lib/whatsapp_notifier/services/web_automation/inbound.ts +228 -18
- data/lib/whatsapp_notifier/services/web_automation/index.ts +123 -41
- data/lib/whatsapp_notifier/services/web_automation/media.test.ts +751 -0
- data/lib/whatsapp_notifier/services/web_automation/media.ts +548 -0
- data/lib/whatsapp_notifier/services/web_automation/send.test.ts +20 -0
- data/lib/whatsapp_notifier/services/web_automation/send.ts +17 -0
- data/lib/whatsapp_notifier/version.rb +1 -1
- data/lib/whatsapp_notifier/web_adapter.rb +199 -13
- data/lib/whatsapp_notifier.rb +20 -0
- data/spec/client_spec.rb +48 -0
- data/spec/generators/install_service_generator_spec.rb +12 -1
- data/spec/providers/web_automation_spec.rb +97 -0
- data/spec/web_adapter_spec.rb +407 -0
- data/spec/whatsapp_notifier_spec.rb +33 -0
- metadata +7 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e65ad0d6844d9762bccd0a929a9d70613a0e9fb145564b75c35f196fc87e4088
|
|
4
|
+
data.tar.gz: 109a415b4a618aac44d5ce9da4f886590a600e8bdb9168ada01e740e9b5add9f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 45cbd20b37120dd2b533db5fa28b31dddbbbb00a06538c5a8c75cccd458d2f598c9d2089b898ed890b8cb88693613849d8ca036743d96bbba0d482cf121c70b4
|
|
7
|
+
data.tar.gz: e63080fe514ff18d3f225baebeefef3856b10f83d80087c7c7a33e3b50cc5a150cdc4a964646520a5f866685c13dd08c14f0a8888bed93fc2df5403676eab93a
|
data/README.md
CHANGED
|
@@ -57,9 +57,11 @@ status = WhatsAppNotifier.connection_status(metadata: { user_id: current_user.id
|
|
|
57
57
|
## Log out (disconnect + clear session)
|
|
58
58
|
|
|
59
59
|
Explicitly disconnects the user and wipes their saved WhatsApp session from the
|
|
60
|
-
service
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
service — including any downloaded inbound media and queued replies, which
|
|
61
|
+
belong to the old pairing — so the next connect starts fresh with a new QR.
|
|
62
|
+
Call this from a user-initiated "Log out WhatsApp" action — NOT from your
|
|
63
|
+
app's sign-out, which should leave the WhatsApp session intact for the next
|
|
64
|
+
login.
|
|
63
65
|
|
|
64
66
|
```ruby
|
|
65
67
|
WhatsAppNotifier.logout(metadata: { user_id: current_user.id })
|
|
@@ -144,6 +146,21 @@ creates a WhatsApp client — so it is safe to poll every few seconds:
|
|
|
144
146
|
those have a fully hydrated WhatsApp Web store. Prometheus metrics live at
|
|
145
147
|
`GET /metrics`.
|
|
146
148
|
|
|
149
|
+
## Upgrading to 0.7.0
|
|
150
|
+
|
|
151
|
+
- **If your app monkey-patches `WhatsAppNotifier::WebAdapter#request`** (a
|
|
152
|
+
common trick to bolt TLS onto the service URL): the shared JSON path now
|
|
153
|
+
also carries `DELETE` (`delete_media`) and attaches `X-WA-Token` when
|
|
154
|
+
`WHATSAPP_WEBHOOK_TOKEN` is set. A patch that only routes `POST`/`GET` or
|
|
155
|
+
drops headers will break the new media calls. Prefer retiring the patch
|
|
156
|
+
entirely — the adapter now honors `https://` service URLs natively on both
|
|
157
|
+
the JSON control plane and the binary media path (`use_ssl` follows the URL
|
|
158
|
+
scheme), so TLS no longer needs a patch.
|
|
159
|
+
- **Logout now wipes stored media**: `POST /logout` removes the user's
|
|
160
|
+
downloaded inbound media along with the session dir and queued replies.
|
|
161
|
+
Fetch (and ideally `delete_media`) anything you want to keep before logging
|
|
162
|
+
a user out.
|
|
163
|
+
|
|
147
164
|
## Notes
|
|
148
165
|
|
|
149
166
|
- This gem uses WhatsApp Web automation. Use responsibly and follow WhatsApp policies.
|
|
@@ -31,6 +31,26 @@ module WhatsAppNotifier
|
|
|
31
31
|
provider_for(provider || @configuration.provider).fetch_inbound(metadata: metadata)
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
+
def fetch_media(message_id:, metadata: {}, provider: nil)
|
|
35
|
+
provider_for(provider || @configuration.provider).fetch_media(message_id: message_id, metadata: metadata)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def delete_media(message_id:, metadata: {}, provider: nil)
|
|
39
|
+
provider_for(provider || @configuration.provider).delete_media(message_id: message_id, metadata: metadata)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def refetch_media(message_id:, chat_id:, metadata: {}, provider: nil)
|
|
43
|
+
provider_for(provider || @configuration.provider).refetch_media(message_id: message_id, chat_id: chat_id, metadata: metadata)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def list_chats(metadata: {}, provider: nil)
|
|
47
|
+
provider_for(provider || @configuration.provider).list_chats(metadata: metadata)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def fetch_history(chat_id:, limit: 50, metadata: {}, provider: nil)
|
|
51
|
+
provider_for(provider || @configuration.provider).fetch_history(chat_id: chat_id, limit: limit, metadata: metadata)
|
|
52
|
+
end
|
|
53
|
+
|
|
34
54
|
def logout(metadata: {}, provider: nil)
|
|
35
55
|
provider_for(provider || @configuration.provider).logout(metadata: metadata)
|
|
36
56
|
end
|
|
@@ -61,6 +61,60 @@ module WhatsAppNotifier
|
|
|
61
61
|
adapter.fetch_inbound(metadata: metadata)
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
+
# Media helpers are optional adapter capabilities (added in v0.7.0) —
|
|
65
|
+
# same guard idiom as fetch_inbound so older adapters fail with a clear
|
|
66
|
+
# ConfigurationError rather than NoMethodError.
|
|
67
|
+
def fetch_media(message_id:, metadata: {})
|
|
68
|
+
raise ConfigurationError, "web automation provider is disabled" unless configuration.web_automation_enabled
|
|
69
|
+
|
|
70
|
+
adapter = configuration.web_adapter
|
|
71
|
+
raise ConfigurationError, "web_adapter does not support media fetch (upgrade to a fetch_media-capable adapter)" unless adapter.respond_to?(:fetch_media)
|
|
72
|
+
|
|
73
|
+
adapter.fetch_media(message_id: message_id, metadata: metadata)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def delete_media(message_id:, metadata: {})
|
|
77
|
+
raise ConfigurationError, "web automation provider is disabled" unless configuration.web_automation_enabled
|
|
78
|
+
|
|
79
|
+
adapter = configuration.web_adapter
|
|
80
|
+
raise ConfigurationError, "web_adapter does not support media deletion (upgrade to a delete_media-capable adapter)" unless adapter.respond_to?(:delete_media)
|
|
81
|
+
|
|
82
|
+
adapter.delete_media(message_id: message_id, metadata: metadata)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# On-demand media re-download (added in v0.8.0) — same guard idiom as
|
|
86
|
+
# fetch_media so older adapters fail with a clear ConfigurationError
|
|
87
|
+
# rather than NoMethodError.
|
|
88
|
+
def refetch_media(message_id:, chat_id:, metadata: {})
|
|
89
|
+
raise ConfigurationError, "web automation provider is disabled" unless configuration.web_automation_enabled
|
|
90
|
+
|
|
91
|
+
adapter = configuration.web_adapter
|
|
92
|
+
raise ConfigurationError, "web_adapter does not support media refetch (upgrade to a refetch_media-capable adapter)" unless adapter.respond_to?(:refetch_media)
|
|
93
|
+
|
|
94
|
+
adapter.refetch_media(message_id: message_id, chat_id: chat_id, metadata: metadata)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Chat-history helpers are optional adapter capabilities (added in
|
|
98
|
+
# v0.8.0) — same guard idiom as fetch_media so older adapters fail with
|
|
99
|
+
# a clear ConfigurationError rather than NoMethodError.
|
|
100
|
+
def list_chats(metadata: {})
|
|
101
|
+
raise ConfigurationError, "web automation provider is disabled" unless configuration.web_automation_enabled
|
|
102
|
+
|
|
103
|
+
adapter = configuration.web_adapter
|
|
104
|
+
raise ConfigurationError, "web_adapter does not support chat listing (upgrade to a list_chats-capable adapter)" unless adapter.respond_to?(:list_chats)
|
|
105
|
+
|
|
106
|
+
adapter.list_chats(metadata: metadata)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def fetch_history(chat_id:, limit: 50, metadata: {})
|
|
110
|
+
raise ConfigurationError, "web automation provider is disabled" unless configuration.web_automation_enabled
|
|
111
|
+
|
|
112
|
+
adapter = configuration.web_adapter
|
|
113
|
+
raise ConfigurationError, "web_adapter does not support history replay (upgrade to a fetch_history-capable adapter)" unless adapter.respond_to?(:fetch_history)
|
|
114
|
+
|
|
115
|
+
adapter.fetch_history(chat_id: chat_id, limit: limit, metadata: metadata)
|
|
116
|
+
end
|
|
117
|
+
|
|
64
118
|
def logout(metadata: {})
|
|
65
119
|
raise ConfigurationError, "web automation provider is disabled" unless configuration.web_automation_enabled
|
|
66
120
|
|