2/5 Lift up error to caller in Teapot lib, introduce can_talk() in Brain.pm

This commit is contained in:
eleksir
2023-01-02 19:06:02 +03:00
parent 3668620bd8
commit 1f3675de8f
48 changed files with 744 additions and 448 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -9,7 +9,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; use Mojo::Base 'Teapot::Bot::Object::Base';
use Teapot::Bot::Object::PhotoSize (); use Teapot::Bot::Object::PhotoSize ();
$Teapot::Bot::Object::Animation::VERSION = '0.024'; $Teapot::Bot::Object::Animation::VERSION = '0.025';
has 'file_id'; has 'file_id';
has 'file_unique_id'; has 'file_unique_id';
@@ -43,7 +43,7 @@ Teapot::Bot::Object::Animation - The base class for Telegram message 'Animation'
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram message 'Animation' type. The base class for Telegram message 'Animation' type.

View File

@@ -8,7 +8,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; 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_id';
has 'file_unique_id'; has 'file_unique_id';
@@ -41,7 +41,7 @@ Teapot::Bot::Object::Audio - The base class for Telegram 'Audio' type objects
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram 'Audio' type objects. The base class for Telegram 'Audio' type objects.

View File

@@ -13,7 +13,7 @@ use List::Util qw/any/;
use Mojo::Base -base; 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 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 =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION

View File

@@ -7,7 +7,7 @@ use 5.018; ## no critic (ProhibitImplicitImport)
use utf8; use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; 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 # https://core.telegram.org/bots/api#callbackgame
# "A placeholder, currently holds no information. Use BotFather to set up your game" # "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 =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram message 'CallbackGame' type. The base class for Telegram message 'CallbackGame' type.

View File

@@ -12,7 +12,7 @@ use Teapot::Bot::Object::Message ();
use Teapot::Bot::Object::ChatPermissions (); use Teapot::Bot::Object::ChatPermissions ();
use Teapot::Bot::Object::ChatLocation (); use Teapot::Bot::Object::ChatLocation ();
$Teapot::Bot::Object::Chat::VERSION = '0.024'; $Teapot::Bot::Object::Chat::VERSION = '0.025';
has 'id'; has 'id';
has 'type'; has 'type';
@@ -86,7 +86,7 @@ Teapot::Bot::Object::Chat - The base class for Telegram 'Chat' type objects
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram 'Chat' type objects. The base class for Telegram 'Chat' type objects.

View File

@@ -9,7 +9,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; use Mojo::Base 'Teapot::Bot::Object::Base';
use Teapot::Bot::Object::User (); use Teapot::Bot::Object::User ();
$Teapot::Bot::Object::ChatInviteLink::VERSION = '0.024'; $Teapot::Bot::Object::ChatInviteLink::VERSION = '0.025';
has 'invite_link'; has 'invite_link';
has 'creator'; has 'creator';
@@ -44,7 +44,7 @@ Teapot::Bot::Object::ChatInviteLink - The base class for Telegram message 'ChatI
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram message 'ChatInviteLink' type. The base class for Telegram message 'ChatInviteLink' type.

View File

@@ -8,7 +8,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; use Mojo::Base 'Teapot::Bot::Object::Base';
$Teapot::Bot::Object::ChatLocation::VERSION = '0.024'; $Teapot::Bot::Object::ChatLocation::VERSION = '0.025';
has 'location'; has 'location';
has 'address'; has 'address';
@@ -34,7 +34,7 @@ Teapot::Bot::Object::ChatLocation - The base class for Telegram message 'ChatLoc
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram message 'ChatLocation' type. The base class for Telegram message 'ChatLocation' type.

View File

