diff options
| author | Guillermo Ramos | 2020-04-26 11:49:06 +0200 | 
|---|---|---|
| committer | Guillermo Ramos | 2020-04-26 11:49:10 +0200 | 
| commit | c5191f10359f32a3af44f4087322348602734a3c (patch) | |
| tree | 2d1de0e76b522157323a23c049689a55c48a18df /lib | |
| parent | 6f347a1ff480a16a4010ef5b5a044bc55ff2c6f7 (diff) | |
| download | tgutils-c5191f10359f32a3af44f4087322348602734a3c.tar.gz | |
Support photos in tgserver
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/TgLib/Api.pm | 25 | 
1 files changed, 22 insertions, 3 deletions
| diff --git a/lib/TgLib/Api.pm b/lib/TgLib/Api.pm index 02e8b83..87f227d 100644 --- a/lib/TgLib/Api.pm +++ b/lib/TgLib/Api.pm @@ -62,12 +62,31 @@ sub send_message {  }  sub send_document { -    my ($self, $chat_id, $photo, $caption) = @_; +    my ($self, $chat_id, $file, $filename, $caption) = @_;      my $logger = $self->{'logger'};      my $uri = "$self->{'uri'}/sendDocument";      my $content = {'chat_id' => $chat_id, -                       'caption' => $caption, -                       'document' => [undef, 'cosa.png', Content => $photo]}; +                   'caption' => $caption, +                   'document' => [undef, $filename, Content => $file]}; + +    my $req = POST $uri, 'Content-Type' => "multipart/form-data", 'Content' => $content; +    $logger->debug(sprintf "Request:\n%s\n", Dumper($req)); # DEBUG + +    my $resp = $self->{'ua'}->request($req); +    $logger->debug(sprintf "Response:\n%s\n", Dumper($resp)); +    if ($resp->is_error()) { +        print decode_json($resp->content)->{'description'}; +        die $resp->message; +    } +} + +sub send_photo { +    my ($self, $chat_id, $photo, $filename, $caption) = @_; +    my $logger = $self->{'logger'}; +    my $uri = "$self->{'uri'}/sendPhoto"; +    my $content = {'chat_id' => $chat_id, +                   'caption' => $caption, +                   'photo' => [undef, $filename, Content => $photo]};      my $req = POST $uri, 'Content-Type' => "multipart/form-data", 'Content' => $content;      $logger->debug(sprintf "Request:\n%s\n", Dumper($req)); # DEBUG | 
