apply-hotfix: amend msg fallback logic

Phillip Davis created

Change summary

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

Detailed changes

sgx-bwmsgsv2.rb 🔗

@@ -1111,8 +1111,16 @@ class WebhookHandler < Goliath::API
 				puts text
 			end
 
-			if not msg
-				msg = Blather::Stanza::Message.new(bare_jid, text)
+			# If text is not empty, but there isn't a msg,
+			# we need to construct a msg to convey that text
+			unless msg || text&.empty?
+				msg = Blather::Stanza::Message.new(
+					bare_jid,
+					# TODO: The numbers, what do they mean?
+					text.gsub(/[\u0000-\u0008\u000b-\u001f]/, "")
+				)
+				msg.document.encoding = "utf-8"
+				msg.chat_state = nil
 			end
 		else # per prior switch, this is:  jparams['direction'] == 'out'
 			tag_parts = jparams['tag'].split(/ /, 2)