whatsapp_notifier 0.9.2 → 0.9.4
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/lib/generators/whatsapp_notifier/install_service_generator.rb +1 -0
- data/lib/whatsapp_notifier/client.rb +4 -0
- data/lib/whatsapp_notifier/providers/web_automation.rb +10 -0
- data/lib/whatsapp_notifier/services/web_automation/history.test.ts +93 -1
- data/lib/whatsapp_notifier/services/web_automation/history.ts +61 -5
- data/lib/whatsapp_notifier/services/web_automation/inbound.test.ts +90 -0
- data/lib/whatsapp_notifier/services/web_automation/inbound.ts +150 -39
- data/lib/whatsapp_notifier/services/web_automation/index.ts +91 -5
- data/lib/whatsapp_notifier/services/web_automation/message_id.test.ts +157 -0
- data/lib/whatsapp_notifier/services/web_automation/message_id.ts +146 -0
- data/lib/whatsapp_notifier/services/web_automation/send.test.ts +21 -1
- data/lib/whatsapp_notifier/services/web_automation/send.ts +15 -0
- data/lib/whatsapp_notifier/version.rb +1 -1
- data/lib/whatsapp_notifier/web_adapter.rb +27 -1
- data/lib/whatsapp_notifier.rb +4 -0
- data/spec/client_spec.rb +5 -2
- data/spec/generators/install_service_generator_spec.rb +2 -1
- data/spec/providers/web_automation_spec.rb +5 -1
- data/spec/web_adapter_spec.rb +31 -0
- data/spec/whatsapp_notifier_spec.rb +2 -0
- metadata +3 -1
data/spec/web_adapter_spec.rb
CHANGED
|
@@ -454,6 +454,37 @@ RSpec.describe WhatsAppNotifier::WebAdapter do
|
|
|
454
454
|
.to raise_error(/service request failed \(401\): User not authenticated/)
|
|
455
455
|
end
|
|
456
456
|
|
|
457
|
+
# Privacy-id resolution (0.9.3): the half a host needs to repair threads it
|
|
458
|
+
# already keyed on an unresolved @lid.
|
|
459
|
+
it "resolves a privacy id to bare phone digits" do
|
|
460
|
+
allow(ENV).to receive(:[]).and_call_original
|
|
461
|
+
allow(ENV).to receive(:[]).with("WHATSAPP_WEBHOOK_TOKEN").and_return("sekrit")
|
|
462
|
+
response = http_success(body: { "success" => true, "lid" => "125417440686124@lid", "pn" => "919882536803@c.us" })
|
|
463
|
+
captured = nil
|
|
464
|
+
http = double("http")
|
|
465
|
+
allow(http).to receive(:request) { |req| captured = req; response }
|
|
466
|
+
allow(Net::HTTP).to receive(:start) { |*_args, **_kwargs, &blk| blk.call(http) }
|
|
467
|
+
|
|
468
|
+
expect(adapter.resolve_lid(lid: "125417440686124@lid", metadata: { user_id: "u-1" }))
|
|
469
|
+
.to eq("919882536803")
|
|
470
|
+
expect(captured).to be_a(Net::HTTP::Get)
|
|
471
|
+
expect(captured.path).to eq("/contacts/lid/u-1?lid=125417440686124")
|
|
472
|
+
expect(captured["X-WA-Token"]).to eq("sekrit")
|
|
473
|
+
end
|
|
474
|
+
|
|
475
|
+
it "returns nil when the privacy id has no phone behind it" do
|
|
476
|
+
allow(Net::HTTP).to receive(:start)
|
|
477
|
+
.and_return(http_success(body: { "success" => true, "lid" => "1@lid", "pn" => nil }))
|
|
478
|
+
|
|
479
|
+
expect(adapter.resolve_lid(lid: "125417440686124", metadata: {})).to be_nil
|
|
480
|
+
end
|
|
481
|
+
|
|
482
|
+
it "does not call the service for a lid with no digits" do
|
|
483
|
+
expect(Net::HTTP).not_to receive(:start)
|
|
484
|
+
|
|
485
|
+
expect(adapter.resolve_lid(lid: "@lid", metadata: {})).to be_nil
|
|
486
|
+
end
|
|
487
|
+
|
|
457
488
|
it "fetches history with the token, posting the chat id and clamped limit" do
|
|
458
489
|
allow(ENV).to receive(:[]).and_call_original
|
|
459
490
|
allow(ENV).to receive(:[]).with("WHATSAPP_WEBHOOK_TOKEN").and_return("sekrit")
|
|
@@ -99,6 +99,7 @@ RSpec.describe WhatsAppNotifier do
|
|
|
99
99
|
allow(fake_client).to receive(:refetch_media).and_return(mime: "image/jpeg", filename: nil, size: 5, status: "available")
|
|
100
100
|
allow(fake_client).to receive(:list_chats).and_return([{ id: "919@c.us", name: "Asha", last_message_at: 9 }])
|
|
101
101
|
allow(fake_client).to receive(:fetch_history).and_return([{ from: "919@c.us", body: "old", message_id: "h1" }])
|
|
102
|
+
allow(fake_client).to receive(:resolve_lid).and_return("919882536803")
|
|
102
103
|
allow(fake_client).to receive(:logout).and_return(success: true)
|
|
103
104
|
described_class.instance_variable_set(:@client, fake_client)
|
|
104
105
|
|
|
@@ -111,6 +112,7 @@ RSpec.describe WhatsAppNotifier do
|
|
|
111
112
|
expect(described_class.refetch_media(message_id: "m1", chat_id: "919@c.us", provider: :web_automation, metadata: { user_id: 1 })).to include(status: "available")
|
|
112
113
|
expect(described_class.list_chats(provider: :web_automation, metadata: { user_id: 1 })).to eq([{ id: "919@c.us", name: "Asha", last_message_at: 9 }])
|
|
113
114
|
expect(described_class.fetch_history(chat_id: "919@c.us", limit: 20, provider: :web_automation, metadata: { user_id: 1 })).to eq([{ from: "919@c.us", body: "old", message_id: "h1" }])
|
|
115
|
+
expect(described_class.resolve_lid(lid: "125417440686124@lid", provider: :web_automation, metadata: { user_id: 1 })).to eq("919882536803")
|
|
114
116
|
expect(described_class.logout(provider: :web_automation, metadata: { user_id: 1 })).to eq(success: true)
|
|
115
117
|
expect(fake_client).to have_received(:fetch_media).with(message_id: "m1", provider: :web_automation, metadata: { user_id: 1 })
|
|
116
118
|
expect(fake_client).to have_received(:delete_media).with(message_id: "m1", provider: :web_automation, metadata: { user_id: 1 })
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: whatsapp_notifier
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.9.
|
|
4
|
+
version: 0.9.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kshitiz Sinha
|
|
@@ -91,6 +91,8 @@ files:
|
|
|
91
91
|
- lib/whatsapp_notifier/services/web_automation/init_gate.ts
|
|
92
92
|
- lib/whatsapp_notifier/services/web_automation/media.test.ts
|
|
93
93
|
- lib/whatsapp_notifier/services/web_automation/media.ts
|
|
94
|
+
- lib/whatsapp_notifier/services/web_automation/message_id.test.ts
|
|
95
|
+
- lib/whatsapp_notifier/services/web_automation/message_id.ts
|
|
94
96
|
- lib/whatsapp_notifier/services/web_automation/metrics.test.ts
|
|
95
97
|
- lib/whatsapp_notifier/services/web_automation/metrics.ts
|
|
96
98
|
- lib/whatsapp_notifier/services/web_automation/package.json
|