1

Make bot more human-like by delaying answers

- Greet newcommers with notable randomized delay + send "typing", pretending we are real human :)
- Make 1-2 second delay in group chat before answer.
This commit is contained in:
eleksir
2020-10-10 14:17:25 +03:00
parent 0d0b8bb4c2
commit 9abb221dac
2 changed files with 30 additions and 1 deletions

View File

@@ -13,7 +13,7 @@ use Telegram::Bot::Brain;
# module shit
use vars qw/$VERSION/;
use Exporter qw(import);
our @EXPORT = qw(getChat getChatMember visavi);
our @EXPORT = qw(getChat getChatMember sendChatAction visavi);
$VERSION = "1.0";
@@ -52,6 +52,23 @@ sub getChatMember {
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 Telegram::Bot::Object::User->create_from_hash($api_response, $self);
return;
}
sub visavi (@) {
my ($userid, $username, $fullname) = @_;
my $name = '';