~singpolyma/sgx-jmp

2c2975dc710f964eb398e5deef5616837cb63f82 — Stephen Paul Weber 1 year, 10 days ago a4621ec
Import group-text fix from prod
1 files changed, 25 insertions(+), 2 deletions(-)

M sgx_jmp.rb
M sgx_jmp.rb => sgx_jmp.rb +25 -2
@@ 168,9 168,32 @@ before nil, to: /\Acustomer_/, from: /(\A|@)#{CONFIG[:sgx]}(\/|\Z)/ do |s|
	halt
end

# Ignore messages to component
ADDRESSES_NS = "http://jabber.org/protocol/address"
message(
	to: /\A#{CONFIG[:component][:jid]}\Z/,
	from: /(\A|@)#{CONFIG[:sgx]}(\/|\Z)/
) do |m|
	StatsD.increment("inbound_group_text")
	sentry_hub = new_sentry_hub(m, name: "message")

	address = m.find("ns:addresses", ns: ADDRESSES_NS).first
		&.find("ns:address", ns: ADDRESSES_NS)
		&.find { |el| el["jid"].to_s.start_with?("customer_") }
	pass unless address

	Customer.for_customer_id(
		Blather::JID.new(address["jid"].to_s).node.delete_prefix("customer_")
	).then(&:jid).then { |customer_jid|
		m.from = m.from.with(domain: CONFIG[:component][:jid])
		m.to = m.to.with(domain: customer_jid.domain)
		address["jid"] = customer_jid.to_s
		BLATHER << m
	}.catch { |e| panic(e, sentry_hub) }
end

# Ignore groupchat messages
# Especially if we have the component join MUC for notifications
message(to: /\A#{CONFIG[:component][:jid]}\Z/) { true }
message(type: :groupchat) { true }

def billable_message(m)
	(m.body && !m.body.empty?) || m.find("ns:x", ns: OOB.registered_ns).first