From 245f3843e9a1cbb63c1d033b72c63d4d7d0d614a Mon Sep 17 00:00:00 2001 From: Christopher Vollick <0@psycoti.ca> Date: Tue, 14 Feb 2023 17:58:26 -0500 Subject: [PATCH] Don't Count Stanzas Without Body as Reached We get messages without bodies from time to time as things like delivery receipts. These are great, and we don't want to forward them to the end-user for sure if we're dealing with a reachable number, but we also don't want to count it as a message that reached us. It's a receipt for a thing I did, not a thing the tester did. --- lib/reachability_repo.rb | 19 +++++++++++++++++-- sgx_jmp.rb | 9 +++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/reachability_repo.rb b/lib/reachability_repo.rb index 341d81c6643276c71ae9993590c4808f21801ea9..b0fc127f88c51bcf6f4abeb1cdbc612940318ca0 100644 --- a/lib/reachability_repo.rb +++ b/lib/reachability_repo.rb @@ -39,13 +39,28 @@ class ReachabilityRepo end end + # This one is for things that don't have a body. + # I still don't want to deliver them to the user, but I don't want to count + # them as a message either + class Ignore + def filter(if_yes: ->(_) {}, **) + EMPromise.resolve(if_yes.call(nil)) + end + end + + ACCEPTABLE_STANZA = Blather::Stanza::Message.new(nil, "I'm cool").freeze + # The customer is who is being contacted # The initiator is the phone number trying to reach them - def find(customer, initiator) + def find(customer, initiator, stanza: ACCEPTABLE_STANZA) return EMPromise.resolve(NotTest.new) unless potential?(initiator) testing?(customer).then do |active| - active ? Test.new(redis, key(customer)) : NotTest.new + if active + stanza.body ? Test.new(redis, key(customer)) : Ignore.new + else + NotTest.new + end end end diff --git a/sgx_jmp.rb b/sgx_jmp.rb index 3262feeab40722d0b24d60e2798ccbc446410fbc..480828b4b999c643c89d6211e1dc8c1fd5b606e3 100644 --- a/sgx_jmp.rb +++ b/sgx_jmp.rb @@ -282,11 +282,12 @@ before nil, to: /\Acustomer_/, from: /(\A|@)#{CONFIG[:sgx]}(\/|\Z)/ do |s| CustomerRepo.new(set_user: Sentry.method(:set_user)).find( s.to.node.delete_prefix("customer_") ).then do |customer| - ReachabilityRepo::SMS.new.find(customer, s.from.node).then do |reach| - reach.filter do - customer.stanza_to(s) + ReachabilityRepo::SMS.new + .find(customer, s.from.node, stanza: s).then do |reach| + reach.filter do + customer.stanza_to(s) + end end - end end halt