Minor Changes

This commit is contained in:
Netkas 2023-02-20 16:06:11 -05:00
parent 11e60c56c4
commit e3ed0529b9
4 changed files with 34 additions and 21 deletions

View file

@ -5,36 +5,22 @@
abstract class EventType
{
const GenericUpdate = 'generic_update';
const Message = 'message';
const EditedMessage = 'edited_message';
const GenericCommandMessage = 'generic_command_message';
const ChatMemberJoined = 'chat_member_joined';
const ChatMemberLeft = 'chat_member_left';
const ChatMemberKicked = 'chat_member_kicked';
const ChatMemberBanned = 'chat_member_banned';
const ChatMemberUnbanned = 'chat_member_unbanned';
const ChatMemberPromoted = 'chat_member_promoted';
const ChatMemberDemoted = 'chat_member_demoted';
const ChatMemberRestricted = 'chat_member_restricted';
const ChatMemberUnrestricted = 'chat_member_unrestricted';
const ChatMemberChanged = 'chat_member_changed';
const ChatTitleChanged = 'chat_title_changed';
const ChatPhotoChanged = 'chat_photo_changed';
Const CallbackQuery = 'callback_query';
const ChatDescriptionChanged = 'chat_description_changed';
}

View file

@ -6,6 +6,7 @@
use CURLFile;
use CurlHandle;
use Exception;
use InvalidArgumentException;
use TgBotLib\Abstracts\ChatMemberStatus;
use TgBotLib\Abstracts\EventType;
@ -129,6 +130,7 @@
* Sets whether the library will use SSL to send requests
*
* @param bool $ssl
* @noinspection PhpUnused
*/
public function setSsl(bool $ssl): void
{
@ -405,6 +407,13 @@
$handler->handle($this, $update);
}
break;
case EventType::CallbackQuery:
if(($update->getCallbackQuery() ?? null) !== null)
{
$handler->handle($this, $update);
}
break;
}
}
@ -2165,4 +2174,19 @@
]);
return true;
}
/**
* Public Destructor
*/
public function __destruct()
{
try
{
$this->close();
}
catch(Exception $e)
{
unset($e);
}
}
}

View file

@ -18,6 +18,8 @@
public function handle(Bot $bot, Update $update): void
{
// reply to the incoming message
$bot->sendMessage($update->getMessage()->getChat()->getId(), 'Hello, ' . $update->getMessage()->getFrom()->getFirstName());
$bot->sendMessage(
$update->getMessage()->getChat()->getId(), 'Hello, ' . $update->getMessage()->getFrom()->getFirstName()
);
}
}

View file

@ -1,13 +1,14 @@
<?php
use commands\StartCommand;
require 'ncc';
import('net.nosial.tgbotlib');
require 'commands/StartCommand.php';
$bot = new TgBotLib\Bot('YOUR_BOT_TOKEN');
$bot->setCommandHandler('start', new StartCommand());
$bot = new TgBotLib\Bot('865804194:AAHTo9aIFP5X47dMYLJ6eoldHJnM6sc3LBc');
$bot->setCommandHandler('start', new \commands\StartCommand());
$bot->handleGetUpdates(true);
print_r(json_encode($bot->getMe()->toArray()) . PHP_EOL);
$bot->sendMessage(570787098, 'Hello, world!');
$bot->handleGetUpdates();
unset($bot);