Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow multiple jids to be specified for sending system messages #14669

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions resources/prosody-plugins/mod_system_chat_message.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
-- Module which can be used as an http endpoint to send system chat messages to meeting participants. The provided token
-- Module which can be used as an http endpoint to send system private chat messages to meeting participants. The provided token
--- in the request is verified whether it has the right to do so. This module should be loaded under the virtual host.
-- Copyright (C) 2024-present 8x8, Inc.

-- curl https://{host}/send-system-message -d '{"message": "testmessage", "to": "{connection_jid}", "room": "{room_jid}"}' -H "content-type: application/json" -H "authorization: Bearer {token}"
-- curl https://{host}/send-system-chat-message -d '{"message": "testmessage", "connectionJIDs": ["{connection_jid}"], "room": "{room_jid}"}' -H "content-type: application/json" -H "authorization: Bearer {token}"

local util = module:require "util";
local token_util = module:require "token/util".new(module);
Expand Down Expand Up @@ -60,11 +60,11 @@ function handle_send_system_message (event)

local displayName = payload["displayName"];
local message = payload["message"];
local to = payload["to"];
local connectionJIDs = payload["connectionJIDs"];
local payload_room = payload["room"];

if not message or not to or not payload_room then
module:log("error", "One of [message, to, room] was not provided");
if not message or not connectionJIDs or not payload_room then
module:log("error", "One of [message, connectionJIDs, room] was not provided");
return { status_code = 400; }
end

Expand Down Expand Up @@ -99,15 +99,17 @@ function handle_send_system_message (event)
message = message,
};

local stanza = st.message({
from = room.jid,
to = to
})
:tag('json-message', { xmlns = 'http://jitsi.org/jitmeet' })
:text(json.encode(data))
:up();
for _, to in ipairs(connectionJIDs) do
local stanza = st.message({
from = room.jid,
to = to
})
:tag('json-message', { xmlns = 'http://jitsi.org/jitmeet' })
:text(json.encode(data))
:up();

room:route_stanza(stanza);
room:route_stanza(stanza);
end

return { status_code = 200 };
end
Expand Down