From 90331bcc49d8f1af365ba26dab74794fb54f7cf8 Mon Sep 17 00:00:00 2001 From: Denver Gingerich Date: Wed, 22 Apr 2020 03:42:38 +0000 Subject: [PATCH] theoretically the first successful group text code Per https://wiki.soprani.ca/SGX/GroupMMS we have implemented the protocol for receiving group texts. For now we hard-code "cheogram.com", but this and other items will be fixed in the near future. While the message going out does look correct, the current Cheogram takes issue with it, sending us back the following error: Instead of sending messages to cheogram.com directly, you can SMS your contacts by sending messages to +1<phone-number>@cheogram.com Jabber IDs. Or, for support, come talk to us in xmpp:discuss@conference.soprani.ca?join ... So this code might not be complete, but we won't know for sure until we're able to do a bit more Cheogram testing. But it could be ready! Also, we only currently handle group texts with 2 recipients - any additional recipients will be dropped. It should be trivial to add more recipients by looping as needed. --- sgx-bwmsgsv2.rb | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/sgx-bwmsgsv2.rb b/sgx-bwmsgsv2.rb index 2f345f6d8598d49924e2a3bd29ea6ac261b3e045..8f48652bb8151e3e2d87f493187d65ba0c4639f7 100755 --- a/sgx-bwmsgsv2.rb +++ b/sgx-bwmsgsv2.rb @@ -838,7 +838,7 @@ class WebhookHandler < Goliath::API return [200, {}, "OK"] end - msg = '' + msg = nil case jparams['direction'] when 'in' text = '' @@ -891,6 +891,35 @@ class WebhookHandler < Goliath::API when 'message-received' # TODO: handle group chat, and fix above text = jparams['text'] + + if jparams['to'].length > 1 + msg = Blather::Stanza::Message.new( + 'cheogram.com', text) # TODO + + addrs = Nokogiri::XML::Node.new( + 'addresses', msg.document) + addrs['xmlns'] = 'http://jabber.org/' + + 'protocol/address' + + addr1 = Nokogiri::XML::Node.new( + 'address', msg.document) + addr1['type'] = 'to' + addr1['jid'] = bare_jid + addrs.add_child(addr1) + + # TODO: actually do N, instead of just 1 + addrn = Nokogiri::XML::Node.new( + 'address', msg.document) + addrn['type'] = 'to' + addrn['uri'] = "sms:#{jparams['to'][1]}" + addrn['delivered'] = 'true' + addrs.add_child(addrn) + + msg.add_child(addrs) + + # TODO: delete + puts "RESPONSE9: #{msg.inspect}" + end else text = "unknown type (#{type})"\ " with text: " + jparams['text'] @@ -899,7 +928,10 @@ class WebhookHandler < Goliath::API puts text end - msg = Blather::Stanza::Message.new(bare_jid, text) + if not msg + msg = Blather::Stanza::Message.new(bare_jid, + text) + end else # per prior switch, this is: jparams['direction'] == 'out' tag_parts = jparams['tag'].split(/ /, 2) id = WEBrick::HTTPUtils.unescape(tag_parts[0])