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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a84b4298c91af2e175b2a8aa46fd2b9101e5b5729558f1387325a8c39894a31
4
- data.tar.gz: e11b629a0b342288eb8199ed95eaf6aa72f9d7ce557984c76e71b58f2e37bb4c
3
+ metadata.gz: e65ad0d6844d9762bccd0a929a9d70613a0e9fb145564b75c35f196fc87e4088
4
+ data.tar.gz: 109a415b4a618aac44d5ce9da4f886590a600e8bdb9168ada01e740e9b5add9f
5
5
  SHA512:
6
- metadata.gz: ed49385c1ea444b94a1ee99ca5ec1c891145bb5474a63544e314a715f85dab8712b743908ce1765efd9c1981b476287c62ed24930061a5fb5a667f2ff781011a
7
- data.tar.gz: 5b7eaec3a131a137edc5ce9dcba1e7cadcabe74bf210ef167975bb6952ac087b803a31d573f6c67b62f188be8d6c6593cd503a371cbdf57e91337a3ddf06f14e
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, so the next connect starts fresh with a new QR. Call this from a
61
- user-initiated "Log out WhatsApp" actionNOT from your app's sign-out, which
62
- should leave the WhatsApp session intact for the next login.
60
+ service including any downloaded inbound media and queued replies, which
61
+ belong to the old pairingso 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.
@@ -12,9 +12,12 @@ module WhatsAppNotifier
12
12
  # host app. The app rebuilds deps with `bun install`.
13
13
  SERVICE_FILES = %w[
14
14
  index.ts
15
+ history.ts
15
16
  inbound.ts
16
17
  init_gate.ts
18
+ media.ts
17
19
  metrics.ts
20
+ send.ts
18
21
  sessions.ts
19
22
  package.json
20
23
  bun.lock
@@ -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