1414
1515use Longman \TelegramBot \Entities \CallbackQuery ;
1616use Longman \TelegramBot \Entities \Chat ;
17+ use Longman \TelegramBot \Entities \ChatMemberUpdated ;
1718use Longman \TelegramBot \Entities \ChosenInlineResult ;
1819use Longman \TelegramBot \Entities \InlineQuery ;
1920use Longman \TelegramBot \Entities \Message ;
@@ -140,13 +141,14 @@ protected static function defineTables(): void
140141 $ tables = [
141142 'callback_query ' ,
142143 'chat ' ,
144+ 'chat_member_updated ' ,
143145 'chosen_inline_result ' ,
144146 'edited_message ' ,
145147 'inline_query ' ,
146148 'message ' ,
147- 'pre_checkout_query ' ,
148149 'poll ' ,
149150 'poll_answer ' ,
151+ 'pre_checkout_query ' ,
150152 'request_limiter ' ,
151153 'shipping_query ' ,
152154 'telegram_update ' ,
@@ -320,6 +322,8 @@ public static function entitiesArrayToJson(array $entities, $default = null)
320322 * @param string|null $pre_checkout_query_id
321323 * @param string|null $poll_id
322324 * @param string|null $poll_answer_poll_id
325+ * @param string|null $my_chat_member_updated_id
326+ * @param string|null $chat_member_updated_id
323327 *
324328 * @return bool If the insert was successful
325329 * @throws TelegramException
@@ -337,10 +341,12 @@ protected static function insertTelegramUpdate(
337341 ?string $ shipping_query_id = null ,
338342 ?string $ pre_checkout_query_id = null ,
339343 ?string $ poll_id = null ,
340- ?string $ poll_answer_poll_id = null
344+ ?string $ poll_answer_poll_id = null ,
345+ ?string $ my_chat_member_updated_id = null ,
346+ ?string $ chat_member_updated_id = null
341347 ): ?bool {
342- if ($ message_id === null && $ edited_message_id === null && $ channel_post_id === null && $ edited_channel_post_id === null && $ inline_query_id === null && $ chosen_inline_result_id === null && $ callback_query_id === null && $ shipping_query_id === null && $ pre_checkout_query_id === null && $ poll_id === null && $ poll_answer_poll_id === null ) {
343- throw new TelegramException ('message_id, edited_message_id, channel_post_id, edited_channel_post_id, inline_query_id, chosen_inline_result_id, callback_query_id, shipping_query_id, pre_checkout_query_id, poll_id, poll_answer_poll_id are all null ' );
348+ if ($ message_id === null && $ edited_message_id === null && $ channel_post_id === null && $ edited_channel_post_id === null && $ inline_query_id === null && $ chosen_inline_result_id === null && $ callback_query_id === null && $ shipping_query_id === null && $ pre_checkout_query_id === null && $ poll_id === null && $ poll_answer_poll_id === null && $ my_chat_member_updated_id === null && $ chat_member_updated_id === null ) {
349+ throw new TelegramException ('message_id, edited_message_id, channel_post_id, edited_channel_post_id, inline_query_id, chosen_inline_result_id, callback_query_id, shipping_query_id, pre_checkout_query_id, poll_id, poll_answer_poll_id, my_chat_member_updated_id, chat_member_updated_id are all null ' );
344350 }
345351
346352 if (!self ::isDbConnected ()) {
@@ -350,9 +356,9 @@ protected static function insertTelegramUpdate(
350356 try {
351357 $ sth = self ::$ pdo ->prepare ('
352358 INSERT IGNORE INTO ` ' . TB_TELEGRAM_UPDATE . '`
353- (`id`, `chat_id`, `message_id`, `edited_message_id`, `channel_post_id`, `edited_channel_post_id`, `inline_query_id`, `chosen_inline_result_id`, `callback_query_id`, `shipping_query_id`, `pre_checkout_query_id`, `poll_id`, `poll_answer_poll_id`)
359+ (`id`, `chat_id`, `message_id`, `edited_message_id`, `channel_post_id`, `edited_channel_post_id`, `inline_query_id`, `chosen_inline_result_id`, `callback_query_id`, `shipping_query_id`, `pre_checkout_query_id`, `poll_id`, `poll_answer_poll_id`, `my_chat_member_updated_id`, `chat_member_updated_id` )
354360 VALUES
355- (:id, :chat_id, :message_id, :edited_message_id, :channel_post_id, :edited_channel_post_id, :inline_query_id, :chosen_inline_result_id, :callback_query_id, :shipping_query_id, :pre_checkout_query_id, :poll_id, :poll_answer_poll_id)
361+ (:id, :chat_id, :message_id, :edited_message_id, :channel_post_id, :edited_channel_post_id, :inline_query_id, :chosen_inline_result_id, :callback_query_id, :shipping_query_id, :pre_checkout_query_id, :poll_id, :poll_answer_poll_id, :my_chat_member_updated_id, :chat_member_updated_id )
356362 ' );
357363
358364 $ sth ->bindValue (':id ' , $ update_id );
@@ -368,6 +374,8 @@ protected static function insertTelegramUpdate(
368374 $ sth ->bindValue (':pre_checkout_query_id ' , $ pre_checkout_query_id );
369375 $ sth ->bindValue (':poll_id ' , $ poll_id );
370376 $ sth ->bindValue (':poll_answer_poll_id ' , $ poll_answer_poll_id );
377+ $ sth ->bindValue (':my_chat_member_updated_id ' , $ my_chat_member_updated_id );
378+ $ sth ->bindValue (':chat_member_updated_id ' , $ chat_member_updated_id );
371379
372380 return $ sth ->execute ();
373381 } catch (PDOException $ e ) {
@@ -520,18 +528,20 @@ public static function insertRequest(Update $update): bool
520528 return false ;
521529 }
522530
523- $ chat_id = null ;
524- $ message_id = null ;
525- $ edited_message_id = null ;
526- $ channel_post_id = null ;
527- $ edited_channel_post_id = null ;
528- $ inline_query_id = null ;
529- $ chosen_inline_result_id = null ;
530- $ callback_query_id = null ;
531- $ shipping_query_id = null ;
532- $ pre_checkout_query_id = null ;
533- $ poll_id = null ;
534- $ poll_answer_poll_id = null ;
531+ $ chat_id = null ;
532+ $ message_id = null ;
533+ $ edited_message_id = null ;
534+ $ channel_post_id = null ;
535+ $ edited_channel_post_id = null ;
536+ $ inline_query_id = null ;
537+ $ chosen_inline_result_id = null ;
538+ $ callback_query_id = null ;
539+ $ shipping_query_id = null ;
540+ $ pre_checkout_query_id = null ;
541+ $ poll_id = null ;
542+ $ poll_answer_poll_id = null ;
543+ $ my_chat_member_updated_id = null ;
544+ $ chat_member_updated_id = null ;
535545
536546 if (($ message = $ update ->getMessage ()) && self ::insertMessageRequest ($ message )) {
537547 $ chat_id = $ message ->getChat ()->getId ();
@@ -559,6 +569,10 @@ public static function insertRequest(Update $update): bool
559569 $ poll_id = $ poll ->getId ();
560570 } elseif (($ poll_answer = $ update ->getPollAnswer ()) && self ::insertPollAnswerRequest ($ poll_answer )) {
561571 $ poll_answer_poll_id = $ poll_answer ->getPollId ();
572+ } elseif (($ my_chat_member = $ update ->getMyChatMember ()) && self ::insertChatMemberUpdatedRequest ($ my_chat_member )) {
573+ $ my_chat_member_updated_id = self ::$ pdo ->lastInsertId ();
574+ } elseif (($ chat_member = $ update ->getChatMember ()) && self ::insertChatMemberUpdatedRequest ($ chat_member )) {
575+ $ chat_member_updated_id = self ::$ pdo ->lastInsertId ();
562576 } else {
563577 return false ;
564578 }
@@ -576,7 +590,9 @@ public static function insertRequest(Update $update): bool
576590 $ shipping_query_id ,
577591 $ pre_checkout_query_id ,
578592 $ poll_id ,
579- $ poll_answer_poll_id
593+ $ poll_answer_poll_id ,
594+ $ my_chat_member_updated_id ,
595+ $ chat_member_updated_id
580596 );
581597 }
582598
@@ -918,6 +934,55 @@ public static function insertPollAnswerRequest(PollAnswer $poll_answer): bool
918934 }
919935 }
920936
937+ /**
938+ * Insert chat member updated request into database
939+ *
940+ * @param ChatMemberUpdated $chat_member_updated
941+ *
942+ * @return bool If the insert was successful
943+ * @throws TelegramException
944+ */
945+ public static function insertChatMemberUpdatedRequest (ChatMemberUpdated $ chat_member_updated ): bool
946+ {
947+ if (!self ::isDbConnected ()) {
948+ return false ;
949+ }
950+
951+ try {
952+ $ sth = self ::$ pdo ->prepare ('
953+ INSERT INTO ` ' . TB_CHAT_MEMBER_UPDATED . '`
954+ (`chat_id`, `user_id`, `date`, `old_chat_member`, `new_chat_member`, `invite_link`, `created_at`)
955+ VALUES
956+ (:chat_id, :user_id, :date, :old_chat_member, :new_chat_member, :invite_link, :created_at)
957+ ' );
958+
959+ $ date = self ::getTimestamp ();
960+ $ chat_id = null ;
961+ $ user_id = null ;
962+
963+ if ($ chat = $ chat_member_updated ->getChat ()) {
964+ $ chat_id = $ chat ->getId ();
965+ self ::insertChat ($ chat , $ date );
966+ }
967+ if ($ user = $ chat_member_updated ->getFrom ()) {
968+ $ user_id = $ user ->getId ();
969+ self ::insertUser ($ user , $ date );
970+ }
971+
972+ $ sth ->bindValue (':chat_id ' , $ chat_id );
973+ $ sth ->bindValue (':user_id ' , $ user_id );
974+ $ sth ->bindValue (':date ' , self ::getTimestamp ($ chat_member_updated ->getDate ()));
975+ $ sth ->bindValue (':old_chat_member ' , $ chat_member_updated ->getOldChatMember ());
976+ $ sth ->bindValue (':new_chat_member ' , $ chat_member_updated ->getNewChatMember ());
977+ $ sth ->bindValue (':invite_link ' , $ chat_member_updated ->getInviteLink ());
978+ $ sth ->bindValue (':created_at ' , $ date );
979+
980+ return $ sth ->execute ();
981+ } catch (PDOException $ e ) {
982+ throw new TelegramException ($ e ->getMessage ());
983+ }
984+ }
985+
921986 /**
922987 * Insert Message request in db
923988 *
@@ -998,17 +1063,19 @@ public static function insertMessageRequest(Message $message): bool
9981063 `audio`, `document`, `animation`, `game`, `photo`, `sticker`, `video`, `voice`, `video_note`, `caption`, `contact`,
9991064 `location`, `venue`, `poll`, `dice`, `new_chat_members`, `left_chat_member`,
10001065 `new_chat_title`, `new_chat_photo`, `delete_chat_photo`, `group_chat_created`,
1001- `supergroup_chat_created`, `channel_chat_created`, `migrate_to_chat_id`, `migrate_from_chat_id`,
1002- `pinned_message`, `invoice`, `successful_payment`, `connected_website`, `passport_data`, `proximity_alert_triggered`, `reply_markup`
1066+ `supergroup_chat_created`, `channel_chat_created`, `message_auto_delete_timer_changed`, `migrate_to_chat_id`, `migrate_from_chat_id`,
1067+ `pinned_message`, `invoice`, `successful_payment`, `connected_website`, `passport_data`, `proximity_alert_triggered`,
1068+ `voice_chat_started`, `voice_chat_ended`, `voice_chat_participants_invited`, `reply_markup`
10031069 ) VALUES (
10041070 :message_id, :user_id, :chat_id, :sender_chat_id, :date, :forward_from, :forward_from_chat, :forward_from_message_id,
10051071 :forward_signature, :forward_sender_name, :forward_date,
10061072 :reply_to_chat, :reply_to_message, :via_bot, :edit_date, :media_group_id, :author_signature, :text, :entities, :caption_entities,
10071073 :audio, :document, :animation, :game, :photo, :sticker, :video, :voice, :video_note, :caption, :contact,
10081074 :location, :venue, :poll, :dice, :new_chat_members, :left_chat_member,
10091075 :new_chat_title, :new_chat_photo, :delete_chat_photo, :group_chat_created,
1010- :supergroup_chat_created, :channel_chat_created, :migrate_to_chat_id, :migrate_from_chat_id,
1011- :pinned_message, :invoice, :successful_payment, :connected_website, :passport_data, :proximity_alert_triggered, :reply_markup
1076+ :supergroup_chat_created, :channel_chat_created, :message_auto_delete_timer_changed, :migrate_to_chat_id, :migrate_from_chat_id,
1077+ :pinned_message, :invoice, :successful_payment, :connected_website, :passport_data, :proximity_alert_triggered,
1078+ :voice_chat_started, :voice_chat_ended, :voice_chat_participants_invited, :reply_markup
10121079 )
10131080 ' );
10141081
@@ -1043,7 +1110,7 @@ public static function insertMessageRequest(Message $message): bool
10431110 $ sth ->bindValue (':reply_to_message ' , $ reply_to_message_id );
10441111
10451112 $ sth ->bindValue (':via_bot ' , $ via_bot_id );
1046- $ sth ->bindValue (':edit_date ' , $ message ->getEditDate ());
1113+ $ sth ->bindValue (':edit_date ' , self :: getTimestamp ( $ message ->getEditDate () ));
10471114 $ sth ->bindValue (':media_group_id ' , $ message ->getMediaGroupId ());
10481115 $ sth ->bindValue (':author_signature ' , $ message ->getAuthorSignature ());
10491116 $ sth ->bindValue (':text ' , $ message ->getText ());
@@ -1072,6 +1139,7 @@ public static function insertMessageRequest(Message $message): bool
10721139 $ sth ->bindValue (':group_chat_created ' , $ message ->getGroupChatCreated ());
10731140 $ sth ->bindValue (':supergroup_chat_created ' , $ message ->getSupergroupChatCreated ());
10741141 $ sth ->bindValue (':channel_chat_created ' , $ message ->getChannelChatCreated ());
1142+ $ sth ->bindValue (':message_auto_delete_timer_changed ' , $ message ->getMessageAutoDeleteTimerChanged ());
10751143 $ sth ->bindValue (':migrate_to_chat_id ' , $ message ->getMigrateToChatId ());
10761144 $ sth ->bindValue (':migrate_from_chat_id ' , $ message ->getMigrateFromChatId ());
10771145 $ sth ->bindValue (':pinned_message ' , $ message ->getPinnedMessage ());
@@ -1080,6 +1148,9 @@ public static function insertMessageRequest(Message $message): bool
10801148 $ sth ->bindValue (':connected_website ' , $ message ->getConnectedWebsite ());
10811149 $ sth ->bindValue (':passport_data ' , $ message ->getPassportData ());
10821150 $ sth ->bindValue (':proximity_alert_triggered ' , $ message ->getProximityAlertTriggered ());
1151+ $ sth ->bindValue (':voice_chat_started ' , $ message ->getVoiceChatStarted ());
1152+ $ sth ->bindValue (':voice_chat_ended ' , $ message ->getVoiceChatEnded ());
1153+ $ sth ->bindValue (':voice_chat_participants_invited ' , $ message ->getVoiceChatParticipantsInvited ());
10831154 $ sth ->bindValue (':reply_markup ' , $ message ->getReplyMarkup ());
10841155
10851156 return $ sth ->execute ();
0 commit comments