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.
@@ -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
@@ -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