@@ -12,7 +12,7 @@ use Mojo::Base 'Teapot::Bot::Object::Base';
use Teapot::Bot::Object::User (); use Teapot::Bot::Object::User ();
$Teapot::Bot::Object::ChatMember::VERSION = '0.024'; $Teapot::Bot::Object::ChatMember::VERSION = '0.025';
# ChatMemberOwner # ChatMemberOwner
has 'user'; has 'user';
@@ -147,7 +147,7 @@ Teapot::Bot::Object::ChatMember - The base class for Telegram 'ChatMember' type
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram 'ChatMember' type objects. The base class for Telegram 'ChatMember' type objects.

View File

@@ -13,7 +13,7 @@ use Teapot::Bot::Object::ChatMember ();
use Teapot::Bot::Object::ChatInviteLink (); use Teapot::Bot::Object::ChatInviteLink ();
use Teapot::Bot::Object::Voice (); use Teapot::Bot::Object::Voice ();
$Teapot::Bot::Object::ChatMemberUpdated::VERSION = '0.024'; $Teapot::Bot::Object::ChatMemberUpdated::VERSION = '0.025';
has 'chat'; has 'chat';
has 'from'; has 'from';
@@ -50,7 +50,7 @@ Teapot::Bot::Object::ChatMemberUpdated - The base class for Telegram 'ChatMember
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram 'ChatMemberUpdated' type objects. The base class for Telegram 'ChatMemberUpdated' type objects.

View File

