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:
@@ -14,17 +14,20 @@
|
||||
chatIds = ["-1001760262519"];
|
||||
parseMode = "Markdown";
|
||||
};
|
||||
mastodon = {
|
||||
matrix = {
|
||||
enable = true;
|
||||
homeserver = "c.im";
|
||||
tokenFile = config.age.secrets.mastodon-token-logotheca.path;
|
||||
language = "de";
|
||||
homeserver = "matrix.4d2.org";
|
||||
tokenFile = config.age.secrets.matrix-token-lakai.path;
|
||||
chatIds = [
|
||||
"!zlwCuPiCNMSxDviFzA:4d2.org"
|
||||
];
|
||||
};
|
||||
command = "${niveumPackages.literature-quote}/bin/literature-quote";
|
||||
};
|
||||
|
||||
age.secrets = {
|
||||
mastodon-token-logotheca.file = ../../secrets/mastodon-token-logotheca.age;
|
||||
matrix-token-lakai.file = ../../secrets/matrix-token-lakai.age;
|
||||
};
|
||||
|
||||
niveum.passport.services = [
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user