diff --git a/sgx_jmp.rb b/sgx_jmp.rb index ca3005c2a8c446d3bc10dffbe4a87a995c08bd7a..389f4a1bd2d4be4f05a0a56cc60b631af4790edf 100644 --- a/sgx_jmp.rb +++ b/sgx_jmp.rb @@ -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