diff --git a/lib/Teapot/Bot/Brain.pm b/lib/Teapot/Bot/Brain.pm index 1baa47b..1b03f9b 100644 --- a/lib/Teapot/Bot/Brain.pm +++ b/lib/Teapot/Bot/Brain.pm @@ -8,28 +8,32 @@ use strict; use warnings; use 5.018; ## no critic (ProhibitImplicitImport) use utf8; -use English qw ( -no_match_vars ); +use English qw ( -no_match_vars ); -use Mojo::IOLoop (); -use Mojo::JSON qw (true false); -use Mojo::UserAgent (); -use Carp qw/carp croak cluck confess/; # use croak where we return error up to app that supply something wrong - # use cluck where we want to say that something bad but non-critical happen in - # lower layer (Mojo loop) - # use confess where we want to say that fatal error happen in lower layer (Mojo loop) -use Log::Any (); -use Data::Dumper qw (Dumper); +use Mojo::IOLoop (); +use Mojo::JSON qw (true false); +use Mojo::UserAgent (); +use Carp qw (carp croak cluck confess); + # use croak where we return error up to app that supply something wrong + # use cluck where we want to say that something bad but non-critical happen in + # lower layer f.ex. Mojo loop) + # use confess where we want to say that fatal error happen in lower layer + # f.ex. in Mojo loop +use Log::Any (); +use Data::Dumper qw (Dumper); -use Teapot::Bot::Object::Message (); -use Teapot::Bot::Object::Poll (); -use Teapot::Bot::Object::PollAnswer (); +# TODO: import subs that are "used here directly by peeking into apropriate ns-es" +use Teapot::Bot::Object::Message (); +use Teapot::Bot::Object::Poll (); +use Teapot::Bot::Object::PollAnswer (); use Teapot::Bot::Object::ChatMemberUpdated (); -use Teapot::Bot::Object::User (); -use Teapot::Bot::Object::Chat (); -use Teapot::Bot::Object::ChatMember (); -use Teapot::Bot::Object::ChatInviteLink (); +use Teapot::Bot::Object::ChatPermissions (); +use Teapot::Bot::Object::User (); +use Teapot::Bot::Object::Chat (); +use Teapot::Bot::Object::ChatMember (); +use Teapot::Bot::Object::ChatInviteLink (); -$Teapot::Bot::Brain::VERSION = '0.024'; +$Teapot::Bot::Brain::VERSION = '0.025'; # base class for building telegram robots with Mojolicious has longpoll_time => 60; @@ -48,16 +52,18 @@ sub add_repeating_task { my $task = shift; my $repeater = sub { - # Perform operation every $seconds seconds my $last_check = time(); - Mojo::IOLoop->recurring(0.1 => sub { - my $loop = shift; - my $now = time(); - return if ($now - $last_check) < $seconds; - $last_check = $now; - $task->($self); - }); + + Mojo::IOLoop->recurring( + 0.1 => sub { + my $loop = shift; + my $now = time(); + return if ($now - $last_check) < $seconds; + $last_check = $now; + $task->($self); + } + ); }; # keep a copy @@ -65,15 +71,16 @@ sub add_repeating_task { # kick it off $repeater->(); + return; } - sub add_listener { my $self = shift; my $coderef = shift; push @{ $self->listeners }, $coderef; + return; } @@ -81,64 +88,104 @@ sub init { croak 'init() was not overridden!'; } - sub think { my $self = shift; $self->init(); $self->_add_getUpdates_handler; - do { Mojo::IOLoop->start } until Mojo::IOLoop->is_running; + + do { + Mojo::IOLoop->start + } until Mojo::IOLoop->is_running; + return; } sub getMe { - my $self = shift; - my $token = $self->token || croak 'No token supplied to getMe()?'; + my $self; - my $url = "https://api.telegram.org/bot${token}/getMe"; + # There is some magic happen if we call function as object, as we usually do here + # But if we access function from usual-style wrapper that calls it directly from namespace it supply noy $self object + # but string with its name, which is a bummer. + while (my $o = shift @_) { + if (ref ($o) ne '') { + $self = $o; + last; + } + } + + my $ret; + + if (! defined($self->token) || $self->token eq '') { + $ret->{error} = 1; + $ret->{message} = 'No token supplied to getChatMember()'; + + return $ret; + } + + my $url = sprintf 'https://api.telegram.org/bot%s/getMe', $self->token; my $api_response = $self->_post_request($url); unless ($api_response->{error}) { return Teapot::Bot::Object::User->create_from_hash($api_response, $self); } else { - return {'error' => 1}; + return $api_response; } } - sub getChatMember { - my $self = shift; + my $self; + + # There is some magic happen if we call function as object, as we usually do here + # But if we access function from usual-style wrapper that calls it directly from namespace it supply noy $self object + # but string with its name, which is a bummer. + while (my $o = shift @_) { + if (ref ($o) ne '') { + $self = $o; + last; + } + } + my $args = shift || {}; my $send_args = {}; + my $ret; + + if (! defined($self->token) || $self->token eq '') { + $ret->{error} = 1; + $ret->{message} = 'No token supplied to getChatMember()'; + + return $ret; + } unless ($args->{chat_id}) { - cluck 'No chat_id supplied to getChatMember()'; - return {'error' => 1}; + $ret->{error} = 1; + $ret->{message} = 'No chat_id supplied to getChatMember()'; + + return $ret; } unless ($args->{user_id}) { - cluck 'No user_id supplied to getChatMember()'; - return {'error' => 1}; - } + $ret->{error} = 1; + $ret->{message} = 'No user_id supplied to getChatMember()'; + return $ret; + } $send_args->{chat_id} = $args->{chat_id}; $send_args->{user_id} = $args->{user_id}; - my $token = $self->token || croak 'No token supplied to getChatMember?'; - - my $url = "https://api.telegram.org/bot${token}/getChatMember"; + my $url = sprintf 'https://api.telegram.org/bot%s/getChatMember', $self->token; my $api_response = $self->_post_request($url, $send_args); unless ($api_response->{error}) { return Teapot::Bot::Object::ChatMember->create_from_hash($api_response, $self); } else { - return {'error' => 1}; + return $api_response; } } @@ -146,192 +193,274 @@ sub banChatMember { my $self = shift; my $args = shift || {}; - my $token = $self->token || croak 'No token supplied to banChatMember?'; my $send_args = {}; + my $ret; + + if (! defined($self->token) || $self->token eq '') { + $ret->{error} = 1; + $ret->{message} = 'No token supplied to banChatMember()'; + + return $ret; + } unless ($args->{chat_id}) { - cluck 'No chat_id supplied to banChatMember()'; - return {'error' => 1}; + $ret->{error} = 1; + $ret->{message} = 'No chat_id supplied to banChatMember()'; + + return $ret; } unless ($args->{user_id}) { - cluck 'No user_id supplied to banChatMember()'; - return {'error' => 1}; + $ret->{error} = 1; + $ret->{message} = 'No user_id supplied to banChatMember()'; + + return $ret; } - $send_args->{chat_id} = $args->{chat_id}; - $send_args->{user_id} = $args->{user_id}; - $send_args->{until_date} = $args->{until_date} if exists $args->{until_date}; + $send_args->{chat_id} = $args->{chat_id}; + $send_args->{user_id} = $args->{user_id}; + $send_args->{until_date} = $args->{until_date} if exists $args->{until_date}; $send_args->{revoke_messages} = $args->{revoke_messages} if exists $args->{revoke_messages}; - my $url = "https://api.telegram.org/bot${token}/banChatMember"; - my $api_response = $self->_post_request($url, $send_args); + my $url = sprintf 'https://api.telegram.org/bot%s/banChatMember', $self->token; - return; + return $self->_post_request($url, $send_args); } - sub unbanChatMember { my $self = shift; my $args = shift || {}; - my $token = $self->token || croak 'No token supplied to unbanChatMember?'; my $send_args = {}; + my $ret; + + if (! defined($self->token) || $self->token eq '') { + $ret->{error} = 1; + $ret->{message} = 'No token supplied to unbanChatMember()'; + + return $ret; + } unless ($args->{chat_id}) { - cluck 'No chat_id supplied to unbanChatMember()'; - return {'error' => 1}; + $ret->{error} = 1; + $ret->{message} = 'No chat_id supplied to unbanChatMember()'; + + return $ret; } unless ($args->{user_id}) { - cluck 'No user_id supplied to unbanChatMember()'; - return {'error' => 1}; + $ret->{error} = 1; + $ret->{message} = 'No user_id supplied to unbanChatMember()'; + + return $ret; } - $send_args->{chat_id} = $args->{chat_id}; - $send_args->{user_id} = $args->{user_id}; + $send_args->{chat_id} = $args->{chat_id}; + $send_args->{user_id} = $args->{user_id}; $send_args->{only_if_banned} = $args->{only_if_banned} if exists $args->{only_if_banned}; - my $url = "https://api.telegram.org/bot${token}/unbanChatMember"; - my $api_response = $self->_post_request($url, $send_args); + my $url = sprintf 'https://api.telegram.org/bot%s/unbanChatMember', $self->token; - return; + return $self->_post_request($url, $send_args); } - sub muteChatMember { my $self = shift; my $args = shift || {}; - my $token = $self->token || croak 'No token supplied to muteChatMember?'; my $send_args = {}; + my $ret; + + if (! defined($self->token) || $self->token eq '') { + $ret->{error} = 1; + $ret->{message} = 'No token supplied to muteChatMember()'; + + return $ret; + } unless ($args->{chat_id}) { - cluck 'No chat_id supplied to muteChatMember()'; - return {'error' => 1}; + $ret->{error} = 1; + $ret->{message} = 'No chat_id supplied to muteChatMember()'; + + return $ret; } unless ($args->{user_id}) { - cluck 'No user_id supplied to muteChatMember()'; - return {'error' => 1}; + $ret->{error} = 1; + $ret->{message} = 'No user_id supplied to muteChatMember()'; + + return $ret; } - $send_args->{chat_id} = $args->{chat_id}; - $send_args->{user_id} = $args->{user_id}; - $send_args->{until_date} = $args->{until_date} if exists $args->{until_date}; + $send_args->{chat_id} = $args->{chat_id}; + $send_args->{user_id} = $args->{user_id}; + $send_args->{until_date} = $args->{until_date} if exists $args->{until_date}; # Revoke all known for API v6.2 permissions - $send_args->{permissions}->{can_send_messages} = false; - $send_args->{permissions}->{can_send_media_messages} = false; - $send_args->{permissions}->{can_send_polls} = false; - $send_args->{permissions}->{can_send_other_messages} = false; + $send_args->{permissions}->{can_send_messages} = false; + $send_args->{permissions}->{can_send_media_messages} = false; + $send_args->{permissions}->{can_send_polls} = false; + $send_args->{permissions}->{can_send_other_messages} = false; $send_args->{permissions}->{can_add_web_page_previews} = false; - $send_args->{permissions}->{can_change_info} = false; - $send_args->{permissions}->{can_invite_users} = false; - $send_args->{permissions}->{can_pin_messages} = false; + $send_args->{permissions}->{can_change_info} = false; + $send_args->{permissions}->{can_invite_users} = false; + $send_args->{permissions}->{can_pin_messages} = false; - my $url = "https://api.telegram.org/bot${token}/restrictChatMember"; - my $api_response = $self->_post_request($url, $send_args); + my $url = sprintf 'https://api.telegram.org/bot%s/restrictChatMember', $self->token; - return; + return $self->_post_request($url, $send_args); } - sub getChat { - my $self = shift; + my $self; + + # There is some magic happen if we call function as object, as we usually do here + # But if we access function from usual-style wrapper that calls it directly from namespace it supply noy $self object + # but string with its name, which is a bummer. + while (my $o = shift @_) { + if (ref ($o) ne '') { + $self = $o; + last; + } + } + my $args = shift || {}; my $send_args = {}; + my $ret; unless ($args->{chat_id}) { - cluck 'No chat_id supplied to getChat()'; - return {'error' => 1}; + $ret->{error} = 1; + $ret->{message} = 'No chat_id supplied to getChat()'; + + return $ret; } + if (! defined($self->token) || $self->token eq '') { + $ret->{error} = 1; + $ret->{message} = 'No token supplied to getChat()'; + + return $ret; + } + + my $url = sprintf 'https://api.telegram.org/bot%s/getChat', $self->token; $send_args->{chat_id} = $args->{chat_id}; - - my $token = $self->token || croak 'No token supplied to getChat()?'; - - my $url = "https://api.telegram.org/bot${token}/getChat"; - my $api_response = $self->_post_request($url, $send_args); + my $api_response = $self->_post_request($url, $send_args); unless ($api_response->{error}) { return Teapot::Bot::Object::Chat->create_from_hash($api_response, $self); } else { - return {'error' => 1}; + return $api_response; } } - sub leaveChat { my $self = shift; my $args = shift || {}; my $send_args = {}; + my $ret; unless ($args->{chat_id}) { - cluck 'No chat_id supplied to getChat()'; - return {'error' => 1}; + $ret->{error} = 1; + $ret->{message} = 'No chat_id supplied to leaveChat()'; + + return $ret; + } + + if (! defined($self->token) || $self->token eq '') { + $ret->{error} = 1; + $ret->{message} = 'No token supplied to leaveChat()'; + + return $ret; + } + + $send_args->{chat_id} = $args->{chat_id}; + my $url = sprintf 'https://api.telegram.org/bot%s/leaveChat', $self->token; + + return $self->_post_request($url, $send_args); +} + +sub can_talk { + my $self = shift; + my $args = shift || {}; + + my $send_args = {}; + my $ret; + + unless ($args->{chat_id}) { + $ret->{error} = 1; + $ret->{message} = 'No chat_id supplied in can_talk()'; + + return $ret; + } + + if (! defined($self->token) || $self->token eq '') { + $ret->{error} = 1; + $ret->{message} = 'No token supplied to can_talk()'; + + return $ret; } $send_args->{chat_id} = $args->{chat_id}; - my $token = $self->token || croak 'No token supplied to getChat()?'; - - my $url = "https://api.telegram.org/bot${token}/leaveChat"; - my $api_response = $self->_post_request($url, $send_args); - - return; + return Teapot::Bot::Object::ChatPermissions->canTalk ($self, $send_args); } - sub sendMessage { my $self = shift; my $args = shift || {}; my $send_args = {}; + my $ret; unless ($args->{chat_id}) { - cluck 'No chat_id supplied in sendMessage()'; - return {'error' => 1}; + $ret->{error} = 1; + $ret->{message} = 'No chat_id supplied in sendMessage()'; + + return $ret; } - $send_args->{chat_id} = $args->{chat_id}; + if (! defined($self->token) || $self->token eq '') { + $ret->{error} = 1; + $ret->{message} = 'No token supplied to sendMessage()'; - if (defined $args->{message_thread_id}) { - $send_args->{message_thread_id} = $args->{message_thread_id}; + return $ret; } unless ($args->{text}) { - cluck 'No text supplied in sendMessage()'; - return {'error' => 1}; + $ret->{error} = 1; + $ret->{message} = 'No text supplied in sendMessage()'; + + return $ret; } - $send_args->{text} = $args->{text}; - - # these are optional, send if they are supplied - $send_args->{parse_mode} = $args->{parse_mode} if exists $args->{parse_mode}; + $send_args->{text} = $args->{text}; + $send_args->{chat_id} = $args->{chat_id}; + $send_args->{message_thread_id} = $args->{message_thread_id} if exists $args->{message_thread_id}; + $send_args->{parse_mode} = $args->{parse_mode} if exists $args->{parse_mode}; $send_args->{disable_web_page_preview} = $args->{disable_web_page_preview} if exists $args->{disable_web_page_preview}; - $send_args->{disable_notification} = $args->{disable_notification} if exists $args->{disable_notification}; - $send_args->{reply_to_message_id} = $args->{reply_to_message_id} if exists $args->{reply_to_message_id}; + $send_args->{disable_notification} = $args->{disable_notification} if exists $args->{disable_notification}; + $send_args->{reply_to_message_id} = $args->{reply_to_message_id} if exists $args->{reply_to_message_id}; # check reply_markup is the right kind if (exists $args->{reply_markup}) { my $reply_markup = $args->{reply_markup}; - if ( ref($reply_markup) ne 'Teapot::Bot::Object::InlineKeyboardMarkup' && - ref($reply_markup) ne 'Teapot::Bot::Object::ReplyKeyboardMarkup' && - ref($reply_markup) ne 'Teapot::Bot::Object::ReplyKeyboardRemove' && + if ( ref($reply_markup) ne 'Teapot::Bot::Object::InlineKeyboardMarkup' || + ref($reply_markup) ne 'Teapot::Bot::Object::ReplyKeyboardMarkup' || + ref($reply_markup) ne 'Teapot::Bot::Object::ReplyKeyboardRemove' || ref($reply_markup) ne 'Teapot::Bot::Object::ForceReply' ) { - cluck 'Incorrect reply_markup in sendMessage()'; - return {'error' => 1}; + $ret->{error} = 1; + $ret->{message} = 'Incorrect reply_markup in sendMessage()'; + + return $ret; } $send_args->{reply_markup} = $reply_markup; } - my $token = $self->token || croak 'No token supplied to sendMessage()?'; - my $url = "https://api.telegram.org/bot${token}/sendMessage"; + my $url = sprintf 'https://api.telegram.org/bot%s/sendMessage', $self->token; my $api_response = $self->_post_request($url, $send_args); unless ($api_response->{error}) { @@ -342,49 +471,55 @@ sub sendMessage { } } - sub forwardMessage { my $self = shift; my $args = shift || {}; my $send_args = {}; + my $ret; + unless ($args->{chat_id}) { - cluck 'No chat_id supplied in forwardMessage()'; - return {'error' => 1}; + $ret->{error} = 1; + $ret->{message} = 'No chat_id supplied in forwardMessage()'; + + return $ret; } - $send_args->{chat_id} = $args->{chat_id}; + unless ($args->{message_id}) { + $ret->{error} = 1; + $ret->{message} = 'No message_id supplied in forwardMessage()'; - if (defined $args->{message_thread_id}) { - $send_args->{message_thread_id} = $args->{message_thread_id}; + return $ret; } unless ($args->{from_chat_id}) { - cluck 'No from_chat_id supplied in forwardMessage()'; - return {'error' => 1}; + $ret->{error} = 1; + $ret->{message} = 'No from_chat_id supplied in forwardMessage()'; + + return $ret; } - $send_args->{from_chat_id} = $args->{from_chat_id}; + if (! defined($self->token) || $self->token eq '') { + $ret->{error} = 1; + $ret->{message} = 'No token supplied to forwardMessage()'; - unless ($args->{message_id}) { - cluck 'No message_id supplied in forwardMessage()'; - return {'error' => 1}; + return $ret; } - $send_args->{message_id} = $args->{message_id}; - - # these are optional, send if they are supplied + $send_args->{chat_id} = $args->{chat_id}; + $send_args->{from_chat_id} = $args->{from_chat_id}; + $send_args->{message_id} = $args->{message_id}; + $send_args->{message_thread_id} = $args->{message_thread_id} if exists $args->{message_thread_id}; $send_args->{disable_notification} = $args->{disable_notification} if exists $args->{disable_notification}; - my $token = $self->token || croak 'No token supplied to forwardMessage()?'; - my $url = "https://api.telegram.org/bot${token}/forwardMessage"; + my $url = sprintf 'https://api.telegram.org/bot%s/forwardMessage', $self->token; my $api_response = $self->_post_request($url, $send_args); unless ($api_response->{error}) { return Teapot::Bot::Object::Message->create_from_hash($api_response, $self); } else { - return {'error' => 1}; + return $api_response; } } @@ -392,289 +527,340 @@ sub forwardMessage { sub deleteMessage { my $self = shift; my $args = shift || {}; + my $send_args = {}; + my $ret; unless ($args->{chat_id}) { - cluck 'No chat_id supplied in deleteMessage()'; - return {'error' => 1}; - } + $ret->{error} = 1; + $ret->{message} = 'No chat_id supplied in deleteMessage()'; - $send_args->{chat_id} = $args->{chat_id}; + return $ret; + } unless ($args->{message_id}) { - cluck 'No message_id supplied in deleteMessage()'; - return {'error' => 1}; + $ret->{error} = 1; + $ret->{message} = 'No message_id supplied in deleteMessage()'; + + return $ret; } + if (! defined($self->token) || $self->token eq '') { + $ret->{error} = 1; + $ret->{message} = 'No token supplied to deleteMessage()'; + + return $ret; + } + + $send_args->{chat_id} = $args->{chat_id}; $send_args->{message_id} = $args->{message_id}; - my $token = $self->token || croak 'No token supplied to deleteMessage()?'; - + # TODO: fix canDeleteMessage() && export it in this fle if (Teapot::Bot::Object::ChatMember->canDeleteMessage($self, $args->{chat_id})) { - my $url = "https://api.telegram.org/bot${token}/deleteMessage"; - $self->_post_request($url, $send_args); + my $url = sprintf 'https://api.telegram.org/bot%s/deleteMessage', $self->token; + + return $self->_post_request($url, $send_args); } else { - return {'error' => 1}; + $ret->{message} = 'Unable to delete message: Not allowed'; + $ret->{error} = 1; + + return $ret; } - - return; } - sub sendPhoto { my $self = shift; my $args = shift || {}; + my $send_args = {}; - if (defined $args->{message_thread_id}) { - $send_args->{message_thread_id} = $args->{message_thread_id}; - } + my $ret; unless ($args->{chat_id}) { - cluck 'No chat_id supplied to sendPhoto()'; - return {'error' => 1}; + $ret->{error} = 1; + $ret->{message} = 'No chat_id supplied in sendPhoto()'; + + return $ret; } - $send_args->{chat_id} = $args->{chat_id}; + unless ($args->{message_id}) { + $ret->{error} = 1; + $ret->{message} = 'No message_id supplied in sendPhoto()'; + + return $ret; + } + + if (! defined($self->token) || $self->token eq '') { + $ret->{error} = 1; + $ret->{message} = 'No token supplied to sendPhoto()'; + + return $ret; + } # photo can be a string (which might be either a URL for telegram servers # to fetch, or a file_id string) or a file on disk to upload - we need # to handle that last case here as it changes the way we create the HTTP # request unless ($args->{photo}) { - cluck 'No photo supplied in sendPhoto()'; - return {'error' => 1}; + $ret->{error} = 1; + $ret->{message} = 'No photo supplied in sendPhoto()'; + + return $ret; } + $send_args->{chat_id} = $args->{chat_id}; + $send_args->{message_thread_id} = $args->{message_thread_id} if exists $args->{message_thread_id}; + if (-e $args->{photo}) { - $send_args->{photo} = { file => $args->{photo} }; + $send_args->{photo} = { file => $args->{photo} }; } else { - $send_args->{photo} = $args->{photo}; + $send_args->{photo} = $args->{photo}; } - my $token = $self->token || croak 'No token in sendPhoto()?'; - my $url = "https://api.telegram.org/bot${token}/sendPhoto"; + my $url = sprintf 'https://api.telegram.org/bot%s/sendPhoto', $self->token; my $api_response = $self->_post_request($url, $send_args); unless ($api_response->{error}) { return Teapot::Bot::Object::Message->create_from_hash($api_response, $self); } else { - return {'error' => 1}; + return $api_response; } } - sub sendChatAction { my $self = shift; my $args = shift || {}; + my $send_args = {}; + my $ret; unless ($args->{chat_id}) { - cluck 'No chat_id supplied in sendChatAction()'; - return {'error' => 1}; + $ret->{error} = 1; + $ret->{message} = 'No chat_id supplied in sendChatAction()'; + + return $ret; } + if (! defined($self->token) || $self->token eq '') { + $ret->{error} = 1; + $ret->{message} = 'No token supplied to sendChatAction()'; + + return $ret; + } + + $args->{action} = 'typing' unless (defined $args->{action}); + $send_args->{chat_id} = $args->{chat_id}; + $send_args->{action} = 'typing'; + $send_args->{action} = 'upload_photo' if ($args->{action} eq 'upload_photo'); + $send_args->{action} = 'record_video' if ($args->{action} eq 'record_video'); + $send_args->{action} = 'upload_video' if ($args->{action} eq 'upload_video'); + $send_args->{action} = 'record_voice' if ($args->{action} eq 'record_voice'); + $send_args->{action} = 'upload_voice' if ($args->{action} eq 'upload_voice'); + $send_args->{action} = 'upload_document' if ($args->{action} eq 'upload_document'); + $send_args->{action} = 'find_location' if ($args->{action} eq 'find_location'); + $send_args->{action} = 'record_video_note' if ($args->{action} eq 'record_video_note'); + $send_args->{action} = 'upload_video_note' if ($args->{action} eq 'upload_video_note'); + $send_args->{action} = 'choose_sticker' if ($args->{action} eq 'choose_sticker'); - unless (defined $args->{action}) { - $args->{action} = 'typing'; - $send_args->{action} = 'typing'; - } + my $url = sprintf 'https://api.telegram.org/bot%s/sendChatAction', $self->token; - if ($args->{action} eq 'upload_photo') { - $send_args->{action} = 'upload_photo'; - } - elsif ($args->{action} eq 'record_video') { - $send_args->{action} = 'record_video'; - } - elsif ($args->{action} eq 'upload_video') { - $send_args->{action} = 'upload_video'; - } - elsif ($args->{action} eq 'record_voice') { - $send_args->{action} = 'record_voice'; - } - elsif ($args->{action} eq 'upload_voice') { - $send_args->{action} = 'upload_voice'; - } - elsif ($args->{action} eq 'upload_document') { - $send_args->{action} = 'upload_document'; - } - elsif ($args->{action} eq 'find_location') { - $send_args->{action} = 'find_location'; - } - elsif ($args->{action} eq 'record_video_note') { - $send_args->{action} = 'record_video_note'; - } - elsif ($args->{action} eq 'upload_video_note') { - $send_args->{action} = 'upload_video_note'; - } - elsif ($args->{action} eq 'choose_sticker') { - $send_args->{action} = 'choose_sticker'; - } - else { - $send_args->{action} = 'typing'; - } - - my $token = $self->token || croak 'No token in sendChatAction()?'; - my $url = "https://api.telegram.org/bot${token}/sendChatAction"; - my $api_response = $self->_post_request ($url, $send_args); - - return; + return $self->_post_request($url, $send_args); } sub exportChatInviteLink { my $self = shift; my $args = shift || {}; - my $send_args = {}; - my $token = $self->token || croak 'No token supplied to createChatInviteLink()?'; + my $send_args = {}; + my $ret; + + if (! defined($self->token) || $self->token eq '') { + $ret->{error} = 1; + $ret->{message} = 'No token supplied to exportChatInviteLink()'; + + return $ret; + } unless ($args->{chat_id}) { - cluck 'No chat_id supplied in createChatInviteLink()'; - return {'error' => 1}; + $ret->{error} = 1; + $ret->{message} = 'No chat_id supplied in exportChatInviteLink()'; + + return $ret; } $send_args->{chat_id} = $args->{chat_id}; - my $url = "https://api.telegram.org/bot${token}/exportChatInviteLink"; - my $api_response = $self->_post_request($url); + my $url = sprintf 'https://api.telegram.org/bot%s/exportChatInviteLink', $self->token; - if ($api_response->{error}) { - return $api_response; - } - else { - return {'error' => 1}; - } + return $self->_post_request($url, $send_args); } sub createChatInviteLink { my $self = shift; my $args = shift || {}; + my $send_args = {}; + my $ret; - my $token = $self->token || croak 'No token supplied to createChatInviteLink()?'; + if (! defined($self->token) || $self->token eq '') { + $ret->{error} = 1; + $ret->{message} = 'No token supplied to createChatInviteLink()'; - unless ($args->{chat_id}) { - cluck 'No chat_id supplied in createChatInviteLink()'; - return {'error' => 1}; + return $ret; } - $send_args->{chat_id} = $args->{chat_id}; - $send_args->{expire_date} = $args->{expire_date} if exists $args->{expire_date}; + unless ($args->{chat_id}) { + $ret->{error} = 1; + $ret->{message} = 'No chat_id supplied in createChatInviteLink()'; + + return $ret; + } + + $send_args->{chat_id} = $args->{chat_id}; + $send_args->{expire_date} = $args->{expire_date} if exists $args->{expire_date}; $send_args->{member_limit} = $args->{member_limit} if exists $args->{member_limit}; - my $url = "https://api.telegram.org/bot${token}/createChatInviteLink"; - my $api_response = $self->_post_request($url); + my $url = sprintf 'https://api.telegram.org/bot%s/createChatInviteLink', $self->token; + my $api_response = $self->_post_request($url, $send_args); unless ($api_response->{error}) { return Teapot::Bot::Object::ChatInviteLink->create_from_hash($api_response, $self); } else { - return {'error' => 1}; + return $api_response; } } sub editChatInviteLink { my $self = shift; my $args = shift || {}; - my $send_args = {}; - my $token = $self->token || croak 'No token supplied to editChatInviteLink()?'; + my $send_args = {}; + my $ret; + + if (! defined($self->token) || $self->token eq '') { + $ret->{error} = 1; + $ret->{message} = 'No token supplied to editChatInviteLink()'; + + return $ret; + } unless ($args->{chat_id}) { - cluck 'No chat_id supplied in editChatInviteLink()'; - return {'error' => 1}; + $ret->{error} = 1; + $ret->{message} = 'No chat_id supplied in editChatInviteLink()'; + + return $ret; } unless ($args->{invite_link}) { - cluck 'No invite_link supplied in editChatInviteLink()'; - return {'error' => 1}; + $ret->{error} = 1; + $ret->{message} = 'No invite_link supplied in editChatInviteLink()'; + + return $ret; } - $send_args->{chat_id} = $args->{chat_id}; - $send_args->{invite_link} = $args->{invite_link}; - $send_args->{expire_date} = $args->{expire_date} if exists $args->{expire_date}; + $send_args->{chat_id} = $args->{chat_id}; + $send_args->{invite_link} = $args->{invite_link}; + $send_args->{expire_date} = $args->{expire_date} if exists $args->{expire_date}; $send_args->{member_limit} = $args->{member_limit} if exists $args->{member_limit}; - my $url = "https://api.telegram.org/bot${token}/editChatInviteLink"; - my $api_response = $self->_post_request($url); + my $url = sprintf 'https://api.telegram.org/bot%s/editChatInviteLink', $self->token; + my $api_response = $self->_post_request($url, $send_args); unless ($api_response->{error}) { return Teapot::Bot::Object::ChatInviteLink->create_from_hash($api_response, $self); } else { - return {'error' => 1}; + return $api_response; } } sub revokeChatInviteLink { my $self = shift; my $args = shift || {}; - my $send_args = {}; - my $token = $self->token || croak 'No token supplied to revokeChatInviteLink()?'; + my $send_args = {}; + my $ret; + + if (! defined($self->token) || $self->token eq '') { + $ret->{error} = 1; + $ret->{message} = 'No token supplied to revokeChatInviteLink()'; + + return $ret; + } unless ($args->{chat_id}) { - cluck 'No chat_id supplied in revokeChatInviteLink()'; - return {'error' => 1}; + $ret->{error} = 1; + $ret->{message} = 'No chat_id supplied in revokeChatInviteLink()'; + + return $ret; } unless ($args->{invite_link}) { - cluck 'No invite_link supplied in revokeChatInviteLink()'; - return {'error' => 1}; + $ret->{error} = 1; + $ret->{message} = 'No invite_link supplied in revokeChatInviteLink()'; + + return $ret; } - $send_args->{chat_id} = $args->{chat_id}; + $send_args->{chat_id} = $args->{chat_id}; $send_args->{invite_link} = $args->{invite_link}; - my $url = "https://api.telegram.org/bot${token}/revokeChatInviteLink"; - my $api_response = $self->_post_request($url); + my $url = sprintf 'https://api.telegram.org/bot%s/revokeChatInviteLink', $self->token; + my $api_response = $self->_post_request($url, $send_args); unless ($api_response->{error}) { return Teapot::Bot::Object::ChatInviteLink->create_from_hash($api_response, $self); } else { - return {'error' => 1}; + return $api_response; } } sub _add_getUpdates_handler { my $self = shift; - my $http_active = 0; + my $http_active = 0; my $last_update_id = -1; - my $token = $self->token; + my $token = $self->token; - Mojo::IOLoop->recurring(0.1 => sub { - # do nothing if our previous longpoll is still going - return if $http_active; + Mojo::IOLoop->recurring( + 0.1 => sub { + # do nothing if our previous longpoll is still going + return if $http_active; - my $offset = $last_update_id + 1; - my $updateURL = "https://api.telegram.org/bot${token}/getUpdates?offset=${offset}&timeout=60"; - $http_active = 1; + my $offset = $last_update_id + 1; + my $updateURL = "https://api.telegram.org/bot${token}/getUpdates?offset=${offset}&timeout=60"; + $http_active = 1; - $self->ua->get($updateURL => sub { - my ($ua, $tx) = @_; - my $res = eval { $tx->res->json; }; + $self->ua->get( + $updateURL => sub { + my ($ua, $tx) = @_; - # it looks like we can catch an error here if timeout or something bad occurs, - # try not to die in this case or we risk to stuck with $http_active=1 forever - if ((defined $res) && $res ne '') { - my $items = $res->{result}; - foreach my $item (@{$items}) { - $last_update_id = $item->{update_id}; - $self->_process_message($item); + # it looks like we can catch an error here if timeout or something bad occurs, + # try not to die in this case or we risk to stuck with $http_active=1 forever + my $res = eval { $tx->res->json; }; + + if ((defined $res) && $res ne '') { + my $items = $res->{result}; + + foreach my $item (@{$items}) { + $last_update_id = $item->{update_id}; + $self->_process_message($item); + } + } else { + cluck "Unable to get update from API: $EVAL_ERROR"; + } + + $http_active = 0; } - } else { - cluck "Unable to get update from API: $EVAL_ERROR"; - } - - $http_active = 0; - }); - }); + ); + } + ); return; } @@ -730,40 +916,29 @@ sub _process_message { return; } - sub _post_request { - my $self = shift; - my $url = shift; + my $self = shift; + my $url = shift; my $form_args = shift || {}; + my $result; my $res = $self->ua->post($url, form => $form_args)->result; if ($res->is_success) { - return $res->json->{result}; + $result = $res->json->{result}; } elsif ($res->is_error) { - my $result->{error} = 1; - # This can be non-fatal error: api change. - #cluck 'Failed to post: ' . $res->message; - carp 'Failed to post to: ' . $res->message; - - carp sprintf ( - "Input parameters: %s\nResonse Dump: %s\nURL:%s\n", - Dumper ($form_args), - Dumper ($res), - $url, - ); - - $result->{message} = $res->content; - $result->{http_code} = $res->code; - $result->{param} = $form_args; - - return $result; # to handle this in upper layers + $result->{error} = 1; + $result->{debug} = $res; + $result->{param} = $form_args; + $result->{url} = $url; } else { # This must be something fatal for sure, because either is_success or is_error must be set by Mojo confess 'Not sure what went wrong'; } + + return $result; } @@ -781,7 +956,7 @@ Teapot::Bot::Brain - A base class to make your very own Telegram bot =head1 VERSION -version 0.024 +version 0.025 =head1 SYNOPSIS @@ -861,7 +1036,8 @@ L. Takes no arguments, and returns the L that represents this bot. -On error returns hash reference with error set to 1 +On error returns hash reference with error field set to 1, also set fields +param, url and debug (which is result of Mojo::UserAgent->post->result->json) =head2 getChatMember @@ -873,7 +1049,8 @@ Takes chat_id, and user_id as arguments. Returns the L that represents properties of Chat User. -On error returns hash reference with error set to 1 +On error returns hash reference with error field set to 1, also set fields +param, url and debug (which is result of Mojo::UserAgent->post->result->json) =head2 banChatMember @@ -883,7 +1060,10 @@ L. Takes chat_id, and user_id as arguments. And optionally until_date and revoke_messages. -Returns nothing, it's send-only method (Telegram API returns true on success) +Returns Telegram API answer that is basically returns true on success. + +On error returns hash reference with error field set to 1, also set fields +param, url and debug (which is result of Mojo::UserAgent->post->result->json) =head2 unbanChatMember @@ -892,7 +1072,10 @@ L. Takes chat_id, and user_id as arguments. And optionally only_if_banned. -Returns nothing, it's send-only method (Telegram API returns true on success) +Returns Telegram API answer that is basically returns true on success. + +On error returns hash reference with error field set to 1, also set fields +param, url and debug (which is result of Mojo::UserAgent->post->result->json) =head2 muteChatMember @@ -901,9 +1084,12 @@ L. Takes chat_id, and user_id as arguments. And optionally until_date. -Shorthand for revoking all perminnsions for member being muted. +Shorthand for revoking all permissions for member being muted. -Returns nothing, it's send-only method (Telegram API returns true on success) +Returns Telegram API answer that is basically returns true on success. + +On error returns hash reference with error field set to 1, also set fields +param, url and debug (which is result of Mojo::UserAgent->post->result->json) =head2 getChat @@ -914,7 +1100,8 @@ Takes chat_id as argument. Returns the L that represents properties of Chat. -On error returns hash reference with error set to 1 +On error returns hash reference with error field set to 1, also set fields +param, url and debug (which is result of Mojo::UserAgent->post->result->json) =head2 leaveChat @@ -923,7 +1110,20 @@ L. Takes chat_id as argument. -Returns nothing, it's send-only method (Telegram API returns true on success) +Returns Telegram API answer that is basically returns true on success. + +On error returns hash reference with error field set to 1, also set fields +param, url and debug (which is result of Mojo::UserAgent->post->result->json) + +=head2 can_talk + +Returns hash reference with error set to 0 and can_talk set either to 0 if bot +is unable to sendMessage() to chat or 1 if bot can sendMessage() to chat. + +On error returns hash reference with error set to 1 and can_talk set to 0 +Also can return hash reference with error field set to 1, also set fields +param, url and debug (which is result of Mojo::UserAgent->post->result->json) if +error caught during calling BotAPI. =head2 sendMessage @@ -931,7 +1131,10 @@ See L. Returns a L object. -On error returns hash reference with error set to 1 +On error returns hash reference with error set to 1. +Also can return hash reference with error field set to 1, also set fields +param, url and debug (which is result of Mojo::UserAgent->post->result->json) if +error caught during calling BotAPI. =head2 forwardMessage @@ -947,7 +1150,10 @@ See L. Returns a L object. -On error returns hash reference with error set to 1 +On error returns hash reference with error set to 1. +Also can return hash reference with error field set to 1, also set fields +param, url and debug (which is result of Mojo::UserAgent->post->result->json) if +error caught during calling BotAPI. =head2 sendPhoto @@ -961,6 +1167,10 @@ On error returns hash reference with error set to 1 See L. Returns nothing, it's send-only method (Telegram API returns true on success) +On error returns hash reference with error set to 1. +Also can return hash reference with error field set to 1, also set fields +param, url and debug (which is result of Mojo::UserAgent->post->result->json) if +error caught during calling BotAPI. =head2 exportChatInviteLink @@ -970,7 +1180,10 @@ Takes chat_id as argument. Returns a raw api answer. -On error returns hash reference with error set to 1 +On error returns hash reference with error set to 1. +Also can return hash reference with error field set to 1, also set fields +param, url and debug (which is result of Mojo::UserAgent->post->result->json) if +error caught during calling BotAPI. =head2 createChatInviteLink @@ -980,7 +1193,10 @@ Takes chat_id as argument. And optionally expire_date and member_limit. Returns a L object. -On error returns hash reference with error set to 1 +On error returns hash reference with error set to 1. +Also can return hash reference with error field set to 1, also set fields +param, url and debug (which is result of Mojo::UserAgent->post->result->json) if +error caught during calling BotAPI. =head2 editChatInviteLink @@ -991,7 +1207,10 @@ and member_limit. Returns a L object. -On error returns hash reference with error set to 1 +On error returns hash reference with error set to 1. +Also can return hash reference with error field set to 1, also set fields +param, url and debug (which is result of Mojo::UserAgent->post->result->json) if +error caught during calling BotAPI. =head2 revokeChatInviteLink @@ -1001,7 +1220,10 @@ Takes chat_id and invite_link as arguments. Returns a L object. -On error returns hash reference with error set to 1 +On error returns hash reference with error set to 1. +Also can return hash reference with error field set to 1, also set fields +param, url and debug (which is result of Mojo::UserAgent->post->result->json) if +error caught during calling BotAPI. =head1 SEE ALSO @@ -1042,3 +1264,5 @@ This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut + +# vim: set ft=perl noet ai ts=2 sw=2 sts=2: diff --git a/lib/Teapot/Bot/Object/Animation.pm b/lib/Teapot/Bot/Object/Animation.pm index a688658..56706a2 100644 --- a/lib/Teapot/Bot/Object/Animation.pm +++ b/lib/Teapot/Bot/Object/Animation.pm @@ -9,7 +9,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; use Teapot::Bot::Object::PhotoSize (); -$Teapot::Bot::Object::Animation::VERSION = '0.024'; +$Teapot::Bot::Object::Animation::VERSION = '0.025'; has 'file_id'; has 'file_unique_id'; @@ -43,7 +43,7 @@ Teapot::Bot::Object::Animation - The base class for Telegram message 'Animation' =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram message 'Animation' type. diff --git a/lib/Teapot/Bot/Object/Audio.pm b/lib/Teapot/Bot/Object/Audio.pm index 7965bcc..a73efb8 100644 --- a/lib/Teapot/Bot/Object/Audio.pm +++ b/lib/Teapot/Bot/Object/Audio.pm @@ -8,7 +8,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; -$Teapot::Bot::Object::Audio::VERSION = '0.024'; +$Teapot::Bot::Object::Audio::VERSION = '0.025'; has 'file_id'; has 'file_unique_id'; @@ -41,7 +41,7 @@ Teapot::Bot::Object::Audio - The base class for Telegram 'Audio' type objects =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram 'Audio' type objects. diff --git a/lib/Teapot/Bot/Object/Base.pm b/lib/Teapot/Bot/Object/Base.pm index dc45766..37d917f 100644 --- a/lib/Teapot/Bot/Object/Base.pm +++ b/lib/Teapot/Bot/Object/Base.pm @@ -13,7 +13,7 @@ use List::Util qw/any/; use Mojo::Base -base; -$Teapot::Bot::Object::Base::VERSION = '0.024'; +$Teapot::Bot::Object::Base::VERSION = '0.025'; has '_brain'; # a reference to our brain @@ -187,7 +187,7 @@ Teapot::Bot::Object::Base - The base class for all Telegram::Bot::Object objects =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION diff --git a/lib/Teapot/Bot/Object/CallbackGame.pm b/lib/Teapot/Bot/Object/CallbackGame.pm index 5ae2c72..82186fe 100644 --- a/lib/Teapot/Bot/Object/CallbackGame.pm +++ b/lib/Teapot/Bot/Object/CallbackGame.pm @@ -7,7 +7,7 @@ use 5.018; ## no critic (ProhibitImplicitImport) use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; -$Teapot::Bot::Object::CallbackGame::VERSION = '0.024'; +$Teapot::Bot::Object::CallbackGame::VERSION = '0.025'; # https://core.telegram.org/bots/api#callbackgame # "A placeholder, currently holds no information. Use BotFather to set up your game" @@ -30,7 +30,7 @@ Teapot::Bot::Object::CallbackGame - The base class for Telegram message 'Callbac =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram message 'CallbackGame' type. diff --git a/lib/Teapot/Bot/Object/Chat.pm b/lib/Teapot/Bot/Object/Chat.pm index 1a8c9e2..c3b9bfe 100644 --- a/lib/Teapot/Bot/Object/Chat.pm +++ b/lib/Teapot/Bot/Object/Chat.pm @@ -12,7 +12,7 @@ use Teapot::Bot::Object::Message (); use Teapot::Bot::Object::ChatPermissions (); use Teapot::Bot::Object::ChatLocation (); -$Teapot::Bot::Object::Chat::VERSION = '0.024'; +$Teapot::Bot::Object::Chat::VERSION = '0.025'; has 'id'; has 'type'; @@ -86,7 +86,7 @@ Teapot::Bot::Object::Chat - The base class for Telegram 'Chat' type objects =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram 'Chat' type objects. diff --git a/lib/Teapot/Bot/Object/ChatInviteLink.pm b/lib/Teapot/Bot/Object/ChatInviteLink.pm index b129c86..2110488 100644 --- a/lib/Teapot/Bot/Object/ChatInviteLink.pm +++ b/lib/Teapot/Bot/Object/ChatInviteLink.pm @@ -9,7 +9,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; use Teapot::Bot::Object::User (); -$Teapot::Bot::Object::ChatInviteLink::VERSION = '0.024'; +$Teapot::Bot::Object::ChatInviteLink::VERSION = '0.025'; has 'invite_link'; has 'creator'; @@ -44,7 +44,7 @@ Teapot::Bot::Object::ChatInviteLink - The base class for Telegram message 'ChatI =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram message 'ChatInviteLink' type. diff --git a/lib/Teapot/Bot/Object/ChatLocation.pm b/lib/Teapot/Bot/Object/ChatLocation.pm index 85e60f4..4e17aa0 100644 --- a/lib/Teapot/Bot/Object/ChatLocation.pm +++ b/lib/Teapot/Bot/Object/ChatLocation.pm @@ -8,7 +8,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; -$Teapot::Bot::Object::ChatLocation::VERSION = '0.024'; +$Teapot::Bot::Object::ChatLocation::VERSION = '0.025'; has 'location'; has 'address'; @@ -34,7 +34,7 @@ Teapot::Bot::Object::ChatLocation - The base class for Telegram message 'ChatLoc =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram message 'ChatLocation' type. diff --git a/lib/Teapot/Bot/Object/ChatMember.pm b/lib/Teapot/Bot/Object/ChatMember.pm index 6b4a025..65511ea 100644 --- a/lib/Teapot/Bot/Object/ChatMember.pm +++ b/lib/Teapot/Bot/Object/ChatMember.pm @@ -12,7 +12,7 @@ use Mojo::Base 'Teapot::Bot::Object::Base'; use Teapot::Bot::Object::User (); -$Teapot::Bot::Object::ChatMember::VERSION = '0.024'; +$Teapot::Bot::Object::ChatMember::VERSION = '0.025'; # ChatMemberOwner has 'user'; @@ -147,7 +147,7 @@ Teapot::Bot::Object::ChatMember - The base class for Telegram 'ChatMember' type =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram 'ChatMember' type objects. diff --git a/lib/Teapot/Bot/Object/ChatMemberUpdated.pm b/lib/Teapot/Bot/Object/ChatMemberUpdated.pm index a37ffcf..617e6b0 100644 --- a/lib/Teapot/Bot/Object/ChatMemberUpdated.pm +++ b/lib/Teapot/Bot/Object/ChatMemberUpdated.pm @@ -13,7 +13,7 @@ use Teapot::Bot::Object::ChatMember (); use Teapot::Bot::Object::ChatInviteLink (); use Teapot::Bot::Object::Voice (); -$Teapot::Bot::Object::ChatMemberUpdated::VERSION = '0.024'; +$Teapot::Bot::Object::ChatMemberUpdated::VERSION = '0.025'; has 'chat'; has 'from'; @@ -50,7 +50,7 @@ Teapot::Bot::Object::ChatMemberUpdated - The base class for Telegram 'ChatMember =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram 'ChatMemberUpdated' type objects. diff --git a/lib/Teapot/Bot/Object/ChatPermissions.pm b/lib/Teapot/Bot/Object/ChatPermissions.pm index e5fc72c..1200044 100644 --- a/lib/Teapot/Bot/Object/ChatPermissions.pm +++ b/lib/Teapot/Bot/Object/ChatPermissions.pm @@ -10,7 +10,7 @@ use Carp qw(carp); use Mojo::Base 'Teapot::Bot::Object::Base'; use Teapot::Bot::Brain (); -$Teapot::Bot::Object::ChatPermissions::VERSION = '0.024'; +$Teapot::Bot::Object::ChatPermissions::VERSION = '0.025'; # all fields are optional # N.B. Some of the fields "overlaps" other, so in order to guess valid set of permissions you should check all of them @@ -38,11 +38,38 @@ sub fields { } sub canTalk { - my $self = shift; + my $self; + my $args = {}; + + # There is some magic happen if we call function as object, as we usually do here + # But if we access function from usual-style wrapper that calls it directly from namespace it supply noy $self object + # but string with its name, which is a bummer. + while (my $o = shift @_) { + if (ref ($o) ne '') { + $self = $o; + last; + } + } + my $chatid = shift; - my $args->{chat_id} = $chatid; + $args->{chat_id} = $chatid; my $can_talk = 0; + my $ret; + + if (! defined($self->token) || $self->token eq '') { + $ret->{error} = 1; + $ret->{message} = 'No token supplied to canTalk()'; + + return $ret; + } + + unless ($args->{chat_id}) { + $ret->{error} = 1; + $ret->{message} = 'No chat_id supplied to canTalk()'; + + return $ret; + } if ($chatid < 0) { # group chat @@ -50,16 +77,23 @@ sub canTalk { # on api error, keep silence if ($chatobj == 0 || $chatobj->{error}) { - carp "Unable to get chat info for $chatid from telegram API"; - return $can_talk; + my $emesg = "Unable to get chat info for $chatid from telegram API"; + $ret->{message} = $emesg; + $ret->{error} = 1; + $ret->{can_talk} = 0; + return $ret; } my $myObj = Teapot::Bot::Brain->getMe ($self); # on api error, keep silence if ($myObj == 0 || $myObj->{error}) { - carp "Unable to get chat info for $chatid from telegram API"; - return $can_talk; + my $emesg = "Unable to get chat info for $chatid from telegram API"; + $ret->{message} = $emesg; + $ret->{error} = 1; + $ret->{can_talk} = 0; + + return $ret; } my $myid = $myObj->id; @@ -68,8 +102,12 @@ sub canTalk { # on api error, keep silence if ($me == 0 || $me->{error}) { - carp 'Unable to get chat info for bot itself from telegram API'; - return $can_talk; + my $emesg = 'Unable to get chat info for bot itself from telegram API'; + $ret->{message} = $emesg; + $ret->{error} = 1; + $ret->{can_talk} = 0; + + return $ret; } if ($me->{'status'} eq 'administrator') { @@ -83,9 +121,13 @@ sub canTalk { $can_talk = 1; } - return $can_talk; + $ret->{error} = 0; + $ret->{can_talk} = $can_talk; + + return $ret; } + 1; __END__ @@ -100,7 +142,7 @@ Teapot::Bot::Object::ChatPermissions - The base class for Telegram 'ChatPermissi =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram 'ChatPermissions' type objects. @@ -114,7 +156,9 @@ attributes available for C objects. A convenience method to check if bot can talk in given conversation. -Returns true if the bot can talk in given conversation, otherwise false. +Returns hash reference with can_talk true if the bot can talk in given conversation, otherwise false. +Also set field error 1 if an error occurs during api interaction. +And if error set to true message field also set plus can_talk set to false. =head1 AUTHOR diff --git a/lib/Teapot/Bot/Object/ChatPhoto.pm b/lib/Teapot/Bot/Object/ChatPhoto.pm index c775cc7..8fb9513 100644 --- a/lib/Teapot/Bot/Object/ChatPhoto.pm +++ b/lib/Teapot/Bot/Object/ChatPhoto.pm @@ -8,7 +8,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; -$Teapot::Bot::Object::ChatPhoto::VERSION = '0.024'; +$Teapot::Bot::Object::ChatPhoto::VERSION = '0.025'; has 'small_file_id'; has 'small_file_unique_id'; @@ -35,7 +35,7 @@ Teapot::Bot::Object::ChatPhoto - The base class for Telegram 'ChatPhoto' type ob =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram 'ChatPhoto' type objects. diff --git a/lib/Teapot/Bot/Object/Contact.pm b/lib/Teapot/Bot/Object/Contact.pm index 9cbb12f..86edd76 100644 --- a/lib/Teapot/Bot/Object/Contact.pm +++ b/lib/Teapot/Bot/Object/Contact.pm @@ -8,7 +8,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; -$Teapot::Bot::Object::Contact::VERSION = '0.024'; +$Teapot::Bot::Object::Contact::VERSION = '0.025'; has 'phone_number'; has 'first_name'; @@ -36,7 +36,7 @@ Teapot::Bot::Object::Contact - The base class for Telegram 'Contact' objects =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram 'Contact' objects. diff --git a/lib/Teapot/Bot/Object/Dice.pm b/lib/Teapot/Bot/Object/Dice.pm index a40c490..6a97a5d 100644 --- a/lib/Teapot/Bot/Object/Dice.pm +++ b/lib/Teapot/Bot/Object/Dice.pm @@ -8,7 +8,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; -$Teapot::Bot::Object::Dice::VERSION = '0.024'; +$Teapot::Bot::Object::Dice::VERSION = '0.025'; has 'emoji'; has 'value'; @@ -31,7 +31,7 @@ Teapot::Bot::Object::Dice - The base class for Telegram message 'Dice' type =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram message 'Dice' type. diff --git a/lib/Teapot/Bot/Object/Document.pm b/lib/Teapot/Bot/Object/Document.pm index 8bf8d95..f582415 100644 --- a/lib/Teapot/Bot/Object/Document.pm +++ b/lib/Teapot/Bot/Object/Document.pm @@ -9,7 +9,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; use Teapot::Bot::Object::PhotoSize (); -$Teapot::Bot::Object::Document::VERSION = '0.024'; +$Teapot::Bot::Object::Document::VERSION = '0.025'; has 'file_id'; has 'file_unique_id'; @@ -39,7 +39,7 @@ Teapot::Bot::Object::Document - The base class for Telegram 'Document' objects =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram 'Document' objects. diff --git a/lib/Teapot/Bot/Object/EncryptedCredentials.pm b/lib/Teapot/Bot/Object/EncryptedCredentials.pm index 3657443..f031775 100644 --- a/lib/Teapot/Bot/Object/EncryptedCredentials.pm +++ b/lib/Teapot/Bot/Object/EncryptedCredentials.pm @@ -8,7 +8,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; -$Teapot::Bot::Object::EncryptedCredentials::VERSION = '0.024'; +$Teapot::Bot::Object::EncryptedCredentials::VERSION = '0.025'; has 'data'; has 'hash'; @@ -32,7 +32,7 @@ Teapot::Bot::Object::EncryptedCredentials - The base class for Telegram 'Encrypt =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram 'EncryptedCredentials' type objects. diff --git a/lib/Teapot/Bot/Object/EncryptedPassportElement.pm b/lib/Teapot/Bot/Object/EncryptedPassportElement.pm index 5f881d9..7002117 100644 --- a/lib/Teapot/Bot/Object/EncryptedPassportElement.pm +++ b/lib/Teapot/Bot/Object/EncryptedPassportElement.pm @@ -8,7 +8,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; -$Teapot::Bot::Object::EncryptedPassportElement::VERSION = '0.024'; +$Teapot::Bot::Object::EncryptedPassportElement::VERSION = '0.025'; # XXX Implement rest of this # https://core.telegram.org/bots/api#encryptedpassportelement @@ -38,7 +38,7 @@ Teapot::Bot::Object::EncryptedPassportElement - The base class for Telegram 'Enc =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram 'EncryptedPassportElement' type objects. diff --git a/lib/Teapot/Bot/Object/ForumTopicClosed.pm b/lib/Teapot/Bot/Object/ForumTopicClosed.pm index 04efa9e..864c698 100644 --- a/lib/Teapot/Bot/Object/ForumTopicClosed.pm +++ b/lib/Teapot/Bot/Object/ForumTopicClosed.pm @@ -8,7 +8,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; -$Teapot::Bot::Object::ForumTopicClosed::VERSION = '0.024'; +$Teapot::Bot::Object::ForumTopicClosed::VERSION = '0.025'; sub fields { @@ -29,7 +29,7 @@ Teapot::Bot::Object::ForumTopicClosed - The base class for Telegram message 'Fo =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram message 'ForumTopicClosed' type. diff --git a/lib/Teapot/Bot/Object/ForumTopicCreated.pm b/lib/Teapot/Bot/Object/ForumTopicCreated.pm index f06c068..e4765aa 100644 --- a/lib/Teapot/Bot/Object/ForumTopicCreated.pm +++ b/lib/Teapot/Bot/Object/ForumTopicCreated.pm @@ -8,7 +8,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; -$Teapot::Bot::Object::ForumTopicCreated::VERSION = '0.024'; +$Teapot::Bot::Object::ForumTopicCreated::VERSION = '0.025'; has 'name'; has 'icon_color'; @@ -32,7 +32,7 @@ Teapot::Bot::Object::ForumTopicCreated - The base class for Telegram message 'F =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram message 'ForumTopicCreated' type. diff --git a/lib/Teapot/Bot/Object/ForumTopicReopened.pm b/lib/Teapot/Bot/Object/ForumTopicReopened.pm index 5001e05..554246c 100644 --- a/lib/Teapot/Bot/Object/ForumTopicReopened.pm +++ b/lib/Teapot/Bot/Object/ForumTopicReopened.pm @@ -8,7 +8,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; -$Teapot::Bot::Object::ForumTopicReopened::VERSION = '0.024'; +$Teapot::Bot::Object::ForumTopicReopened::VERSION = '0.025'; sub fields { @@ -29,7 +29,7 @@ Teapot::Bot::Object::ForumTopicReopened - The base class for Telegram message ' =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram message 'ForumTopicReopened' type. diff --git a/lib/Teapot/Bot/Object/Game.pm b/lib/Teapot/Bot/Object/Game.pm index 140dab5..26ec5a1 100644 --- a/lib/Teapot/Bot/Object/Game.pm +++ b/lib/Teapot/Bot/Object/Game.pm @@ -11,7 +11,7 @@ use Teapot::Bot::Object::PhotoSize (); use Teapot::Bot::Object::Animation (); use Teapot::Bot::Object::MessageEntity (); -$Teapot::Bot::Object::Game::VERSION = '0.024'; +$Teapot::Bot::Object::Game::VERSION = '0.025'; has 'title'; has 'description'; @@ -45,7 +45,7 @@ Teapot::Bot::Object::Game - The base class for Telegram message 'Game' type =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram message 'Game' type. diff --git a/lib/Teapot/Bot/Object/InlineKeyboardButton.pm b/lib/Teapot/Bot/Object/InlineKeyboardButton.pm index 7134797..1bdc980 100644 --- a/lib/Teapot/Bot/Object/InlineKeyboardButton.pm +++ b/lib/Teapot/Bot/Object/InlineKeyboardButton.pm @@ -10,7 +10,7 @@ use Mojo::Base 'Teapot::Bot::Object::Base'; use Teapot::Bot::Object::LoginUrl (); use Teapot::Bot::Object::CallbackGame (); -$Teapot::Bot::Object::InlineKeyboardButton::VERSION = '0.024'; +$Teapot::Bot::Object::InlineKeyboardButton::VERSION = '0.025'; has 'text'; has 'url'; @@ -43,7 +43,7 @@ Teapot::Bot::Object::InlineKeyboardButton - The base class for Telegram 'InlineK =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram 'InlineKeyboardButton' type objects. diff --git a/lib/Teapot/Bot/Object/InlineKeyboardMarkup.pm b/lib/Teapot/Bot/Object/InlineKeyboardMarkup.pm index a2cf5d3..947633d 100644 --- a/lib/Teapot/Bot/Object/InlineKeyboardMarkup.pm +++ b/lib/Teapot/Bot/Object/InlineKeyboardMarkup.pm @@ -9,7 +9,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; use Teapot::Bot::Object::InlineKeyboardButton (); -$Teapot::Bot::Object::InlineKeyboardMarkup::VERSION = '0.024'; +$Teapot::Bot::Object::InlineKeyboardMarkup::VERSION = '0.025'; has 'inline_keyboard'; @@ -35,7 +35,7 @@ Teapot::Bot::Object::InlineKeyboardMarkup - The base class for Telegram 'InlineK =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram 'InlineKeyboardMarkup' type objects. diff --git a/lib/Teapot/Bot/Object/Invoice.pm b/lib/Teapot/Bot/Object/Invoice.pm index 9848ed5..3018b20 100644 --- a/lib/Teapot/Bot/Object/Invoice.pm +++ b/lib/Teapot/Bot/Object/Invoice.pm @@ -8,7 +8,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; -$Teapot::Bot::Object::Invoice::VERSION = '0.024'; +$Teapot::Bot::Object::Invoice::VERSION = '0.025'; has 'title'; has 'description'; @@ -34,7 +34,7 @@ Teapot::Bot::Object::Invoice - The base class for Telegram 'Invoice' type object =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram 'Invoice' type objects. diff --git a/lib/Teapot/Bot/Object/Location.pm b/lib/Teapot/Bot/Object/Location.pm index 35d1f22..128403d 100644 --- a/lib/Teapot/Bot/Object/Location.pm +++ b/lib/Teapot/Bot/Object/Location.pm @@ -8,7 +8,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; -$Teapot::Bot::Object::Location::VERSION = '0.024'; +$Teapot::Bot::Object::Location::VERSION = '0.025'; has 'longitude'; has 'latitude'; @@ -35,7 +35,7 @@ Teapot::Bot::Object::Location - The base class for Telegram message 'Location' t =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram message 'Location' type. diff --git a/lib/Teapot/Bot/Object/LoginUrl.pm b/lib/Teapot/Bot/Object/LoginUrl.pm index d61425b..a3ca6ce 100644 --- a/lib/Teapot/Bot/Object/LoginUrl.pm +++ b/lib/Teapot/Bot/Object/LoginUrl.pm @@ -8,7 +8,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; -$Teapot::Bot::Object::LoginUrl::VERSION = '0.024'; +$Teapot::Bot::Object::LoginUrl::VERSION = '0.025'; has 'url'; has 'forward_text'; @@ -33,7 +33,7 @@ Teapot::Bot::Object::LoginUrl - The base class for Telegram 'LoginUrl' type obje =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram 'LoginUrl' type objects. diff --git a/lib/Teapot/Bot/Object/MaskPosition.pm b/lib/Teapot/Bot/Object/MaskPosition.pm index 19ec37d..972acb4 100644 --- a/lib/Teapot/Bot/Object/MaskPosition.pm +++ b/lib/Teapot/Bot/Object/MaskPosition.pm @@ -8,7 +8,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; -$Teapot::Bot::Object::MaskPosition::VERSION = '0.024'; +$Teapot::Bot::Object::MaskPosition::VERSION = '0.025'; has 'point'; has 'x_shift'; @@ -33,7 +33,7 @@ Teapot::Bot::Object::MaskPosition - The base class for Telegram 'MaskPosition' t =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram 'MaskPosition' type objects. diff --git a/lib/Teapot/Bot/Object/Message.pm b/lib/Teapot/Bot/Object/Message.pm index 28dc6ac..839560f 100644 --- a/lib/Teapot/Bot/Object/Message.pm +++ b/lib/Teapot/Bot/Object/Message.pm @@ -40,7 +40,7 @@ use Teapot::Bot::Object::VideoChatStarted (); use Teapot::Bot::Object::VideoChatEnded (); use Teapot::Bot::Object::VideoChatParticipantsInvited (); -$Teapot::Bot::Object::Message::VERSION = '0.024'; +$Teapot::Bot::Object::Message::VERSION = '0.025'; # basic message stuff has 'message_id'; @@ -163,54 +163,76 @@ sub arrays { return qw/photo entities caption_entities new_chat_members new_chat_photo/; } - sub reply { my $self = shift; my $text = shift; - my $chatid = $self->chat->id; - my $message_thread_id = eval {$self->message_thread_id}; + my $ret = ''; - if (Teapot::Bot::Object::ChatPermissions->canTalk($self, $chatid)) { - if (defined $message_thread_id && $message_thread_id ne '') { - return $self->_brain->sendMessage({chat_id => $chatid, message_thread_id => $message_thread_id, text => $text}); - } else { - return $self->_brain->sendMessage({chat_id => $chatid, text => $text}); + my $send_args->{chat_id} = $self->chat->id; + my $message_thread_id = eval {$self->message_thread_id}; + + my $can_talk = $self->_brain->can_talk($send_args); + + if ($can_talk->{error}) { + $ret = $can_talk; + } else { + if ($can_talk->{can_talk}) { + $send_args->{text} = $text; + + if (defined $message_thread_id && $message_thread_id ne '') { + $send_args->{$message_thread_id} = $message_thread_id; + } + + $ret = $self->_brain->sendMessage($send_args); } } - return {'error' => 1}; + return $ret; } sub replyMd { my $self = shift; my $text = shift; - my $chatid = $self->chat->id; - my $message_thread_id = eval {$self->message_thread_id}; + my $ret = ''; - if (Teapot::Bot::Object::ChatPermissions->canTalk ($self, $chatid)) { - my $send_args; - $send_args->{text} = $text; - $send_args->{parse_mode} = 'Markdown'; - $send_args->{chat_id} = $chatid; - $send_args->{message_thread_id} = $message_thread_id if (defined $message_thread_id); - return $self->_brain->sendMessage($send_args); + my $send_args->{chat_id} = $self->chat->id; + my $message_thread_id = eval {$self->message_thread_id}; + + my $can_talk = $self->_brain->can_talk($send_args); + + if ($can_talk->{error}) { + $ret = $can_talk; + } else { + if ($can_talk->{can_talk}) { + $send_args->{text} = $text; + $send_args->{parse_mode} = 'Markdown'; + $send_args->{message_thread_id} = $message_thread_id if (defined $message_thread_id); + + $ret = $self->_brain->sendMessage($send_args); + } } - return {'error' => 1}; + return $ret; } sub typing { my $self = shift; - my $chatid = $self->chat->id; + my $ret = ''; + my $send_args->{chat_id} = $self->chat->id; + my $can_talk = $self->_brain->can_talk($send_args); - if (Teapot::Bot::Object::ChatPermissions->canTalk ($self, $chatid)) { - return $self->_brain->sendChatAction({chat_id => $chatid}); + if ($can_talk->{error}) { + $ret = $can_talk; + } else { + if ($can_talk->{can_talk}) { + $ret = $self->_brain->sendChatAction($send_args); + } } - return {'error' => 1}; + return $ret; } 1; @@ -227,7 +249,7 @@ Teapot::Bot::Object::Message - The base class for the Telegram type "Message" =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for the Telegram type "Message". @@ -243,6 +265,9 @@ A convenience method to reply to a message with text. Will return the C object representing the message sent. +On error returns hash reference with error field set to 1, also set fields +param, url and debug (which is result of Mojo::UserAgent->post->result->json) + =head2 replyMd @@ -250,12 +275,15 @@ A convenience method to reply to a message with markdown formatted text. Will return the C object representing the message sent. +On error returns hash reference with error field set to 1, also set fields +param, url and debug (which is result of Mojo::UserAgent->post->result->json) =head2 typing Sends notification to chat that bot is "typing" something. -Returns nothing that should be checked. +On error returns hash reference with error field set to 1, also set fields +param, url and debug (which is result of Mojo::UserAgent->post->result->json) =head1 AUTHOR diff --git a/lib/Teapot/Bot/Object/MessageAutoDeleteTimerChanged.pm b/lib/Teapot/Bot/Object/MessageAutoDeleteTimerChanged.pm index 541cd6f..a35dfbd 100644 --- a/lib/Teapot/Bot/Object/MessageAutoDeleteTimerChanged.pm +++ b/lib/Teapot/Bot/Object/MessageAutoDeleteTimerChanged.pm @@ -8,7 +8,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; -$Teapot::Bot::Object::MessageAutoDeleteTimerChanged::VERSION = '0.024'; +$Teapot::Bot::Object::MessageAutoDeleteTimerChanged::VERSION = '0.025'; has 'message_auto_delete_time'; @@ -32,7 +32,7 @@ Teapot::Bot::Object::MessageAutoDeleteTimerChanged - The base class for Telegram =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram 'MessageAutoDeleteTimerChanged' type objects. diff --git a/lib/Teapot/Bot/Object/MessageEntity.pm b/lib/Teapot/Bot/Object/MessageEntity.pm index 264588f..4a7d9e8 100644 --- a/lib/Teapot/Bot/Object/MessageEntity.pm +++ b/lib/Teapot/Bot/Object/MessageEntity.pm @@ -9,7 +9,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; use Teapot::Bot::Object::User (); -$Teapot::Bot::Object::MessageEntity::VERSION = '0.024'; +$Teapot::Bot::Object::MessageEntity::VERSION = '0.025'; has 'type'; has 'offset'; @@ -39,7 +39,7 @@ Teapot::Bot::Object::MessageEntity - The base class for Telegram 'MessageEntity' =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram 'MessageEntity' type objects. diff --git a/lib/Teapot/Bot/Object/PassportData.pm b/lib/Teapot/Bot/Object/PassportData.pm index 89896db..3d27da2 100644 --- a/lib/Teapot/Bot/Object/PassportData.pm +++ b/lib/Teapot/Bot/Object/PassportData.pm @@ -10,7 +10,7 @@ use Mojo::Base 'Teapot::Bot::Object::Base'; use Teapot::Bot::Object::EncryptedPassportElement (); use Teapot::Bot::Object::EncryptedCredentials (); -$Teapot::Bot::Object::PassportData::VERSION = '0.024'; +$Teapot::Bot::Object::PassportData::VERSION = '0.025'; has 'data'; # Array of EncryptedPassportElement has 'credentials'; # EncryptedCredentials @@ -40,7 +40,7 @@ Teapot::Bot::Object::PassportData - The base class for Telegram 'PassportData' t =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram 'PassportData' type objects. diff --git a/lib/Teapot/Bot/Object/PhotoSize.pm b/lib/Teapot/Bot/Object/PhotoSize.pm index 7768d50..ed9f1ee 100644 --- a/lib/Teapot/Bot/Object/PhotoSize.pm +++ b/lib/Teapot/Bot/Object/PhotoSize.pm @@ -8,7 +8,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; -$Teapot::Bot::Object::PhotoSize::VERSION = '0.024'; +$Teapot::Bot::Object::PhotoSize::VERSION = '0.025'; has 'file_id'; has 'file_unique_id'; @@ -34,7 +34,7 @@ Teapot::Bot::Object::PhotoSize - The base class for Telegram message 'PhotoSize' =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram message 'PhotoSize' type. diff --git a/lib/Teapot/Bot/Object/Poll.pm b/lib/Teapot/Bot/Object/Poll.pm index 468f1a7..9e9c57e 100644 --- a/lib/Teapot/Bot/Object/Poll.pm +++ b/lib/Teapot/Bot/Object/Poll.pm @@ -9,7 +9,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; use Teapot::Bot::Object::PollOption (); -$Teapot::Bot::Object::Poll::VERSION = '0.024'; +$Teapot::Bot::Object::Poll::VERSION = '0.025'; has 'id'; has 'question'; @@ -52,7 +52,7 @@ Teapot::Bot::Object::Poll - The base class for Telegram 'Poll' type objects =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram 'Poll' type objects diff --git a/lib/Teapot/Bot/Object/PollAnswer.pm b/lib/Teapot/Bot/Object/PollAnswer.pm index 3657aec..fd2e75b 100644 --- a/lib/Teapot/Bot/Object/PollAnswer.pm +++ b/lib/Teapot/Bot/Object/PollAnswer.pm @@ -8,7 +8,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; -$Teapot::Bot::Object::PollAnswer::VERSION = '0.024'; +$Teapot::Bot::Object::PollAnswer::VERSION = '0.025'; has 'poll_id'; has 'user'; @@ -39,7 +39,7 @@ Teapot::Bot::Object::PollAnswer - The base class for Telegram 'PollAnswer' type =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram 'PollAnswer' type objects. diff --git a/lib/Teapot/Bot/Object/PollOption.pm b/lib/Teapot/Bot/Object/PollOption.pm index 0904157..5563850 100644 --- a/lib/Teapot/Bot/Object/PollOption.pm +++ b/lib/Teapot/Bot/Object/PollOption.pm @@ -8,7 +8,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; -$Teapot::Bot::Object::PollOption::VERSION = '0.024'; +$Teapot::Bot::Object::PollOption::VERSION = '0.025'; has 'text'; has 'voter_count'; @@ -31,7 +31,7 @@ Teapot::Bot::Object::PollOption - The base class for Telegram 'PollOption' type =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram 'PollOption' type objects. diff --git a/lib/Teapot/Bot/Object/ProximityAlertTriggered.pm b/lib/Teapot/Bot/Object/ProximityAlertTriggered.pm index da2800b..17cb383 100644 --- a/lib/Teapot/Bot/Object/ProximityAlertTriggered.pm +++ b/lib/Teapot/Bot/Object/ProximityAlertTriggered.pm @@ -8,7 +8,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; -$Teapot::Bot::Object::ProximityAlertTriggered::VERSION = '0.024'; +$Teapot::Bot::Object::ProximityAlertTriggered::VERSION = '0.025'; has 'traveler'; # User has 'watcher'; # User @@ -35,7 +35,7 @@ Teapot::Bot::Object::ProximityAlertTriggered - The base class for Telegram messa =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram message 'ProximityAlertTriggered' type. diff --git a/lib/Teapot/Bot/Object/Sticker.pm b/lib/Teapot/Bot/Object/Sticker.pm index 6db3581..90f7c23 100644 --- a/lib/Teapot/Bot/Object/Sticker.pm +++ b/lib/Teapot/Bot/Object/Sticker.pm @@ -10,7 +10,7 @@ use Mojo::Base 'Teapot::Bot::Object::Base'; use Teapot::Bot::Object::PhotoSize (); use Teapot::Bot::Object::MaskPosition (); -$Teapot::Bot::Object::Sticker::VERSION = '0.024'; +$Teapot::Bot::Object::Sticker::VERSION = '0.025'; has 'file_id'; has 'file_unique_id'; @@ -46,7 +46,7 @@ Teapot::Bot::Object::Sticker - The base class for Telegram message 'Sticker' typ =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram message 'Sticker' type. diff --git a/lib/Teapot/Bot/Object/SuccessfulPayment.pm b/lib/Teapot/Bot/Object/SuccessfulPayment.pm index bc82d90..34b30be 100644 --- a/lib/Teapot/Bot/Object/SuccessfulPayment.pm +++ b/lib/Teapot/Bot/Object/SuccessfulPayment.pm @@ -9,7 +9,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; # use Teapot::Bot::Object::OrderInfo; -$Teapot::Bot::Object::SuccessfulPayment::VERSION = '0.024'; +$Teapot::Bot::Object::SuccessfulPayment::VERSION = '0.025'; has 'currency'; has 'total_amount'; @@ -41,7 +41,7 @@ Teapot::Bot::Object::SuccessfulPayment - The base class for Telegram 'Successful =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram 'SuccessfulPayment' type objects. diff --git a/lib/Teapot/Bot/Object/User.pm b/lib/Teapot/Bot/Object/User.pm index ba81684..cfb2573 100644 --- a/lib/Teapot/Bot/Object/User.pm +++ b/lib/Teapot/Bot/Object/User.pm @@ -8,7 +8,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; -$Teapot::Bot::Object::User::VERSION = '0.024'; +$Teapot::Bot::Object::User::VERSION = '0.025'; has 'id'; has 'is_bot'; @@ -41,7 +41,7 @@ Teapot::Bot::Object::User - The base class for Telegram message 'User' type =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram message 'User' type. diff --git a/lib/Teapot/Bot/Object/Venue.pm b/lib/Teapot/Bot/Object/Venue.pm index f771163..4f7b76f 100644 --- a/lib/Teapot/Bot/Object/Venue.pm +++ b/lib/Teapot/Bot/Object/Venue.pm @@ -9,7 +9,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; use Teapot::Bot::Object::Location (); -$Teapot::Bot::Object::Venue::VERSION = '0.024'; +$Teapot::Bot::Object::Venue::VERSION = '0.025'; has 'location'; #Location has 'title'; @@ -41,7 +41,7 @@ Teapot::Bot::Object::Venue - The base class for Telegram 'LoginUrl' type objects =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram 'LoginUrl' type objects. diff --git a/lib/Teapot/Bot/Object/Video.pm b/lib/Teapot/Bot/Object/Video.pm index ddafc7d..10f258e 100644 --- a/lib/Teapot/Bot/Object/Video.pm +++ b/lib/Teapot/Bot/Object/Video.pm @@ -9,7 +9,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; use Teapot::Bot::Object::PhotoSize (); -$Teapot::Bot::Object::Video::VERSION = '0.024'; +$Teapot::Bot::Object::Video::VERSION = '0.025'; has 'file_id'; has 'file_unique_id'; @@ -43,7 +43,7 @@ Teapot::Bot::Object::Video - The base class for Telegram 'Video' object =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram 'Video' object. diff --git a/lib/Teapot/Bot/Object/VideoChatEnded.pm b/lib/Teapot/Bot/Object/VideoChatEnded.pm index 12f5432..ec7ffdc 100644 --- a/lib/Teapot/Bot/Object/VideoChatEnded.pm +++ b/lib/Teapot/Bot/Object/VideoChatEnded.pm @@ -8,7 +8,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; -$Teapot::Bot::Object::VideoChatEnded::VERSION = '0.024'; +$Teapot::Bot::Object::VideoChatEnded::VERSION = '0.025'; # This object represents a service message about a Video chat started in the chat. Currently holds no information. has 'duration'; @@ -31,7 +31,7 @@ Teapot::Bot::Object::VideoChatEnded - The base class for Telegram message 'Video =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram message 'VideoChatEnded' type. diff --git a/lib/Teapot/Bot/Object/VideoChatParticipantsInvited.pm b/lib/Teapot/Bot/Object/VideoChatParticipantsInvited.pm index ee527e1..ff97857 100644 --- a/lib/Teapot/Bot/Object/VideoChatParticipantsInvited.pm +++ b/lib/Teapot/Bot/Object/VideoChatParticipantsInvited.pm @@ -9,7 +9,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; use Teapot::Bot::Object::User (); -$Teapot::Bot::Object::VideoChatParticipantsInvited::VERSION = '0.024'; +$Teapot::Bot::Object::VideoChatParticipantsInvited::VERSION = '0.025'; # This object represents a service message about a Video chat started in the chat. Currently holds no information. has 'users'; @@ -36,7 +36,7 @@ Teapot::Bot::Object::VideoChatParticipantsInvited - The base class for Telegram =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram message 'VideoChatParticipantsInvited' type. diff --git a/lib/Teapot/Bot/Object/VideoChatScheduled.pm b/lib/Teapot/Bot/Object/VideoChatScheduled.pm index b45c8bf..c94c6b9 100644 --- a/lib/Teapot/Bot/Object/VideoChatScheduled.pm +++ b/lib/Teapot/Bot/Object/VideoChatScheduled.pm @@ -8,7 +8,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; -$Teapot::Bot::Object::VideoChatScheduled::VERSION = '0.024'; +$Teapot::Bot::Object::VideoChatScheduled::VERSION = '0.025'; # This object represents a service message about a video chat started in the chat. Currently holds no information. has 'start_date'; @@ -31,7 +31,7 @@ Teapot::Bot::Object::VideoChatScheduled - The base class for Telegram message 'V =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram message 'VideoChatScheduled' type. diff --git a/lib/Teapot/Bot/Object/VideoChatStarted.pm b/lib/Teapot/Bot/Object/VideoChatStarted.pm index f16d9eb..7c8c7ba 100644 --- a/lib/Teapot/Bot/Object/VideoChatStarted.pm +++ b/lib/Teapot/Bot/Object/VideoChatStarted.pm @@ -8,7 +8,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; -$Teapot::Bot::Object::VideoChatStarted::VERSION = '0.024'; +$Teapot::Bot::Object::VideoChatStarted::VERSION = '0.025'; # This object represents a service message about a Video chat started in the chat. Currently holds no information. has 'stub'; @@ -31,7 +31,7 @@ Teapot::Bot::Object::VideoChatStarted - The base class for Telegram message 'Vid =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram message 'VideoChatStarted' type. diff --git a/lib/Teapot/Bot/Object/VideoNote.pm b/lib/Teapot/Bot/Object/VideoNote.pm index 3e0da1d..ab61284 100644 --- a/lib/Teapot/Bot/Object/VideoNote.pm +++ b/lib/Teapot/Bot/Object/VideoNote.pm @@ -9,7 +9,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; use Teapot::Bot::Object::PhotoSize (); -$Teapot::Bot::Object::VideoNote::VERSION = '0.024'; +$Teapot::Bot::Object::VideoNote::VERSION = '0.025'; has 'file_id'; has 'file_unique_id'; @@ -40,7 +40,7 @@ Teapot::Bot::Object::VideoNote - The base class for Telegram 'VideoNote' type ob =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram 'VideoNote' type object. diff --git a/lib/Teapot/Bot/Object/Voice.pm b/lib/Teapot/Bot/Object/Voice.pm index 90aac6a..9ae3a8b 100644 --- a/lib/Teapot/Bot/Object/Voice.pm +++ b/lib/Teapot/Bot/Object/Voice.pm @@ -8,7 +8,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; -$Teapot::Bot::Object::Voice::VERSION = '0.024'; +$Teapot::Bot::Object::Voice::VERSION = '0.025'; has 'file_id'; has 'file_unique_id'; @@ -34,7 +34,7 @@ Teapot::Bot::Object::Voice - The base class for Telegram 'Voice' type objects =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram 'Voice' type objects. diff --git a/lib/Teapot/Bot/Object/WebAppData.pm b/lib/Teapot/Bot/Object/WebAppData.pm index 7eb3e42..2fd37ab 100644 --- a/lib/Teapot/Bot/Object/WebAppData.pm +++ b/lib/Teapot/Bot/Object/WebAppData.pm @@ -8,7 +8,7 @@ use utf8; use Mojo::Base 'Teapot::Bot::Object::Base'; -$Teapot::Bot::Object::WebAppData::VERSION = '0.024'; +$Teapot::Bot::Object::WebAppData::VERSION = '0.025'; has 'data'; has 'button_text'; @@ -31,7 +31,7 @@ Teapot::Bot::Object::WebAppData - The base class for Telegram 'WebAppData' type =head1 VERSION -version 0.024 +version 0.025 =head1 DESCRIPTION The base class for Telegram 'WebAppData' type objects.