Finished Webhooks and Telegram bindings
This commit is contained in:
1 parent
c2d300d2f8
commit
74ae914886
7 files changed
+1283
-109
No files matched your search
+40
-8
@@ -4,16 +4,48 @@ use warnings;
|
||||
use FindBin qw($RealBin);
|
||||
use lib "$RealBin/../lib";
|
||||
|
||||
# One-shot helper to register (or remove) the Telegram webhook.
|
||||
# One-shot helper to register or remove the Telegram webhook.
|
||||
# Run once after install, and again whenever the webhook URL changes.
|
||||
# Only one webhook can be active per bot token at a time.
|
||||
#
|
||||
# Usage:
|
||||
# mnemosyne-webhook [--config /path/to/mnemosyne.conf] [--delete]
|
||||
#
|
||||
# TODO: Load config
|
||||
# TODO: --delete: call Mnemosyne::Telegram::delete_webhook()
|
||||
# TODO: default: call Mnemosyne::Telegram::set_webhook(webhook_url, webhook_secret)
|
||||
# TODO: Print result (registered URL, or confirmation of deletion)
|
||||
# mnemosyne-webhook [--config /path] [--delete]
|
||||
|
||||
print "mnemosyne-webhook: not yet implemented\n";
|
||||
use Mnemosyne::Config;
|
||||
use Mnemosyne::Telegram;
|
||||
|
||||
my $config_path = "$RealBin/../config/mnemosyne.conf";
|
||||
my $do_delete = 0;
|
||||
|
||||
while (@ARGV) {
|
||||
my $arg = shift @ARGV;
|
||||
if ($arg eq '--config' && @ARGV) { $config_path = shift @ARGV }
|
||||
elsif ($arg eq '--delete') { $do_delete = 1 }
|
||||
else { die "Unknown argument: $arg\n" }
|
||||
}
|
||||
|
||||
die "Config file not found: $config_path\n" unless -f $config_path;
|
||||
my $config = Mnemosyne::Config->new($config_path);
|
||||
my $token = $config->get('bot', 'token') or die "bot.token missing\n";
|
||||
my $secret = $config->get('bot', 'webhook_secret') or die "bot.webhook_secret missing\n";
|
||||
my $wh_url = $config->get('bot', 'webhook_url') or die "bot.webhook_url missing\n";
|
||||
|
||||
my $tg = Mnemosyne::Telegram->new($token);
|
||||
|
||||
if ($do_delete) {
|
||||
my $res = $tg->delete_webhook;
|
||||
if ($res->{ok}) {
|
||||
print "Webhook deleted.\n";
|
||||
} else {
|
||||
print "Error: $res->{description}\n";
|
||||
exit 1;
|
||||
}
|
||||
} else {
|
||||
my $res = $tg->set_webhook($wh_url, $secret);
|
||||
if ($res->{ok}) {
|
||||
print "Webhook registered: $wh_url\n";
|
||||
} else {
|
||||
print "Error: $res->{description}\n";
|
||||
exit 1;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user