Add support for handling poll answer updates
This commit is contained in:
parent
3ce87cabcb
commit
d56cc3dd22
3 changed files with 37 additions and 0 deletions
|
@ -86,6 +86,11 @@
|
|||
return UpdateEventType::MY_CHAT_MEMBER_UPDATED;
|
||||
}
|
||||
|
||||
if($update->getPollAnswer() !== null)
|
||||
{
|
||||
return UpdateEventType::POLL_ANSWER;
|
||||
}
|
||||
|
||||
return UpdateEventType::UPDATE_EVENT;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
30
src/TgBotLib/Events/PollAnswerEvent.php
Normal file
30
src/TgBotLib/Events/PollAnswerEvent.php
Normal 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();
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue