aboutsummaryrefslogtreecommitdiff
path: root/tgserver
diff options
context:
space:
mode:
authorGuillermo Ramos2019-06-25 12:19:59 +0200
committerGuillermo Ramos2019-06-25 12:44:04 +0200
commit16cd42e6fbfbf6fff06fd50926ac374b771e3f97 (patch)
tree8427a9f4afceacaffb4cd5594524678ccbf7060a /tgserver
parentd7f4ee6f0f86f462c26a27eb8d267abd592f01af (diff)
downloadtgutils-16cd42e6fbfbf6fff06fd50926ac374b771e3f97.tar.gz
Move Telegram comm logic to TgLib::Api
Diffstat (limited to 'tgserver')
-rwxr-xr-xtgserver12
1 files changed, 6 insertions, 6 deletions
diff --git a/tgserver b/tgserver
index ed58e46..9c6e89c 100755
--- a/tgserver
+++ b/tgserver
@@ -5,7 +5,7 @@
# Run `tgserver -h` for quick help, or `tgserver -h -v` for full manual.
################################################################################
-$main::VERSION = "0.1.0";
+$main::VERSION = "0.1.1";
use Getopt::Long qw(:config auto_version);
use Pod::Usage qw<pod2usage>;
@@ -18,6 +18,7 @@ use lib "$FindBin::Bin/lib";
use TgLib qw<fetch_token>;
require TgLib::Logger;
+require TgLib::Api;
my $TOKEN;
my $VERBOSE = 0;
@@ -40,8 +41,8 @@ while (1) {
foreach my $update (@{decode_json <$recv>}) {
$logger->debug(sprintf "Update %s", Dumper($update));
my $text = $update->{'message'}{'text'};
- my $chatid = $update->{'message'}{'chat'}{'id'};
- $logger->info("Received update from chat $chatid\n");
+ my $chat_id = $update->{'message'}{'chat'}{'id'};
+ $logger->info("Received update from chat $chat_id\n");
use IPC::Open2 qw<open2>;
my $pid = open2(my $progr, my $progw, "@ARGV");
@@ -53,9 +54,8 @@ while (1) {
close($progr);
if ($response) {
- open(my $send, "|-", "$FindBin::Bin/tgsend --token $TOKEN $chatid");
- print $send $response;
- close($send);
+ my $api = TgLib::Api->new($TOKEN, $logger);
+ $api->send_message($chat_id, $text, $response);
} else {
$logger->warn("Empty response, skipping\n");
}