aboutsummaryrefslogtreecommitdiff
path: root/lib/TgLib/Api.pm
diff options
context:
space:
mode:
authorGuillermo Ramos2020-02-24 17:47:39 +0100
committerGuillermo Ramos2020-02-24 17:47:53 +0100
commit267e948b52ce6a58d016b05e4616b8f1836e027f (patch)
treeee2b170c64c9797e7aa8d677c9025b941d963715 /lib/TgLib/Api.pm
parent0b6a8a5275afb4921e3a85810dfe7bbb16e5b4ae (diff)
downloadtgutils-267e948b52ce6a58d016b05e4616b8f1836e027f.tar.gz
Fix UTF-8 encoding in Api module
Diffstat (limited to 'lib/TgLib/Api.pm')
-rw-r--r--lib/TgLib/Api.pm5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/TgLib/Api.pm b/lib/TgLib/Api.pm
index b0a66bf..1fe8d06 100644
--- a/lib/TgLib/Api.pm
+++ b/lib/TgLib/Api.pm
@@ -49,11 +49,12 @@ sub send_message {
my ($self, $chat_id, $text) = @_;
my $logger = $self->{'logger'};
my $uri = "$self->{'uri'}/sendMessage";
- my $content = encode_json {'chat_id' => $chat_id, 'text' => $text};
+ $logger->info("Sending to $chat_id: '$text'\n");
+ utf8::decode($text) unless utf8::is_utf8($text);
+ my $content = encode_json {'chat_id' => $chat_id, 'text' => $text};
my $req = HTTP::Request->new("POST", $uri,
["Content-Type", "application/json"], $content);
- $logger->info("Sending to $chat_id: '$text'\n");
$logger->debug(sprintf "Request:\n%s\n", Dumper($req));
my $resp = $self->{'ua'}->request($req);