Add support for handling poll answer updates

This commit is contained in:
netkas 2024-11-01 18:16:17 -04:00
parent 3ce87cabcb
commit d56cc3dd22
3 changed files with 37 additions and 0 deletions

View file

@ -86,6 +86,11 @@
return UpdateEventType::MY_CHAT_MEMBER_UPDATED;
}
if($update->getPollAnswer() !== null)
{
return UpdateEventType::POLL_ANSWER;
}
return UpdateEventType::UPDATE_EVENT;
}
}

View file

@ -7,6 +7,7 @@
use TgBotLib\Events\ChatJoinRequestEvent;
use TgBotLib\Events\ChatMemberUpdatedEvent;
use TgBotLib\Events\MyChatMemberUpdatedEvent;
use TgBotLib\Events\PollAnswerEvent;
use TgBotLib\Events\RemovedChatBoostEvent;
enum UpdateEventType : string
@ -17,4 +18,5 @@
case CHAT_JOIN_REQUEST_EVENT = ChatJoinRequestEvent::class;
case CHAT_MEMBER_UPDATED = ChatMemberUpdatedEvent::class;
case MY_CHAT_MEMBER_UPDATED = MyChatMemberUpdatedEvent::class;
case POLL_ANSWER = PollAnswerEvent::class;
}

View file

@ -0,0 +1,30 @@
<?php
namespace TgBotLib\Events;
use TgBotLib\Abstracts\UpdateEvent;
use TgBotLib\Bot;
use TgBotLib\Enums\UpdateEventType;
use TgBotLib\Objects\PollAnswer;
abstract class PollAnswerEvent extends UpdateEvent
{
/**
* @inheritDoc
*/
public static function getEventType(): UpdateEventType
{
return UpdateEventType::POLL_ANSWER;
}
/**
* A user changed their answer in a non-anonymous poll.
* Bots receive new votes only in polls that were sent by the bot itself.
*
* @return PollAnswer The poll answer associated with the current update.
*/
protected function getPollAnswer(): PollAnswer
{
return $this->update->getPollAnswer();
}
}