1
0
mirror of https://github.com/kmein/niveum synced 2026-03-16 10:11:08 +01:00

bots: post on matrix as well

This commit is contained in:
2024-10-08 22:35:41 +02:00
parent a28fca11a7
commit 136d4e699f
2 changed files with 35 additions and 4 deletions

View File

@@ -17,6 +17,8 @@ with lib; let
"telegram-token:${bot.telegram.tokenFile}"
] ++ lib.optionals (bot.mastodon.enable) [
"mastodon-token:${bot.mastodon.tokenFile}"
] ++ lib.optionals (bot.matrix.enable) [
"matrix-token:${bot.matrix.tokenFile}"
];
};
wants = ["network-online.target"];
@@ -25,6 +27,17 @@ with lib; let
if [ -n "$QUOTE" ]; then
echo $QUOTE >&2
${lib.optionalString (bot.matrix.enable) ''
export MATRIX_TOKEN="$(cat "$CREDENTIALS_DIRECTORY/matrix-token")"
export JSON_PAYLOAD=$(${pkgs.jq}/bin/jq -n --arg msgtype "m.text" --arg body "$QUOTE" '{msgtype: $msgtype, body: $body}')
${strings.concatStringsSep "\n" (map (chatId: ''
${pkgs.curl}/bin/curl -X POST "https://${bot.matrix.homeserver}/_matrix/client/r0/rooms/${chatId}/send/m.room.message" \
-d "$JSON_PAYLOAD" \
-H "Authorization: Bearer $MATRIX_TOKEN" \
-H "Content-Type: application/json"
'') bot.matrix.chatIds)}
''}
${lib.optionalString (bot.mastodon.enable) ''
export MASTODON_TOKEN="$(cat "$CREDENTIALS_DIRECTORY/mastodon-token")"
${pkgs.curl}/bin/curl -X POST "https://${bot.mastodon.homeserver}/api/v1/statuses" \
@@ -56,6 +69,21 @@ in {
enable = mkEnableOption "Mastodon and Telegram bot";
time = mkOption {type = types.str;};
command = mkOption {type = types.str;};
matrix = mkOption {
default = {};
type = types.submodule {
options = {
enable = mkEnableOption "Posting to Matrix";
tokenFile = mkOption {type = types.path;};
homeserver = mkOption {
type = types.str;
};
chatIds = mkOption {
type = types.listOf types.str;
};
};
};
};
mastodon = mkOption {
default = {};
type = types.submodule {