1

Vendor Telegram::Bot

This commit is contained in:
eleksir
2020-10-28 18:06:21 +03:00
parent c9b46cc6f0
commit c3818e5dee
31 changed files with 2312 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
package Telegram::Bot::Object::Animation;
$Telegram::Bot::Object::Animation::VERSION = '0.021';
# ABSTRACT: The base class for Telegram message 'Animation' type.
use Mojo::Base 'Telegram::Bot::Object::Base';
use Telegram::Bot::Object::PhotoSize;
use Carp qw/croak/;
has 'file_id';
has 'width';
has 'height';
has 'duration';
has 'thumb'; #PhotoSize
has 'file_name';
has 'mime_type';
has 'file_size';
sub fields {
return { scalar => [qw/file_id width height duration file_name mime_type file_size/],
'Telegram::Bot::Object::PhotoSize' => [qw/thumb/],
};
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Telegram::Bot::Object::Animation - The base class for Telegram message 'Animation' type.
=head1 VERSION
version 0.021
=head1 DESCRIPTION
See L<https://core.telegram.org/bots/api#animation> for details of the
attributes available for L<Telegram::Bot::Object::Animation> objects.
=head1 AUTHOR
Justin Hawkins <justin@eatmorecode.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Justin Hawkins.
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

View File

@@ -0,0 +1,54 @@
package Telegram::Bot::Object::Audio;
$Telegram::Bot::Object::Audio::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'Audio' type objects
use Mojo::Base 'Telegram::Bot::Object::Base';
has 'file_id';
has 'duration';
has 'performer';
has 'title';
has 'mime_type';
has 'file_size';
has 'thumb'; #PhotoSize
sub fields {
return { scalar => [qw/file_id duration performer title mime_type file_size/],
'Telegram::Bot::Object::PhotoSize' => [qw/thumb/],
};
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Telegram::Bot::Object::Audio - The base class for Telegram 'Audio' type objects
=head1 VERSION
version 0.021
=head1 DESCRIPTION
See L<https://core.telegram.org/bots/api#audio> for details of the
attributes available for L<Telegram::Bot::Object::Audio> objects.
=head1 AUTHOR
Justin Hawkins <justin@eatmorecode.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Justin Hawkins.
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

View File

@@ -0,0 +1,180 @@
package Telegram::Bot::Object::Base;
$Telegram::Bot::Object::Base::VERSION = '0.021';
# ABSTRACT: The base class for all Telegram::Bot::Object objects.
use Mojo::Base -base;
has '_brain'; # a reference to our brain
sub arrays { qw// } # override if needed
sub _field_is_array {
my $self = shift;
my $field = shift;
if (grep /^$field$/, $self->arrays) {
return 1;
}
return;
}
sub array_of_arrays { qw// } #override if needed
sub _field_is_array_of_arrays {
my $self = shift;
my $field = shift;
if (grep /^$field$/, $self->array_of_arrays) {
return 1;
}
return;
}
# create an object from a hash. Needs to deal with the nested types, and
# arrays
sub create_from_hash {
my $class = shift;
my $hash = shift;
my $brain = shift || die "no brain supplied";
my $obj = $class->new(_brain => $brain);
# deal with each type of field
foreach my $type (keys %{ $class->fields }) {
my @fields_of_this_type = @{ $class->fields->{$type} };
foreach my $field (@fields_of_this_type) {
# ignore fields for which we have no value in the hash
next if (! defined $hash->{$field} );
# warn "type: $type field $field\n";
if ($type eq 'scalar') {
if ($obj->_field_is_array($field)) {
# simple scalar array ref, so just copy it
my $val = $hash->{$field};
# deal with boolean stuff so we don't pollute our object
# with JSON
if (ref($val) eq 'JSON::PP::Boolean') {
$val = !!$val;
}
$obj->$field($val);
}
elsif ($obj->_field_is_array_of_arrays) {
die "not yet implemented for scalars";
}
else {
my $val = $hash->{$field};
if (ref($val) eq 'JSON::PP::Boolean') {
$val = 0+$val;
}
$obj->$field($val);
}
}
else {
if ($obj->_field_is_array($field)) {
my @sub_array;
foreach my $data ( @{ $hash->{$field} } ) {
push @sub_array, $type->create_from_hash($data, $brain);
}
$obj->$field(\@sub_array);
}
elsif ($obj->_field_is_array_of_arrays) {
die "not yet implemented for scalars";
}
else {
$obj->$field($type->create_from_hash($hash->{$field}, $brain));
}
}
}
}
return $obj;
}
sub as_hashref {
my $self = shift;
my $hash = {};
# add the simple scalar values
foreach my $type ( keys %{ $self->fields }) {
my @fields = @{ $self->fields->{$type} };
foreach my $field (@fields) {
if ($type eq 'scalar') {
$hash->{$field} = $self->$field;
}
else {
# non array types
$hash->{$field} = $self->$field->as_hashref
if (ref($self->$field) ne 'ARRAY' && defined $self->$field);
# array types
$hash->{$field} = [
map { $_->as_hashref } @{ $self->$field }
] if (ref($self->$field) eq 'ARRAY');
}
}
}
return $hash;
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Telegram::Bot::Object::Base - The base class for all Telegram::Bot::Object objects.
=head1 VERSION
version 0.021
=head1 DESCRIPTION
This class should not be instantiated itself. Instead, instantiate a sub-class.
You should generally not need to instantiate objects of sub-classes of L<Telegram::Bot::Object::Base>,
instead the appropriate objects will be created from an incoming request via
L<Telegram::Bot::Brain>.
You can then use the methods referenced below on those objects.
=head1 METHODS
=head2 arrays
Should be overridden by subclasses, returning an array listing of which fields
for the object are arrays.
=head2 array_of_arrays
Should be overridden by subclasses, returning an array listing od which fields
for the object are arrays of arrays.
=head2 create_from_hash
Create an object of the appropriate class, including any sub-objects of
other types, as needed.
=head2 as_hashref
Return this object as a hashref.
=head1 AUTHOR
Justin Hawkins <justin@eatmorecode.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Justin Hawkins.
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

View File

@@ -0,0 +1,47 @@
package Telegram::Bot::Object::CallbackGame;
$Telegram::Bot::Object::CallbackGame::VERSION = '0.021';
# ABSTRACT: The base class for Telegram message 'CallbackGame' type.
use Mojo::Base 'Telegram::Bot::Object::Base';
# https://core.telegram.org/bots/api#callbackgame
# "A placeholder, currently holds no information. Use BotFather to set up your game"
sub fields {
return { },
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Telegram::Bot::Object::CallbackGame - The base class for Telegram message 'CallbackGame' type.
=head1 VERSION
version 0.021
=head1 DESCRIPTION
See L<https://core.telegram.org/bots/api#callbackgame> for details of the
attributes available for L<Telegram::Bot::Object::CallbackGame> objects.
=head1 AUTHOR
Justin Hawkins <justin@eatmorecode.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Justin Hawkins.
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

View File

@@ -0,0 +1,87 @@
package Telegram::Bot::Object::Chat;
$Telegram::Bot::Object::Chat::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'Chat' type objects
use Mojo::Base 'Telegram::Bot::Object::Base';
use Telegram::Bot::Object::ChatPhoto;
use Telegram::Bot::Object::Message;
has 'id';
has 'type';
has 'title';
has 'username';
has 'first_name';
has 'last_name';
has 'all_members_are_administrators';
has 'photo'; #ChatPhoto
has 'description';
has 'invite_link';
has 'pinned_message'; #Message
has 'sticker_set_name';
has 'can_set_sticker_set';
sub fields {
return {
'scalar' => [qw/id type title username first_name
last_name all_members_are_administrators
description invite_link sticker_set_name
can_set_sticker_set/],
'Telegram::Bot::Object::ChatPhoto' => [qw/photo/],
'Telegram::Bot::Object::Message' => [qw/pinned_message/],
};
}
sub is_user {
shift->id > 0;
}
sub is_group {
shift->id < 0;
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Telegram::Bot::Object::Chat - The base class for Telegram 'Chat' type objects
=head1 VERSION
version 0.021
=head1 DESCRIPTION
See L<https://core.telegram.org/bots/api#chat> for details of the
attributes available for L<Telegram::Bot::Object::Chat> objects.
=head1 METHODS
=head2 is_user
Returns true is this is a chat is a single user.
=head2 is_group
Returns true if this is a chat is a group.
=head1 AUTHOR
Justin Hawkins <justin@eatmorecode.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Justin Hawkins.
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

View File

@@ -0,0 +1,49 @@
package Telegram::Bot::Object::ChatPhoto;
$Telegram::Bot::Object::ChatPhoto::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'ChatPhoto' type objects
use Mojo::Base 'Telegram::Bot::Object::Base';
has 'small_file_id';
has 'big_file_id';
sub fields {
return {
'scalar' => [qw/small_file_id big_file_id/],
};
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Telegram::Bot::Object::ChatPhoto - The base class for Telegram 'ChatPhoto' type objects
=head1 VERSION
version 0.021
=head1 DESCRIPTION
See L<https://core.telegram.org/bots/api#chatphoto> for details of the
attributes available for L<Telegram::Bot::Object::ChatPhoto> objects.
=head1 AUTHOR
Justin Hawkins <justin@eatmorecode.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Justin Hawkins.
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

View File

@@ -0,0 +1,50 @@
package Telegram::Bot::Object::Contact;
$Telegram::Bot::Object::Contact::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'Contact' objects.
use Mojo::Base 'Telegram::Bot::Object::Base';
has 'phone_number';
has 'first_name';
has 'last_name';
has 'user_id';
sub fields {
return { scalar => [qw/phone_number first_name last_name user_id/],
};
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Telegram::Bot::Object::Contact - The base class for Telegram 'Contact' objects.
=head1 VERSION
version 0.021
=head1 DESCRIPTION
See L<https://core.telegram.org/bots/api#chat> for details of the
attributes available for L<Telegram::Bot::Object::Contact> objects.
=head1 AUTHOR
Justin Hawkins <justin@eatmorecode.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Justin Hawkins.
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

View File

@@ -0,0 +1,54 @@
package Telegram::Bot::Object::Document;
$Telegram::Bot::Object::Document::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'Document' objects
use Mojo::Base 'Telegram::Bot::Object::Base';
use Telegram::Bot::Object::PhotoSize;
has 'file_id';
has 'thumb'; #PhotoSize
has 'file_name';
has 'mime_type';
has 'file_size';
sub fields {
return { scalar => [qw/file_id file_name mime_type file_size/],
'Telegram::Bot::Object::PhotoSize' => [qw/thumb/]
};
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Telegram::Bot::Object::Document - The base class for Telegram 'Document' objects
=head1 VERSION
version 0.021
=head1 DESCRIPTION
See L<https://core.telegram.org/bots/api#document> for details of the
attributes available for L<Telegram::Bot::Object::Document> objects.
=head1 AUTHOR
Justin Hawkins <justin@eatmorecode.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Justin Hawkins.
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

View File

@@ -0,0 +1,48 @@
package Telegram::Bot::Object::EncryptedCredentials;
$Telegram::Bot::Object::EncryptedCredentials::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'EncryptedCredentials' type objects
use Mojo::Base 'Telegram::Bot::Object::Base';
has 'data';
has 'hash';
has 'secret';
sub fields {
return { 'scalar' => [qw/ data hash secret/] };
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Telegram::Bot::Object::EncryptedCredentials - The base class for Telegram 'EncryptedCredentials' type objects
=head1 VERSION
version 0.021
=head1 DESCRIPTION
See L<https://core.telegram.org/bots/api#encryptedcredentials> for details of the
attributes available for L<Telegram::Bot::Object::EncryptedCredentials> objects.
=head1 AUTHOR
Justin Hawkins <justin@eatmorecode.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Justin Hawkins.
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

View File

@@ -0,0 +1,56 @@
package Telegram::Bot::Object::EncryptedPassportElement;
$Telegram::Bot::Object::EncryptedPassportElement::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'EncryptedPassportElement' type objects
use Mojo::Base 'Telegram::Bot::Object::Base';
# XXX Implement rest of this
# https://core.telegram.org/bots/api#encryptedpassportelement
has 'type';
has 'data';
has 'phone_number';
has 'email';
# XXX more here
sub fields {
return { 'scalar' => [qw/type data phone_number email/] };
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Telegram::Bot::Object::EncryptedPassportElement - The base class for Telegram 'EncryptedPassportElement' type objects
=head1 VERSION
version 0.021
=head1 DESCRIPTION
See L<https://core.telegram.org/bots/api#encryptedpassportelement> for details of the
attributes available for L<Telegram::Bot::Object::EncryptedPassportElement> objects.
Note that this type is not yet fully implemented.
=head1 AUTHOR
Justin Hawkins <justin@eatmorecode.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Justin Hawkins.
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

View File

@@ -0,0 +1,60 @@
package Telegram::Bot::Object::Game;
$Telegram::Bot::Object::Game::VERSION = '0.021';
# ABSTRACT: The base class for Telegram message 'Game' type.
use Mojo::Base 'Telegram::Bot::Object::Base';
use Telegram::Bot::Object::PhotoSize;
use Telegram::Bot::Object::Animation;
use Telegram::Bot::Object::MessageEntity;
has 'title';
has 'description';
has 'photo'; # Array of PhotoSize
has 'text';
has 'text_entities'; #Array of MessageEntity
has 'animation'; #Animation
sub fields {
return { scalar => [qw/title description text/],
'Telegram::Bot::Object::PhotoSize' => [qw/photo/],
'Telegram::Bot::Object::MessageEntity' => [qw/text_entities/],
'Telegram::Bot::Object::Animation' => [qw/animation/],
};
}
sub arrays { qw/photo text_entities/ }
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Telegram::Bot::Object::Game - The base class for Telegram message 'Game' type.
=head1 VERSION
version 0.021
=head1 DESCRIPTION
See L<https://core.telegram.org/bots/api#game> for details of the
attributes available for L<Telegram::Bot::Object::Game> objects.
=head1 AUTHOR
Justin Hawkins <justin@eatmorecode.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Justin Hawkins.
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

View File

@@ -0,0 +1,60 @@
package Telegram::Bot::Object::InlineKeyboardButton;
$Telegram::Bot::Object::InlineKeyboardButton::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'InlineKeyboardButton' type objects
use Mojo::Base 'Telegram::Bot::Object::Base';
use Telegram::Bot::Object::LoginUrl;
use Telegram::Bot::Object::CallbackGame;
has 'text';
has 'url';
has 'login_url'; #LoginUrl
has 'callback_data';
has 'switch_inline_query';
has 'switch_inline_query_current_chat';
has 'callback_game'; # CallbackGame
has 'pay';
sub fields {
return { 'scalar' => [qw/text url callback_data switch_inline_query
switch_inline_query_current_chat switch_inline_query_current_chat
pay/],
'Telegram::Bot::Object::LoginUrl' => [qw/login_url/],
'Telegram::Bot::Object::CallbackGame'=> [qw/callback_game/],
};
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Telegram::Bot::Object::InlineKeyboardButton - The base class for Telegram 'InlineKeyboardButton' type objects
=head1 VERSION
version 0.021
=head1 DESCRIPTION
See L<https://core.telegram.org/bots/api#inlinekeyboardbutton> for details of the
attributes available for L<Telegram::Bot::Object::InlineKeyboardButton> objects.
=head1 AUTHOR
Justin Hawkins <justin@eatmorecode.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Justin Hawkins.
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

View File

@@ -0,0 +1,52 @@
package Telegram::Bot::Object::InlineKeyboardMarkup;
$Telegram::Bot::Object::InlineKeyboardMarkup::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'InlineKeyboardMarkup' type objects
use Mojo::Base 'Telegram::Bot::Object::Base';
use Telegram::Bot::Object::InlineKeyboardButton;
has 'inline_keyboard';
sub fields {
return { 'Telegram::Bot::Object::InlineKeyboardButton' => [qw/inline_keyboard/],
};
}
sub array_of_arrays {
qw/inline_keyboard/;
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Telegram::Bot::Object::InlineKeyboardMarkup - The base class for Telegram 'InlineKeyboardMarkup' type objects
=head1 VERSION
version 0.021
=head1 DESCRIPTION
See L<https://core.telegram.org/bots/api#inlinekeyboardmarkup> for details of the
attributes available for L<Telegram::Bot::Object::InlineKeyboardMarkup> objects.
=head1 AUTHOR
Justin Hawkins <justin@eatmorecode.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Justin Hawkins.
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

View File

@@ -0,0 +1,51 @@
package Telegram::Bot::Object::Invoice;
$Telegram::Bot::Object::Invoice::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'Invoice' type objects
use Mojo::Base 'Telegram::Bot::Object::Base';
has 'title';
has 'description';
has 'start_parameter';
has 'currency';
has 'total_amount';
sub fields {
return { scalar => [qw/title description start_parameter currency total_amount/],
};
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Telegram::Bot::Object::Invoice - The base class for Telegram 'Invoice' type objects
=head1 VERSION
version 0.021
=head1 DESCRIPTION
See L<https://core.telegram.org/bots/api#invoice> for details of the
attributes available for L<Telegram::Bot::Object::Invoice> objects.
=head1 AUTHOR
Justin Hawkins <justin@eatmorecode.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Justin Hawkins.
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

View File

@@ -0,0 +1,48 @@
package Telegram::Bot::Object::Location;
$Telegram::Bot::Object::Location::VERSION = '0.021';
# ABSTRACT: The base class for Telegram message 'Location' type.
use Mojo::Base 'Telegram::Bot::Object::Base';
has 'longitude';
has 'latitude';
sub fields {
return { scalar => [qw/longitude latitude/],
};
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Telegram::Bot::Object::Location - The base class for Telegram message 'Location' type.
=head1 VERSION
version 0.021
=head1 DESCRIPTION
See L<https://core.telegram.org/bots/api#location> for details of the
attributes available for L<Telegram::Bot::Object::Location> objects.
=head1 AUTHOR
Justin Hawkins <justin@eatmorecode.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Justin Hawkins.
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

View File

@@ -0,0 +1,49 @@
package Telegram::Bot::Object::LoginUrl;
$Telegram::Bot::Object::LoginUrl::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'LoginUrl' type objects
use Mojo::Base 'Telegram::Bot::Object::Base';
has 'url';
has 'forward_text';
has 'bot_username';
has 'request_write_access';
sub fields {
return { 'scalar' => [qw/url forward_text bot_username request_write_access/] };
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Telegram::Bot::Object::LoginUrl - The base class for Telegram 'LoginUrl' type objects
=head1 VERSION
version 0.021
=head1 DESCRIPTION
See L<https://core.telegram.org/bots/api#loginurl> for details of the
attributes available for L<Telegram::Bot::Object::LoginUrl> objects.
=head1 AUTHOR
Justin Hawkins <justin@eatmorecode.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Justin Hawkins.
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

View File

@@ -0,0 +1,178 @@
package Telegram::Bot::Object::Message;
$Telegram::Bot::Object::Message::VERSION = '0.021';
# ABSTRACT: The base class for the Telegram type "Message".
use Mojo::Base 'Telegram::Bot::Object::Base';
use Telegram::Bot::Object::User;
use Telegram::Bot::Object::Chat;
use Telegram::Bot::Object::MessageEntity;
use Telegram::Bot::Object::Audio;
use Telegram::Bot::Object::Document;
use Telegram::Bot::Object::Animation;
use Telegram::Bot::Object::Game;
use Telegram::Bot::Object::PhotoSize;
use Telegram::Bot::Object::Sticker;
use Telegram::Bot::Object::Video;
use Telegram::Bot::Object::Voice;
use Telegram::Bot::Object::VideoNote;
use Telegram::Bot::Object::Contact;
use Telegram::Bot::Object::Location;
use Telegram::Bot::Object::Poll;
use Telegram::Bot::Object::Location;
use Telegram::Bot::Object::PhotoSize;
use Telegram::Bot::Object::Invoice;
use Telegram::Bot::Object::Venue;
use Telegram::Bot::Object::SuccessfulPayment;
use Telegram::Bot::Object::PassportData;
use Telegram::Bot::Object::InlineKeyboardMarkup;
use Data::Dumper;
# basic message stuff
has 'message_id';
has 'from'; # User
has 'date';
has 'chat'; # Chat
has 'forward_from'; # User
has 'forward_from_chat'; # Chat
has 'forward_from_message_id';
has 'forward_signature';
has 'forward_sender_name';
has 'forward_date';
has 'reply_to_message'; # Message
has 'edit_date';
has 'media_group_id';
has 'author_signature';
has 'text';
has 'entities'; # Array of MessageEntity
has 'caption_entities'; # Array of MessageEntity
has 'audio'; # Audio
has 'document'; # Document
has 'animation'; # Animation
has 'game'; # Game
has 'photo'; # Array of PhotoSize
has 'sticker'; # Sticker
has 'video'; # Video
has 'voice'; # Voice
has 'video_note'; # VideoNote
has 'caption';
has 'contact'; # Contact
has 'location'; # Location
has 'venue'; # Venue
has 'poll'; # Poll
has 'new_chat_members'; # Array of User
has 'left_chat_member'; # User
has 'new_chat_title';
has 'new_chat_photo'; # Array of PhotoSize
has 'delete_chat_photo';
has 'group_chat_created';
has 'supergroup_chat_created';
has 'channel_chat_created';
has 'migrate_to_chat_id';
has 'migrate_from_chat_id';
has 'pinned_message'; # Message
has 'invoice'; # Invoice
has 'successful_payment'; # SuccessfulPayment
has 'connected_website';
has 'passport_data'; # PassportData
has 'reply_markup'; # Array of InlineKeyboardMarkup
sub fields {
return {
'scalar' => [qw/message_id date forward_from_message_id
forward_signature forward_sender_name
forward_date edit_date media_group_id
author_signature text caption
new_chat_title delete_chat_photo
group_chat_created supergroup_chat_created
channel_chat_created migrate_to_chat_id
migrate_from_chat_id connected_website/],
'Telegram::Bot::Object::User' => [qw/from forward_from new_chat_members left_chat_member /],
'Telegram::Bot::Object::Chat' => [qw/chat forward_from_chat/],
'Telegram::Bot::Object::Message' => [qw/reply_to_message pinned_message/],
'Telegram::Bot::Object::MessageEntity' => [qw/entities caption_entities /],
'Telegram::Bot::Object::Audio' => [qw/audio/],
'Telegram::Bot::Object::Document' => [qw/document/],
'Telegram::Bot::Object::Animation' => [qw/animation/],
'Telegram::Bot::Object::Game' => [qw/game/],
'Telegram::Bot::Object::PhotoSize' => [qw/photo new_chat_photo/],
'Telegram::Bot::Object::Sticker' => [qw/sticker/],
'Telegram::Bot::Object::Video' => [qw/video/],
'Telegram::Bot::Object::Voice' => [qw/voice/],
'Telegram::Bot::Object::VideoNote' => [qw/video_note/],
'Telegram::Bot::Object::Contact' => [qw/contact/],
'Telegram::Bot::Object::Location' => [qw/location/],
'Telegram::Bot::Object::Venue' => [qw/venue/],
'Telegram::Bot::Object::Poll' => [qw/poll/],
'Telegram::Bot::Object::Invoice' => [qw/invoice/],
'Telegram::Bot::Object::SuccessfulPayment' => [qw/successful_payment/],
'Telegram::Bot::Object::PassportData' => [qw/passport_data/],
'Telegram::Bot::Object::InlineKeyboardMarkup' => [qw/reply_markup/],
};
}
sub arrays {
qw/photo entities caption_entities new_chat_members new_chat_photo/
}
sub reply {
my $self = shift;
my $text = shift;
return $self->_brain->sendMessage({chat_id => $self->chat->id, text => $text});
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Telegram::Bot::Object::Message - The base class for the Telegram type "Message".
=head1 VERSION
version 0.021
=head1 DESCRIPTION
See L<https://core.telegram.org/bots/api#message> for details of the
attributes available for L<Telegram::Bot::Object::Message> objects.
=head1 METHODS
=head2
A convenience method to reply to a message with text.
Will return the L<Telegram::Bot::Object::Message> object representing the message
sent.
=head1 AUTHOR
Justin Hawkins <justin@eatmorecode.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Justin Hawkins.
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

View File

@@ -0,0 +1,54 @@
package Telegram::Bot::Object::MessageEntity;
$Telegram::Bot::Object::MessageEntity::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'MessageEntity' type objects
use Mojo::Base 'Telegram::Bot::Object::Base';
use Telegram::Bot::Object::User;
has 'type';
has 'offset';
has 'length';
has 'url';
has 'user'; #User
sub fields {
return {
'scalar' => [qw/type offset length url/],
'Telegram::Bot::Object::User' => [qw/user/],
};
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Telegram::Bot::Object::MessageEntity - The base class for Telegram 'MessageEntity' type objects
=head1 VERSION
version 0.021
=head1 DESCRIPTION
See L<https://core.telegram.org/bots/api#messageentity> for details of the
attributes available for L<Telegram::Bot::Object::MessageEntity> objects.
=head1 AUTHOR
Justin Hawkins <justin@eatmorecode.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Justin Hawkins.
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

View File

@@ -0,0 +1,54 @@
package Telegram::Bot::Object::PassportData;
$Telegram::Bot::Object::PassportData::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'PassportData' type objects
use Mojo::Base 'Telegram::Bot::Object::Base';
use Telegram::Bot::Object::EncryptedPassportElement;
use Telegram::Bot::Object::EncryptedCredentials;
has 'data'; # Array of EncryptedPassportElement
has 'credentials'; # EncryptedCredentials
sub fields {
return { 'Telegram::Bot::Object::EncryptedPassportElement' => [qw/data/],
'Telegram::Bot::Object::EncryptedCredentials' => [qw/credentials/],
};
}
sub arrays {
qw/data/;
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Telegram::Bot::Object::PassportData - The base class for Telegram 'PassportData' type objects
=head1 VERSION
version 0.021
=head1 DESCRIPTION
See L<https://core.telegram.org/bots/api#passportdata> for details of the
attributes available for L<Telegram::Bot::Object::PassportData> objects.
=head1 AUTHOR
Justin Hawkins <justin@eatmorecode.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Justin Hawkins.
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

View File

@@ -0,0 +1,51 @@
package Telegram::Bot::Object::PhotoSize;
$Telegram::Bot::Object::PhotoSize::VERSION = '0.021';
# ABSTRACT: The base class for Telegram message 'PhotoSize' type.
use Mojo::Base 'Telegram::Bot::Object::Base';
use Carp qw/croak/;
has 'file_id';
has 'width';
has 'height';
has 'file_size';
sub fields {
return { scalar => [qw/file_id width height file_size/]
};
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Telegram::Bot::Object::PhotoSize - The base class for Telegram message 'PhotoSize' type.
=head1 VERSION
version 0.021
=head1 DESCRIPTION
See L<https://core.telegram.org/bots/api#photosize> for details of the
attributes available for L<Telegram::Bot::Object::PhotoSize> objects.
=head1 AUTHOR
Justin Hawkins <justin@eatmorecode.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Justin Hawkins.
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

View File

@@ -0,0 +1,58 @@
package Telegram::Bot::Object::Poll;
$Telegram::Bot::Object::Poll::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'Poll' type objects
use Mojo::Base 'Telegram::Bot::Object::Base';
use Telegram::Bot::Object::PollOption;
has 'id';
has 'question';
has 'options'; # Array of PollOption
has 'is_closed';
sub fields {
return { scalar => [qw/id question is_closed/],
'Telegram::Bot::Object::PollOption' => [qw/options /],
};
}
sub arrays {
qw/options/;
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Telegram::Bot::Object::Poll - The base class for Telegram 'Poll' type objects
=head1 VERSION
version 0.021
=head1 DESCRIPTION
See L<https://core.telegram.org/bots/api#poll> for details of the
attributes available for L<Telegram::Bot::Object::Poll> objects.
=head1 AUTHOR
Justin Hawkins <justin@eatmorecode.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Justin Hawkins.
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

View File

@@ -0,0 +1,48 @@
package Telegram::Bot::Object::PollOption;
$Telegram::Bot::Object::PollOption::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'PollOption' type objects
use Mojo::Base 'Telegram::Bot::Object::Base';
has 'text';
has 'voter_count';
sub fields {
return { scalar => [qw/text voter_count/],
};
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Telegram::Bot::Object::PollOption - The base class for Telegram 'PollOption' type objects
=head1 VERSION
version 0.021
=head1 DESCRIPTION
See L<https://core.telegram.org/bots/api#polloption> for details of the
attributes available for L<Telegram::Bot::Object::PollOption> objects.
=head1 AUTHOR
Justin Hawkins <justin@eatmorecode.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Justin Hawkins.
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

View File

@@ -0,0 +1,57 @@
package Telegram::Bot::Object::Sticker;
$Telegram::Bot::Object::Sticker::VERSION = '0.021';
# ABSTRACT: The base class for Telegram message 'Sticker' type.
use Mojo::Base 'Telegram::Bot::Object::Base';
use Telegram::Bot::Object::PhotoSize;
has 'file_id';
has 'width';
has 'height';
has 'thumb'; # PhotoSize
has 'emoji';
has 'set_name';
# has 'mask_position'; # XXX TODO
has 'file_size';
sub fields {
return { scalar => [qw/file_id width height emoji
set_name file_size /],
'Telegram::Bot::Object::PhotoSize' => [ qw/thumb/ ],
};
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Telegram::Bot::Object::Sticker - The base class for Telegram message 'Sticker' type.
=head1 VERSION
version 0.021
=head1 DESCRIPTION
See L<https://core.telegram.org/bots/api#sticker> for details of the
attributes available for L<Telegram::Bot::Object::Sticker> objects.
=head1 AUTHOR
Justin Hawkins <justin@eatmorecode.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Justin Hawkins.
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

View File

@@ -0,0 +1,57 @@
package Telegram::Bot::Object::SuccessfulPayment;
$Telegram::Bot::Object::SuccessfulPayment::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'SuccessfulPayment' type objects
use Mojo::Base 'Telegram::Bot::Object::Base';
# use Telegram::Bot::Object::OrderInfo;
has 'currency';
has 'total_amount';
has 'invoice_payload';
has 'shipping_option_id';
# has 'order_info'; #OrderInfo XXX
has 'telegram_payment_charge_id';
has 'provider_payment_charge_id';
sub fields {
return { scalar => [qw/currency total_amount invoice_payload shipping_option_id
telegram_payment_charge_id provider_payment_charge_id/],
# 'Telegram::Bot::Object::OrderInfo' => [qw/order_info/],
};
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Telegram::Bot::Object::SuccessfulPayment - The base class for Telegram 'SuccessfulPayment' type objects
=head1 VERSION
version 0.021
=head1 DESCRIPTION
See L<https://core.telegram.org/bots/api#successfulpayment> for details of the
attributes available for L<Telegram::Bot::Object::SuccessfulPayment> objects.
=head1 AUTHOR
Justin Hawkins <justin@eatmorecode.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Justin Hawkins.
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

View File

@@ -0,0 +1,52 @@
package Telegram::Bot::Object::User;
$Telegram::Bot::Object::User::VERSION = '0.021';
# ABSTRACT: The base class for Telegram message 'User' type.
use Mojo::Base 'Telegram::Bot::Object::Base';
has 'id';
has 'is_bot';
has 'first_name';
has 'last_name'; # optional
has 'username'; # optional
has 'language_code'; # optional
sub fields {
return { scalar => [qw/id is_bot first_name last_name username language_code/]
};
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Telegram::Bot::Object::User - The base class for Telegram message 'User' type.
=head1 VERSION
version 0.021
=head1 DESCRIPTION
See L<https://core.telegram.org/bots/api#user> for details of the
attributes available for L<Telegram::Bot::Object::User> objects.
=head1 AUTHOR
Justin Hawkins <justin@eatmorecode.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Justin Hawkins.
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

View File

@@ -0,0 +1,54 @@
package Telegram::Bot::Object::Venue;
$Telegram::Bot::Object::Venue::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'LoginUrl' type objects
use Mojo::Base 'Telegram::Bot::Object::Base';
use Telegram::Bot::Object::Location;
has 'location'; #Location
has 'title';
has 'address';
has 'foursquare_id';
has 'foursquare_type';
sub fields {
return { 'scalar' => [qw/title address
foursquare_id foursquare_type/],
'Telegram::Bot::Object::Location' => [qw/location/] };
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Telegram::Bot::Object::Venue - The base class for Telegram 'LoginUrl' type objects
=head1 VERSION
version 0.021
=head1 DESCRIPTION
See L<https://core.telegram.org/bots/api#venue> for details of the
attributes available for L<Telegram::Bot::Object::Venue> objects.
=head1 AUTHOR
Justin Hawkins <justin@eatmorecode.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Justin Hawkins.
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

View File

@@ -0,0 +1,56 @@
package Telegram::Bot::Object::Video;
$Telegram::Bot::Object::Video::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'Video' object.
use Mojo::Base 'Telegram::Bot::Object::Base';
use Telegram::Bot::Object::PhotoSize;
has 'file_id';
has 'width';
has 'height';
has 'duration';
has 'thumb'; #PhotoSize
has 'mime_type';
has 'file_size';
sub fields {
return { scalar => [qw/file_id width height duration
mime_type file_size /],
'Telegram::Bot::Object::PhotoSize' => [qw/thumb/]
};
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Telegram::Bot::Object::Video - The base class for Telegram 'Video' object.
=head1 VERSION
version 0.021
=head1 DESCRIPTION
See L<https://core.telegram.org/bots/api#video> for details of the
attributes available for L<Telegram::Bot::Object::Video> objects.
=head1 AUTHOR
Justin Hawkins <justin@eatmorecode.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Justin Hawkins.
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

View File

@@ -0,0 +1,55 @@
package Telegram::Bot::Object::VideoNote;
$Telegram::Bot::Object::VideoNote::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'VideoNote' type objects
use Mojo::Base 'Telegram::Bot::Object::Base';
use Telegram::Bot::Object::PhotoSize;
has 'file_id';
has 'length';
has 'duration';
has 'mime_type';
has 'thumb'; #PhotoSize
has 'file_size';
sub fields {
return { scalar => [qw/file_id length duration mime_type file_size/],
'Telegram::Bot::Object::PhotoSize' => [qw/thumb /],
};
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Telegram::Bot::Object::VideoNote - The base class for Telegram 'VideoNote' type objects
=head1 VERSION
version 0.021
=head1 DESCRIPTION
See L<https://core.telegram.org/bots/api#videonote> for details of the
attributes available for L<Telegram::Bot::Object::VideoNote> objects.
=head1 AUTHOR
Justin Hawkins <justin@eatmorecode.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Justin Hawkins.
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

View File

@@ -0,0 +1,50 @@
package Telegram::Bot::Object::Voice;
$Telegram::Bot::Object::Voice::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'Voice' type objects
use Mojo::Base 'Telegram::Bot::Object::Base';
has 'file_id';
has 'duration';
has 'mime_type';
has 'file_size';
sub fields {
return { scalar => [qw/file_id duration mime_type file_size/]
};
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Telegram::Bot::Object::Voice - The base class for Telegram 'Voice' type objects
=head1 VERSION
version 0.021
=head1 DESCRIPTION
See L<https://core.telegram.org/bots/api#voice> for details of the
attributes available for L<Telegram::Bot::Object::Voice> objects.
=head1 AUTHOR
Justin Hawkins <justin@eatmorecode.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Justin Hawkins.
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