1717use Longman \TelegramBot \Entities \ChosenInlineResult ;
1818use Longman \TelegramBot \Entities \InlineQuery ;
1919use Longman \TelegramBot \Entities \Message ;
20+ use Longman \TelegramBot \Entities \Poll ;
2021use Longman \TelegramBot \Entities \ReplyToMessage ;
2122use Longman \TelegramBot \Entities \Update ;
2223use Longman \TelegramBot \Entities \User ;
@@ -141,6 +142,7 @@ protected static function defineTables()
141142 'edited_message ' ,
142143 'inline_query ' ,
143144 'message ' ,
145+ 'poll ' ,
144146 'request_limiter ' ,
145147 'telegram_update ' ,
146148 'user ' ,
@@ -309,6 +311,7 @@ public static function entitiesArrayToJson($entities, $default = null)
309311 * @param string $chosen_inline_result_id
310312 * @param string $callback_query_id
311313 * @param string $edited_message_id
314+ * @param string $poll_id
312315 *
313316 * @return bool If the insert was successful
314317 * @throws TelegramException
@@ -320,10 +323,11 @@ public static function insertTelegramUpdate(
320323 $ inline_query_id = null ,
321324 $ chosen_inline_result_id = null ,
322325 $ callback_query_id = null ,
323- $ edited_message_id = null
326+ $ edited_message_id = null ,
327+ $ poll_id = null
324328 ) {
325- if ($ message_id === null && $ inline_query_id === null && $ chosen_inline_result_id === null && $ callback_query_id === null && $ edited_message_id === null ) {
326- throw new TelegramException ('message_id, inline_query_id, chosen_inline_result_id, callback_query_id, edited_message_id are all null ' );
329+ if ($ message_id === null && $ inline_query_id === null && $ chosen_inline_result_id === null && $ callback_query_id === null && $ edited_message_id === null && $ poll_id === null ) {
330+ throw new TelegramException ('message_id, inline_query_id, chosen_inline_result_id, callback_query_id, edited_message_id, poll_id are all null ' );
327331 }
328332
329333 if (!self ::isDbConnected ()) {
@@ -333,9 +337,9 @@ public static function insertTelegramUpdate(
333337 try {
334338 $ sth = self ::$ pdo ->prepare ('
335339 INSERT IGNORE INTO ` ' . TB_TELEGRAM_UPDATE . '`
336- (`id`, `chat_id`, `message_id`, `inline_query_id`, `chosen_inline_result_id`, `callback_query_id`, `edited_message_id`)
340+ (`id`, `chat_id`, `message_id`, `inline_query_id`, `chosen_inline_result_id`, `callback_query_id`, `edited_message_id`, `poll_id` )
337341 VALUES
338- (:id, :chat_id, :message_id, :inline_query_id, :chosen_inline_result_id, :callback_query_id, :edited_message_id)
342+ (:id, :chat_id, :message_id, :inline_query_id, :chosen_inline_result_id, :callback_query_id, :edited_message_id, :poll_id )
339343 ' );
340344
341345 $ sth ->bindValue (':id ' , $ id );
@@ -345,6 +349,7 @@ public static function insertTelegramUpdate(
345349 $ sth ->bindValue (':inline_query_id ' , $ inline_query_id );
346350 $ sth ->bindValue (':chosen_inline_result_id ' , $ chosen_inline_result_id );
347351 $ sth ->bindValue (':callback_query_id ' , $ callback_query_id );
352+ $ sth ->bindValue (':poll_id ' , $ poll_id );
348353
349354 return $ sth ->execute ();
350355 } catch (PDOException $ e ) {
@@ -599,6 +604,23 @@ public static function insertRequest(Update $update)
599604 $ callback_query_id
600605 );
601606 }
607+ } elseif ($ update_type === 'poll ' ) {
608+ $ poll = $ update ->getPoll ();
609+
610+ if (self ::insertPollRequest ($ poll )) {
611+ $ poll_id = $ poll ->getId ();
612+
613+ return self ::insertTelegramUpdate (
614+ $ update_id ,
615+ null ,
616+ null ,
617+ null ,
618+ null ,
619+ null ,
620+ null ,
621+ $ poll_id
622+ );
623+ }
602624 }
603625
604626 return false ;
@@ -759,6 +781,43 @@ public static function insertCallbackQueryRequest(CallbackQuery $callback_query)
759781 }
760782 }
761783
784+ /**
785+ * Insert poll request into database
786+ *
787+ * @param Poll $poll
788+ *
789+ * @return bool If the insert was successful
790+ * @throws TelegramException
791+ */
792+ public static function insertPollRequest (Poll $ poll )
793+ {
794+ if (!self ::isDbConnected ()) {
795+ return false ;
796+ }
797+
798+ try {
799+ $ sth = self ::$ pdo ->prepare ('
800+ INSERT INTO ` ' . TB_POLL . '`
801+ (`id`, `question`, `options`, `is_closed`, `created_at`)
802+ VALUES
803+ (:id, :question, :options, :is_closed, :created_at)
804+ ON DUPLICATE KEY UPDATE
805+ `options` = VALUES(`options`),
806+ `is_closed` = VALUES(`is_closed`)
807+ ' );
808+
809+ $ sth ->bindValue (':id ' , $ poll ->getId ());
810+ $ sth ->bindValue (':question ' , $ poll ->getQuestion ());
811+ $ sth ->bindValue (':options ' , self ::entitiesArrayToJson ($ poll ->getOptions (), null ));
812+ $ sth ->bindValue (':is_closed ' , $ poll ->getIsClosed ());
813+ $ sth ->bindValue (':created_at ' , self ::getTimestamp ());
814+
815+ return $ sth ->execute ();
816+ } catch (PDOException $ e ) {
817+ throw new TelegramException ($ e ->getMessage ());
818+ }
819+ }
820+
762821 /**
763822 * Insert Message request in db
764823 *
0 commit comments