@@ -10,7 +10,7 @@ use Carp qw(carp);
use Mojo::Base 'Teapot::Bot::Object::Base'; use Mojo::Base 'Teapot::Bot::Object::Base';
use Teapot::Bot::Brain (); use Teapot::Bot::Brain ();
$Teapot::Bot::Object::ChatPermissions::VERSION = '0.024'; $Teapot::Bot::Object::ChatPermissions::VERSION = '0.025';
# all fields are optional # 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 # 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 { 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 $chatid = shift;
my $args->{chat_id} = $chatid; $args->{chat_id} = $chatid;
my $can_talk = 0; 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) { if ($chatid < 0) {
# group chat # group chat
@@ -50,16 +77,23 @@ sub canTalk {
# on api error, keep silence # on api error, keep silence
if ($chatobj == 0 || $chatobj->{error}) { if ($chatobj == 0 || $chatobj->{error}) {
carp "Unable to get chat info for $chatid from telegram API"; my $emesg = "Unable to get chat info for $chatid from telegram API";
return $can_talk; $ret->{message} = $emesg;
$ret->{error} = 1;
$ret->{can_talk} = 0;
return $ret;
} }
my $myObj = Teapot::Bot::Brain->getMe ($self); my $myObj = Teapot::Bot::Brain->getMe ($self);
# on api error, keep silence # on api error, keep silence
if ($myObj == 0 || $myObj->{error}) { if ($myObj == 0 || $myObj->{error}) {
carp "Unable to get chat info for $chatid from telegram API"; my $emesg = "Unable to get chat info for $chatid from telegram API";
return $can_talk; $ret->{message} = $emesg;
$ret->{error} = 1;
$ret->{can_talk} = 0;
return $ret;
} }
my $myid = $myObj->id; my $myid = $myObj->id;
@@ -68,8 +102,12 @@ sub canTalk {
# on api error, keep silence # on api error, keep silence
if ($me == 0 || $me->{error}) { if ($me == 0 || $me->{error}) {
carp 'Unable to get chat info for bot itself from telegram API'; my $emesg = 'Unable to get chat info for bot itself from telegram API';
return $can_talk; $ret->{message} = $emesg;
$ret->{error} = 1;
$ret->{can_talk} = 0;
return $ret;
} }
if ($me->{'status'} eq 'administrator') { if ($me->{'status'} eq 'administrator') {
@@ -83,9 +121,13 @@ sub canTalk {
$can_talk = 1; $can_talk = 1;
} }
return $can_talk; $ret->{error} = 0;
$ret->{can_talk} = $can_talk;
return $ret;
} }
1; 1;
__END__ __END__
@@ -100,7 +142,7 @@ Teapot::Bot::Object::ChatPermissions - The base class for Telegram 'ChatPermissi
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram 'ChatPermissions' type objects. The base class for Telegram 'ChatPermissions' type objects.
@@ -114,7 +156,9 @@ attributes available for C<Teapot::Bot::Object::ChatPermissions> objects.
A convenience method to check if bot can talk in given conversation. 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 =head1 AUTHOR

View File

@@ -8,7 +8,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; 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_id';
has 'small_file_unique_id'; has 'small_file_unique_id';
@@ -35,7 +35,7 @@ Teapot::Bot::Object::ChatPhoto - The base class for Telegram 'ChatPhoto' type ob
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram 'ChatPhoto' type objects. The base class for Telegram 'ChatPhoto' type objects.

View File

@@ -8,7 +8,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; 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 'phone_number';
has 'first_name'; has 'first_name';
@@ -36,7 +36,7 @@ Teapot::Bot::Object::Contact - The base class for Telegram 'Contact' objects
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram 'Contact' objects. The base class for Telegram 'Contact' objects.

View File

@@ -8,7 +8,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; use Mojo::Base 'Teapot::Bot::Object::Base';
$Teapot::Bot::Object::Dice::VERSION = '0.024'; $Teapot::Bot::Object::Dice::VERSION = '0.025';
has 'emoji'; has 'emoji';
has 'value'; has 'value';
@@ -31,7 +31,7 @@ Teapot::Bot::Object::Dice - The base class for Telegram message 'Dice' type
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram message 'Dice' type. The base class for Telegram message 'Dice' type.

View File

@@ -9,7 +9,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; use Mojo::Base 'Teapot::Bot::Object::Base';
use Teapot::Bot::Object::PhotoSize (); use Teapot::Bot::Object::PhotoSize ();
$Teapot::Bot::Object::Document::VERSION = '0.024'; $Teapot::Bot::Object::Document::VERSION = '0.025';
has 'file_id'; has 'file_id';
has 'file_unique_id'; has 'file_unique_id';
@@ -39,7 +39,7 @@ Teapot::Bot::Object::Document - The base class for Telegram 'Document' objects
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram 'Document' objects. The base class for Telegram 'Document' objects.

View File

@@ -8,7 +8,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; use Mojo::Base 'Teapot::Bot::Object::Base';
$Teapot::Bot::Object::EncryptedCredentials::VERSION = '0.024'; $Teapot::Bot::Object::EncryptedCredentials::VERSION = '0.025';
has 'data'; has 'data';
has 'hash'; has 'hash';
@@ -32,7 +32,7 @@ Teapot::Bot::Object::EncryptedCredentials - The base class for Telegram 'Encrypt
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram 'EncryptedCredentials' type objects. The base class for Telegram 'EncryptedCredentials' type objects.

View File

@@ -8,7 +8,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; 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 # XXX Implement rest of this
# https://core.telegram.org/bots/api#encryptedpassportelement # https://core.telegram.org/bots/api#encryptedpassportelement
@@ -38,7 +38,7 @@ Teapot::Bot::Object::EncryptedPassportElement - The base class for Telegram 'Enc
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram 'EncryptedPassportElement' type objects. The base class for Telegram 'EncryptedPassportElement' type objects.

View File

@@ -8,7 +8,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; use Mojo::Base 'Teapot::Bot::Object::Base';
$Teapot::Bot::Object::ForumTopicClosed::VERSION = '0.024'; $Teapot::Bot::Object::ForumTopicClosed::VERSION = '0.025';
sub fields { sub fields {
@@ -29,7 +29,7 @@ Teapot::Bot::Object::ForumTopicClosed - The base class for Telegram message 'Fo
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram message 'ForumTopicClosed' type. The base class for Telegram message 'ForumTopicClosed' type.

View File

@@ -8,7 +8,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; use Mojo::Base 'Teapot::Bot::Object::Base';
$Teapot::Bot::Object::ForumTopicCreated::VERSION = '0.024'; $Teapot::Bot::Object::ForumTopicCreated::VERSION = '0.025';
has 'name'; has 'name';
has 'icon_color'; has 'icon_color';
@@ -32,7 +32,7 @@ Teapot::Bot::Object::ForumTopicCreated - The base class for Telegram message 'F
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram message 'ForumTopicCreated' type. The base class for Telegram message 'ForumTopicCreated' type.

View File

@@ -8,7 +8,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; use Mojo::Base 'Teapot::Bot::Object::Base';
$Teapot::Bot::Object::ForumTopicReopened::VERSION = '0.024'; $Teapot::Bot::Object::ForumTopicReopened::VERSION = '0.025';
sub fields { sub fields {
@@ -29,7 +29,7 @@ Teapot::Bot::Object::ForumTopicReopened - The base class for Telegram message '
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram message 'ForumTopicReopened' type. The base class for Telegram message 'ForumTopicReopened' type.

View File

@@ -11,7 +11,7 @@ use Teapot::Bot::Object::PhotoSize ();
use Teapot::Bot::Object::Animation (); use Teapot::Bot::Object::Animation ();
use Teapot::Bot::Object::MessageEntity (); use Teapot::Bot::Object::MessageEntity ();
$Teapot::Bot::Object::Game::VERSION = '0.024'; $Teapot::Bot::Object::Game::VERSION = '0.025';
has 'title'; has 'title';
has 'description'; has 'description';
@@ -45,7 +45,7 @@ Teapot::Bot::Object::Game - The base class for Telegram message 'Game' type
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram message 'Game' type. The base class for Telegram message 'Game' type.

View File

@@ -10,7 +10,7 @@ use Mojo::Base 'Teapot::Bot::Object::Base';
use Teapot::Bot::Object::LoginUrl (); use Teapot::Bot::Object::LoginUrl ();
use Teapot::Bot::Object::CallbackGame (); use Teapot::Bot::Object::CallbackGame ();
$Teapot::Bot::Object::InlineKeyboardButton::VERSION = '0.024'; $Teapot::Bot::Object::InlineKeyboardButton::VERSION = '0.025';
has 'text'; has 'text';
has 'url'; has 'url';
@@ -43,7 +43,7 @@ Teapot::Bot::Object::InlineKeyboardButton - The base class for Telegram 'InlineK
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram 'InlineKeyboardButton' type objects. The base class for Telegram 'InlineKeyboardButton' type objects.

View File

@@ -9,7 +9,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; use Mojo::Base 'Teapot::Bot::Object::Base';
use Teapot::Bot::Object::InlineKeyboardButton (); use Teapot::Bot::Object::InlineKeyboardButton ();
$Teapot::Bot::Object::InlineKeyboardMarkup::VERSION = '0.024'; $Teapot::Bot::Object::InlineKeyboardMarkup::VERSION = '0.025';
has 'inline_keyboard'; has 'inline_keyboard';
@@ -35,7 +35,7 @@ Teapot::Bot::Object::InlineKeyboardMarkup - The base class for Telegram 'InlineK
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram 'InlineKeyboardMarkup' type objects. The base class for Telegram 'InlineKeyboardMarkup' type objects.

View File

@@ -8,7 +8,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; use Mojo::Base 'Teapot::Bot::Object::Base';
$Teapot::Bot::Object::Invoice::VERSION = '0.024'; $Teapot::Bot::Object::Invoice::VERSION = '0.025';
has 'title'; has 'title';
has 'description'; has 'description';
@@ -34,7 +34,7 @@ Teapot::Bot::Object::Invoice - The base class for Telegram 'Invoice' type object
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram 'Invoice' type objects. The base class for Telegram 'Invoice' type objects.

View File

@@ -8,7 +8,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; use Mojo::Base 'Teapot::Bot::Object::Base';
$Teapot::Bot::Object::Location::VERSION = '0.024'; $Teapot::Bot::Object::Location::VERSION = '0.025';
has 'longitude'; has 'longitude';
has 'latitude'; has 'latitude';
@@ -35,7 +35,7 @@ Teapot::Bot::Object::Location - The base class for Telegram message 'Location' t
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram message 'Location' type. The base class for Telegram message 'Location' type.

View File

@@ -8,7 +8,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; use Mojo::Base 'Teapot::Bot::Object::Base';
$Teapot::Bot::Object::LoginUrl::VERSION = '0.024'; $Teapot::Bot::Object::LoginUrl::VERSION = '0.025';
has 'url'; has 'url';
has 'forward_text'; has 'forward_text';
@@ -33,7 +33,7 @@ Teapot::Bot::Object::LoginUrl - The base class for Telegram 'LoginUrl' type obje
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram 'LoginUrl' type objects. The base class for Telegram 'LoginUrl' type objects.

View File

@@ -8,7 +8,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; use Mojo::Base 'Teapot::Bot::Object::Base';
$Teapot::Bot::Object::MaskPosition::VERSION = '0.024'; $Teapot::Bot::Object::MaskPosition::VERSION = '0.025';
has 'point'; has 'point';
has 'x_shift'; has 'x_shift';
@@ -33,7 +33,7 @@ Teapot::Bot::Object::MaskPosition - The base class for Telegram 'MaskPosition' t
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram 'MaskPosition' type objects. The base class for Telegram 'MaskPosition' type objects.

View File

@@ -40,7 +40,7 @@ use Teapot::Bot::Object::VideoChatStarted ();
use Teapot::Bot::Object::VideoChatEnded (); use Teapot::Bot::Object::VideoChatEnded ();
use Teapot::Bot::Object::VideoChatParticipantsInvited (); use Teapot::Bot::Object::VideoChatParticipantsInvited ();
$Teapot::Bot::Object::Message::VERSION = '0.024'; $Teapot::Bot::Object::Message::VERSION = '0.025';
# basic message stuff # basic message stuff
has 'message_id'; has 'message_id';
@@ -163,54 +163,76 @@ sub arrays {
return qw/photo entities caption_entities new_chat_members new_chat_photo/; return qw/photo entities caption_entities new_chat_members new_chat_photo/;
} }
sub reply { sub reply {
my $self = shift; my $self = shift;
my $text = shift; my $text = shift;
my $chatid = $self->chat->id; my $ret = '';
my $send_args->{chat_id} = $self->chat->id;
my $message_thread_id = eval {$self->message_thread_id}; my $message_thread_id = eval {$self->message_thread_id};
if (Teapot::Bot::Object::ChatPermissions->canTalk($self, $chatid)) { my $can_talk = $self->_brain->can_talk($send_args);
if (defined $message_thread_id && $message_thread_id ne '') {
return $self->_brain->sendMessage({chat_id => $chatid, message_thread_id => $message_thread_id, text => $text}); if ($can_talk->{error}) {
$ret = $can_talk;
} else { } else {
return $self->_brain->sendMessage({chat_id => $chatid, text => $text}); 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 { sub replyMd {
my $self = shift; my $self = shift;
my $text = shift; my $text = shift;
my $chatid = $self->chat->id; my $ret = '';
my $send_args->{chat_id} = $self->chat->id;
my $message_thread_id = eval {$self->message_thread_id}; my $message_thread_id = eval {$self->message_thread_id};
if (Teapot::Bot::Object::ChatPermissions->canTalk ($self, $chatid)) { my $can_talk = $self->_brain->can_talk($send_args);
my $send_args;
if ($can_talk->{error}) {
$ret = $can_talk;
} else {
if ($can_talk->{can_talk}) {
$send_args->{text} = $text; $send_args->{text} = $text;
$send_args->{parse_mode} = 'Markdown'; $send_args->{parse_mode} = 'Markdown';
$send_args->{chat_id} = $chatid;
$send_args->{message_thread_id} = $message_thread_id if (defined $message_thread_id); $send_args->{message_thread_id} = $message_thread_id if (defined $message_thread_id);
return $self->_brain->sendMessage($send_args);
$ret = $self->_brain->sendMessage($send_args);
}
} }
return {'error' => 1}; return $ret;
} }
sub typing { sub typing {
my $self = shift; 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)) { if ($can_talk->{error}) {
return $self->_brain->sendChatAction({chat_id => $chatid}); $ret = $can_talk;
} else {
if ($can_talk->{can_talk}) {
$ret = $self->_brain->sendChatAction($send_args);
}
} }
return {'error' => 1}; return $ret;
} }
1; 1;
@@ -227,7 +249,7 @@ Teapot::Bot::Object::Message - The base class for the Telegram type "Message"
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for the Telegram type "Message". 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<Teapot::Bot::Object::Message> object representing the message Will return the C<Teapot::Bot::Object::Message> object representing the message
sent. 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 =head2 replyMd
@@ -250,12 +275,15 @@ A convenience method to reply to a message with markdown formatted text.
Will return the C<Teapot::Bot::Object::Message> object representing the message Will return the C<Teapot::Bot::Object::Message> object representing the message
sent. 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 =head2 typing
Sends notification to chat that bot is "typing" something. 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 =head1 AUTHOR

View File

@@ -8,7 +8,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; 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'; has 'message_auto_delete_time';
@@ -32,7 +32,7 @@ Teapot::Bot::Object::MessageAutoDeleteTimerChanged - The base class for Telegram
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram 'MessageAutoDeleteTimerChanged' type objects. The base class for Telegram 'MessageAutoDeleteTimerChanged' type objects.

View File

@@ -9,7 +9,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; use Mojo::Base 'Teapot::Bot::Object::Base';
use Teapot::Bot::Object::User (); use Teapot::Bot::Object::User ();
$Teapot::Bot::Object::MessageEntity::VERSION = '0.024'; $Teapot::Bot::Object::MessageEntity::VERSION = '0.025';
has 'type'; has 'type';
has 'offset'; has 'offset';
@@ -39,7 +39,7 @@ Teapot::Bot::Object::MessageEntity - The base class for Telegram 'MessageEntity'
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram 'MessageEntity' type objects. The base class for Telegram 'MessageEntity' type objects.

View File

@@ -10,7 +10,7 @@ use Mojo::Base 'Teapot::Bot::Object::Base';
use Teapot::Bot::Object::EncryptedPassportElement (); use Teapot::Bot::Object::EncryptedPassportElement ();
use Teapot::Bot::Object::EncryptedCredentials (); 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 'data'; # Array of EncryptedPassportElement
has 'credentials'; # EncryptedCredentials has 'credentials'; # EncryptedCredentials
@@ -40,7 +40,7 @@ Teapot::Bot::Object::PassportData - The base class for Telegram 'PassportData' t
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram 'PassportData' type objects. The base class for Telegram 'PassportData' type objects.

View File

@@ -8,7 +8,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; 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_id';
has 'file_unique_id'; has 'file_unique_id';
@@ -34,7 +34,7 @@ Teapot::Bot::Object::PhotoSize - The base class for Telegram message 'PhotoSize'
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram message 'PhotoSize' type. The base class for Telegram message 'PhotoSize' type.

View File

@@ -9,7 +9,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; use Mojo::Base 'Teapot::Bot::Object::Base';
use Teapot::Bot::Object::PollOption (); use Teapot::Bot::Object::PollOption ();
$Teapot::Bot::Object::Poll::VERSION = '0.024'; $Teapot::Bot::Object::Poll::VERSION = '0.025';
has 'id'; has 'id';
has 'question'; has 'question';
@@ -52,7 +52,7 @@ Teapot::Bot::Object::Poll - The base class for Telegram 'Poll' type objects
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram 'Poll' type objects The base class for Telegram 'Poll' type objects

View File

@@ -8,7 +8,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; 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 'poll_id';
has 'user'; has 'user';
@@ -39,7 +39,7 @@ Teapot::Bot::Object::PollAnswer - The base class for Telegram 'PollAnswer' type
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram 'PollAnswer' type objects. The base class for Telegram 'PollAnswer' type objects.

View File

@@ -8,7 +8,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; use Mojo::Base 'Teapot::Bot::Object::Base';
$Teapot::Bot::Object::PollOption::VERSION = '0.024'; $Teapot::Bot::Object::PollOption::VERSION = '0.025';
has 'text'; has 'text';
has 'voter_count'; has 'voter_count';
@@ -31,7 +31,7 @@ Teapot::Bot::Object::PollOption - The base class for Telegram 'PollOption' type
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram 'PollOption' type objects. The base class for Telegram 'PollOption' type objects.

View File

@@ -8,7 +8,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; 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 'traveler'; # User
has 'watcher'; # User has 'watcher'; # User
@@ -35,7 +35,7 @@ Teapot::Bot::Object::ProximityAlertTriggered - The base class for Telegram messa
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram message 'ProximityAlertTriggered' type. The base class for Telegram message 'ProximityAlertTriggered' type.

View File

@@ -10,7 +10,7 @@ use Mojo::Base 'Teapot::Bot::Object::Base';
use Teapot::Bot::Object::PhotoSize (); use Teapot::Bot::Object::PhotoSize ();
use Teapot::Bot::Object::MaskPosition (); use Teapot::Bot::Object::MaskPosition ();
$Teapot::Bot::Object::Sticker::VERSION = '0.024'; $Teapot::Bot::Object::Sticker::VERSION = '0.025';
has 'file_id'; has 'file_id';
has 'file_unique_id'; has 'file_unique_id';
@@ -46,7 +46,7 @@ Teapot::Bot::Object::Sticker - The base class for Telegram message 'Sticker' typ
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram message 'Sticker' type. The base class for Telegram message 'Sticker' type.

View File

@@ -9,7 +9,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; use Mojo::Base 'Teapot::Bot::Object::Base';
# use Teapot::Bot::Object::OrderInfo; # use Teapot::Bot::Object::OrderInfo;
$Teapot::Bot::Object::SuccessfulPayment::VERSION = '0.024'; $Teapot::Bot::Object::SuccessfulPayment::VERSION = '0.025';
has 'currency'; has 'currency';
has 'total_amount'; has 'total_amount';
@@ -41,7 +41,7 @@ Teapot::Bot::Object::SuccessfulPayment - The base class for Telegram 'Successful
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram 'SuccessfulPayment' type objects. The base class for Telegram 'SuccessfulPayment' type objects.

View File

@@ -8,7 +8,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; use Mojo::Base 'Teapot::Bot::Object::Base';
$Teapot::Bot::Object::User::VERSION = '0.024'; $Teapot::Bot::Object::User::VERSION = '0.025';
has 'id'; has 'id';
has 'is_bot'; has 'is_bot';
@@ -41,7 +41,7 @@ Teapot::Bot::Object::User - The base class for Telegram message 'User' type
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram message 'User' type. The base class for Telegram message 'User' type.

View File

@@ -9,7 +9,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; use Mojo::Base 'Teapot::Bot::Object::Base';
use Teapot::Bot::Object::Location (); use Teapot::Bot::Object::Location ();
$Teapot::Bot::Object::Venue::VERSION = '0.024'; $Teapot::Bot::Object::Venue::VERSION = '0.025';
has 'location'; #Location has 'location'; #Location
has 'title'; has 'title';
@@ -41,7 +41,7 @@ Teapot::Bot::Object::Venue - The base class for Telegram 'LoginUrl' type objects
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram 'LoginUrl' type objects. The base class for Telegram 'LoginUrl' type objects.

View File

@@ -9,7 +9,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; use Mojo::Base 'Teapot::Bot::Object::Base';
use Teapot::Bot::Object::PhotoSize (); use Teapot::Bot::Object::PhotoSize ();
$Teapot::Bot::Object::Video::VERSION = '0.024'; $Teapot::Bot::Object::Video::VERSION = '0.025';
has 'file_id'; has 'file_id';
has 'file_unique_id'; has 'file_unique_id';
@@ -43,7 +43,7 @@ Teapot::Bot::Object::Video - The base class for Telegram 'Video' object
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram 'Video' object. The base class for Telegram 'Video' object.

View File

@@ -8,7 +8,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; 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. # This object represents a service message about a Video chat started in the chat. Currently holds no information.
has 'duration'; has 'duration';
@@ -31,7 +31,7 @@ Teapot::Bot::Object::VideoChatEnded - The base class for Telegram message 'Video
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram message 'VideoChatEnded' type. The base class for Telegram message 'VideoChatEnded' type.

View File

@@ -9,7 +9,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; use Mojo::Base 'Teapot::Bot::Object::Base';
use Teapot::Bot::Object::User (); 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. # This object represents a service message about a Video chat started in the chat. Currently holds no information.
has 'users'; has 'users';
@@ -36,7 +36,7 @@ Teapot::Bot::Object::VideoChatParticipantsInvited - The base class for Telegram
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram message 'VideoChatParticipantsInvited' type. The base class for Telegram message 'VideoChatParticipantsInvited' type.

View File

@@ -8,7 +8,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; 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. # This object represents a service message about a video chat started in the chat. Currently holds no information.
has 'start_date'; has 'start_date';
@@ -31,7 +31,7 @@ Teapot::Bot::Object::VideoChatScheduled - The base class for Telegram message 'V
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram message 'VideoChatScheduled' type. The base class for Telegram message 'VideoChatScheduled' type.

View File

@@ -8,7 +8,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; 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. # This object represents a service message about a Video chat started in the chat. Currently holds no information.
has 'stub'; has 'stub';
@@ -31,7 +31,7 @@ Teapot::Bot::Object::VideoChatStarted - The base class for Telegram message 'Vid
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram message 'VideoChatStarted' type. The base class for Telegram message 'VideoChatStarted' type.

View File

@@ -9,7 +9,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; use Mojo::Base 'Teapot::Bot::Object::Base';
use Teapot::Bot::Object::PhotoSize (); use Teapot::Bot::Object::PhotoSize ();
$Teapot::Bot::Object::VideoNote::VERSION = '0.024'; $Teapot::Bot::Object::VideoNote::VERSION = '0.025';
has 'file_id'; has 'file_id';
has 'file_unique_id'; has 'file_unique_id';
@@ -40,7 +40,7 @@ Teapot::Bot::Object::VideoNote - The base class for Telegram 'VideoNote' type ob
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram 'VideoNote' type object. The base class for Telegram 'VideoNote' type object.

View File

@@ -8,7 +8,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; 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_id';
has 'file_unique_id'; has 'file_unique_id';
@@ -34,7 +34,7 @@ Teapot::Bot::Object::Voice - The base class for Telegram 'Voice' type objects
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram 'Voice' type objects. The base class for Telegram 'Voice' type objects.

View File

@@ -8,7 +8,7 @@ use utf8;
use Mojo::Base 'Teapot::Bot::Object::Base'; use Mojo::Base 'Teapot::Bot::Object::Base';
$Teapot::Bot::Object::WebAppData::VERSION = '0.024'; $Teapot::Bot::Object::WebAppData::VERSION = '0.025';
has 'data'; has 'data';
has 'button_text'; has 'button_text';
@@ -31,7 +31,7 @@ Teapot::Bot::Object::WebAppData - The base class for Telegram 'WebAppData' type
=head1 VERSION =head1 VERSION
version 0.024 version 0.025
=head1 DESCRIPTION =head1 DESCRIPTION
The base class for Telegram 'WebAppData' type objects. The base class for Telegram 'WebAppData' type objects.