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