theoretically the first successful group text code

Denver Gingerich created

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:

<message to="cheogram.com" type="error" from="<from>">
   <body>Instead of sending messages to cheogram.com directly,
   you can SMS your contacts by sending messages to
   +1&lt;phone-number&gt;@cheogram.com Jabber IDs.  Or, for support,
   come talk to us in xmpp:discuss@conference.soprani.ca?join</body>
...

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.

Change summary

sgx-bwmsgsv2.rb | 36 ++++++++++++++++++++++++++++++++++--
1 file changed, 34 insertions(+), 2 deletions(-)

Detailed changes

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])