From eb4764026b51035c280e6c305efbe2cab29eb56f Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 6 Jan 2021 11:27:50 +0100 Subject: [PATCH] Add script for notifying Kosmos channels from Ruby An example for notifying Kosmos XMPP channels from plain Ruby, with no dependencies. --- scripts/util/notify_xmpp.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 scripts/util/notify_xmpp.rb diff --git a/scripts/util/notify_xmpp.rb b/scripts/util/notify_xmpp.rb new file mode 100644 index 0000000..c481e7a --- /dev/null +++ b/scripts/util/notify_xmpp.rb @@ -0,0 +1,15 @@ +require 'uri' +require 'net/http' +require 'json' + +WEBHOOK_TOKEN = "foo" + +def send_notification(msg) + uri = URI.parse('https://hal8000.chat.kosmos.org/incoming/#{WEBHOOK_TOKEN}') + https = Net::HTTP.new(uri.host, uri.port) + https.use_ssl = true + request = Net::HTTP::Post.new(uri.request_uri, 'Content-Type' => 'application/json') + request.body = { room: "ops@kosmos.chat", message: msg }.to_json + response = https.request(request) + puts response.inspect +end