1

Use Teapot' sendChatAction, getChat and getChatMember, remove dups of these subs in telegramlib.pm

This commit is contained in:
eleksir
2020-10-30 16:15:11 +03:00
parent f0b1ae9c43
commit 43c0286414
2 changed files with 26 additions and 61 deletions

View File

@@ -13,62 +13,10 @@ use Teapot::Bot::Brain;
# module shit
use vars qw/$VERSION/;
use Exporter qw(import);
our @EXPORT_OK = qw(getChat getChatMember sendChatAction visavi);
our @EXPORT_OK = qw(visavi);
$VERSION = '1.0';
# complete framework with our getChat()
sub getChat {
my $self = shift;
my $id = shift;
my $send_args = {};
$send_args->{chat_id} = $id;
my $token = $self->token;
my $url = "https://api.telegram.org/bot${token}/getChat";
my $api_response = $self->_post_request ($url, $send_args);
# we seek for permissions, when making call to this subroutine, but
# framework does just omits it, when creating object from hash, so
# pick raw json object instead
#return Teapot::Bot::Object::User->create_from_hash($api_response, $self);
return $api_response;
}
# complete framework with our getChatMember()
sub getChatMember {
my $self = shift;
my $chatid = shift;
my $userid = shift;
my $send_args = {};
$send_args->{chat_id} = $chatid;
$send_args->{user_id} = $userid;
my $token = $self->token;
my $url = "https://api.telegram.org/bot${token}/getChatMember";
my $api_response = $self->_post_request ($url, $send_args);
# return Teapot::Bot::Object::User->create_from_hash($api_response, $self);
return $api_response;
}
# complete framework with our sendChatAction()
# sets bot status to "typing" for 5 seconds
# # TODO: more actions!
sub sendChatAction {
my $self = shift;
my $chatid = shift;
my $send_args = {};
$send_args->{chat_id} = $chatid;
$send_args->{action} = 'typing';
my $token = $self->token;
my $url = "https://api.telegram.org/bot${token}/sendChatAction";
my $api_response = $self->_post_request ($url, $send_args);
# return Teapot::Bot::Object::User->create_from_hash($api_response, $self);
return;
}
sub visavi {
my ($userid, $username, $fullname) = @_;
my $name = '';