diff --git a/.rubocop.yml b/.rubocop.yml index fbc1ecb8f344eba8306d4332dd08d0eda986c141..5b78f7bba2bb72dd78b9d572a954eac1e8a03dcd 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -143,5 +143,8 @@ Style/FrozenStringLiteralComment: Exclude: - forms/**/*.rb +Style/RescueModifier: + Enabled: false + Naming/AccessorMethodName: Enabled: false diff --git a/sgx_endstream.rb b/sgx_endstream.rb index 87c712ccf031c80775be13f66fff18cd8b084472..1505e88976e53d1f08116e787ca65050ed4e4aee 100755 --- a/sgx_endstream.rb +++ b/sgx_endstream.rb @@ -155,6 +155,8 @@ ibr type: :set do |iq| end message from: /@sms.chat.1pcom.net\Z/ do |m| + json = JSON.parse(m.body) rescue nil + tel = if m.from.node.length > 7 "+#{m.from.node}" else @@ -164,6 +166,22 @@ message from: /@sms.chat.1pcom.net\Z/ do |m| m.from = Blather::JID.new(tel, CONFIG[:component][:jid]) m.to = ProxiedJID.new(m.to).unproxied m.subject = nil # They send a generic subject for some reason + + if json.is_a?(Hash) && json["response"] + log.info("SMS Status", json) + resp = json["response"] + m.id = resp["id"] + swap = m.from + m.from = m.to + m.to = swap + m.body = "" + m = m.as_error( + "recipient-unavailable", + :cancel, + "#{resp['text']} (#{resp['code']} #{resp['subcode']} #{resp['dlrid']})" + ) + end + self << m end @@ -195,12 +213,12 @@ message ->(m) { !m.oobs.empty? }, to: /\A\+?\d+@/ do |m| self << OutgoingMMS.for(m).to_stanza(id: m.id, from: m.from) end -def too_long_for_sms(m) +def too_long_for_sms?(m) # ~3 segments m.body.length > (m.body.ascii_only? ? 160 : 70) * 3 end -message :body, method(:too_long_for_sms).to_proc, to: /\A\+?\d+@/ do |m| +message :body, method(:too_long_for_sms?).to_proc, to: /\A\+?\d+@/ do |m| self << OutgoingMMS.for(m).to_stanza(id: m.id, from: m.from) end