mirror of
https://github.com/kmein/niveum
synced 2026-03-16 10:11:08 +01:00
mopidy, mail, telegram
This commit is contained in:
41
modules/telegram-bot.nix
Normal file
41
modules/telegram-bot.nix
Normal file
@@ -0,0 +1,41 @@
|
||||
{ lib, config, pkgs, ... }:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.niveum.telegramBots;
|
||||
|
||||
botService = name: bot: nameValuePair "telegram-bot-${name}" {
|
||||
enable = bot.enable;
|
||||
startAt = bot.time;
|
||||
serviceConfig.Type = "oneshot";
|
||||
wantedBy = [ "network-online.target" ];
|
||||
script = ''
|
||||
${pkgs.curl}/bin/curl -s -X POST "https://api.telegram.org/bot${bot.token}/sendMessage" \
|
||||
-d chat_id="${bot.chatId}" \
|
||||
-d text="$(${bot.command})" ${
|
||||
if bot.parseMode == null then ""
|
||||
else "-d parse_mode=${bot.parseMode}"
|
||||
}
|
||||
'';
|
||||
};
|
||||
in {
|
||||
options.niveum.telegramBots = mkOption {
|
||||
type = types.attrsOf (types.submodule {
|
||||
options = {
|
||||
enable = mkEnableOption "Telegram bot";
|
||||
time = mkOption { type = types.str; };
|
||||
token = mkOption { type = types.strMatching "[0-9A-Za-z:-]+"; };
|
||||
chatId = mkOption { type = types.strMatching "[0-9]+|@[A-Za-z0-9]+"; };
|
||||
command = mkOption { type = types.str; };
|
||||
parseMode = mkOption {
|
||||
type = types.nullOr (types.enum ["HTML" "Markdown"]);
|
||||
default = null;
|
||||
};
|
||||
};
|
||||
});
|
||||
default = {};
|
||||
};
|
||||
|
||||
config = {
|
||||
systemd.services = attrsets.mapAttrs' botService cfg;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user