aboutsummaryrefslogtreecommitdiff
path: root/tgserver
diff options
context:
space:
mode:
authorGuillermo Ramos2020-02-24 18:22:58 +0100
committerGuillermo Ramos2020-02-24 18:22:58 +0100
commit0817cf1c12f8ad49435fa6cbc85fe76028a92325 (patch)
tree65f71bce16546cb05d7a5663a63dd71ad2feb8b0 /tgserver
parent267e948b52ce6a58d016b05e4616b8f1836e027f (diff)
downloadtgutils-0817cf1c12f8ad49435fa6cbc85fe76028a92325.tar.gz
Pass user/chat metadata from tgserver to child
Diffstat (limited to 'tgserver')
-rwxr-xr-xtgserver7
1 files changed, 5 insertions, 2 deletions
diff --git a/tgserver b/tgserver
index 796c09d..9511b94 100755
--- a/tgserver
+++ b/tgserver
@@ -62,6 +62,9 @@ while (1) {
$logger->debug(sprintf "Update %s", Dumper($update));
my $msg = $update->{'message'};
+ $ENV{'TGUTILS_CHAT_ID'} = $msg->{'chat'}{'id'};
+ $ENV{'TGUTILS_FROM_ID'} = $msg->{'from'}{'id'};
+ $ENV{'TGUTILS_FROM_USERNAME'} = $msg->{'from'}{'username'};
if (exists $msg->{'photo'}) {
handle_photo($msg);
} else {
@@ -99,11 +102,11 @@ sub handle_text {
sub reply {
my $chat_id = shift;
my $response = shift;
- my $type = ref $response eq 'HASH' ? $response->{'type'} : undef;
+ my $type = ref $response eq 'HASH' ? $response->{'type'} : 'TEXT';
if ($type eq 'DOCUMENT') {
my $caption = $response->{'caption'};
$api->send_document($chat_id, decode_base64 $response->{'content'}, $caption);
- } elsif ($response) {
+ } elsif ($type eq 'TEXT' and $response) {
$api->send_message($chat_id, $response);
} else {
$logger->warn("Empty response, skipping\n");