Software /
code /
prosody-modules
Changeset
3672:b8bcea17ccd6
mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 17 Sep 2019 17:12:59 +0200 |
parents | 3671:73c456d9ec67 |
children | 3673:11ebf1da416b |
files | mod_muc_webchat_url/README.markdown mod_muc_webchat_url/mod_muc_webchat_url.lua |
diffstat | 2 files changed, 101 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_muc_webchat_url/README.markdown Tue Sep 17 17:12:59 2019 +0200 @@ -0,0 +1,40 @@ +# Introduction + +Many projects have a support room accessible via a web chat. This module +allows making the URL to such a web chat discoverable via the XMPP +service discovery protocol, enabling e.g. [search +engines](https://search.jabbercat.org/) to index and present these. + +# Configuring + +## Enabling + +``` {.lua} +Component "rooms.example.net" "muc" +modules_enabled = { + "muc_webchat_url"; +} +``` + +## Settings + +The URL is configured using the in-band MUC room configuration protocol. + +The module can optionally be configured to give all public (not +members-only, hidden or password protected) rooms gain a default value +based on a template: + +``` {.lua} +muc_webchat_url = "https://chat.example.com/join?room={node}" +``` + +The following variables will be subsituted with room address details: + +`{jid}` +: The complete room address, eg `room@muc.example.com`· + +`{node}` +: The local part (before the `@`) of the room JID. + +`{host}` +: The domain name part of the room JID.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_muc_webchat_url/mod_muc_webchat_url.lua Tue Sep 17 17:12:59 2019 +0200 @@ -0,0 +1,61 @@ +local jid_split = require "util.jid".split; +module:depends"muc"; + +local webchat_baseurl = module:get_option_string("muc_webchat_baseurl", nil); + +local function get_webchat_url(room) + local webchat_url = room._data.webchat_url; + if webchat_url then -- explicitly configured + return webchat_url; + end + if not webchat_baseurl then + -- no template + return nil; + end + if room:get_hidden() or room:get_members_only() or room:get_password() then + -- not a public room + return nil; + end + return (webchat_baseurl:gsub("{(%w+)}", { + jid = room.jid, + node = select(1, jid_split(room.jid)), + host = select(2, jid_split(room.jid)), + })); +end + +module:hook("muc-config-form", function(event) + local room, form = event.room, event.form; + table.insert(form, { + name = "muc#roomconfig_webchat_url", + type = "text-single", + label = "URL where this room can be joined", + value = get_webchat_url(room), + }); +end); + +module:hook("muc-config-submitted", function(event) + local room, fields, changed = event.room, event.fields, event.changed; + local new = fields["muc#roomconfig_webchat_url"]; + if new ~= room._data.webchat_url then + room._data.webchat_url = new; + if type(changed) == "table" then + changed["muc#roomconfig_webchat_url"] = true; + else + event.changed = true; + end + end +end); + +module:hook("muc-disco#info", function (event) + local room, form, formdata = event.room, event.form, event.formdata; + + local webchat_url = get_webchat_url(room); + if not webchat_url or webchat_url == "" then + return; + end + table.insert(form, { + name = "muc#roominfo_webchat_url", + }); + formdata["muc#roominfo_webchat_url"] = webchat_url; +end); +