14
14
15
15
use Longman \TelegramBot \Entities \CallbackQuery ;
16
16
use Longman \TelegramBot \Entities \Chat ;
17
+ use Longman \TelegramBot \Entities \ChatMemberUpdated ;
17
18
use Longman \TelegramBot \Entities \ChosenInlineResult ;
18
19
use Longman \TelegramBot \Entities \InlineQuery ;
19
20
use Longman \TelegramBot \Entities \Message ;
@@ -140,13 +141,14 @@ protected static function defineTables(): void
140
141
$ tables = [
141
142
'callback_query ' ,
142
143
'chat ' ,
144
+ 'chat_member_updated ' ,
143
145
'chosen_inline_result ' ,
144
146
'edited_message ' ,
145
147
'inline_query ' ,
146
148
'message ' ,
147
- 'pre_checkout_query ' ,
148
149
'poll ' ,
149
150
'poll_answer ' ,
151
+ 'pre_checkout_query ' ,
150
152
'request_limiter ' ,
151
153
'shipping_query ' ,
152
154
'telegram_update ' ,
@@ -320,6 +322,8 @@ public static function entitiesArrayToJson(array $entities, $default = null)
320
322
* @param string|null $pre_checkout_query_id
321
323
* @param string|null $poll_id
322
324
* @param string|null $poll_answer_poll_id
325
+ * @param string|null $my_chat_member_updated_id
326
+ * @param string|null $chat_member_updated_id
323
327
*
324
328
* @return bool If the insert was successful
325
329
* @throws TelegramException
@@ -337,10 +341,12 @@ protected static function insertTelegramUpdate(
337
341
?string $ shipping_query_id = null ,
338
342
?string $ pre_checkout_query_id = null ,
339
343
?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
341
347
): ?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 ' );
344
350
}
345
351
346
352
if (!self ::isDbConnected ()) {
@@ -350,9 +356,9 @@ protected static function insertTelegramUpdate(
350
356
try {
351
357
$ sth = self ::$ pdo ->prepare ('
352
358
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` )
354
360
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 )
356
362
' );
357
363
358
364
$ sth ->bindValue (':id ' , $ update_id );
@@ -368,6 +374,8 @@ protected static function insertTelegramUpdate(
368
374
$ sth ->bindValue (':pre_checkout_query_id ' , $ pre_checkout_query_id );
369
375
$ sth ->bindValue (':poll_id ' , $ poll_id );
370
376
$ 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 );
371
379
372
380
return $ sth ->execute ();
373
381
} catch (PDOException $ e ) {
@@ -520,18 +528,20 @@ public static function insertRequest(Update $update): bool
520
528
return false ;
521
529
}
522
530
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 ;
535
545
536
546
if (($ message = $ update ->getMessage ()) && self ::insertMessageRequest ($ message )) {
537
547
$ chat_id = $ message ->getChat ()->getId ();
@@ -559,6 +569,10 @@ public static function insertRequest(Update $update): bool
559
569
$ poll_id = $ poll ->getId ();
560
570
} elseif (($ poll_answer = $ update ->getPollAnswer ()) && self ::insertPollAnswerRequest ($ poll_answer )) {
561
571
$ 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 ();
562
576
} else {
563
577
return false ;
564
578
}
@@ -576,7 +590,9 @@ public static function insertRequest(Update $update): bool
576
590
$ shipping_query_id ,
577
591
$ pre_checkout_query_id ,
578
592
$ poll_id ,
579
- $ poll_answer_poll_id
593
+ $ poll_answer_poll_id ,
594
+ $ my_chat_member_updated_id ,
595
+ $ chat_member_updated_id
580
596
);
581
597
}
582
598
@@ -918,6 +934,55 @@ public static function insertPollAnswerRequest(PollAnswer $poll_answer): bool
918
934
}
919
935
}
920
936
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
+
921
986
/**
922
987
* Insert Message request in db
923
988
*
@@ -998,17 +1063,19 @@ public static function insertMessageRequest(Message $message): bool
998
1063
`audio`, `document`, `animation`, `game`, `photo`, `sticker`, `video`, `voice`, `video_note`, `caption`, `contact`,
999
1064
`location`, `venue`, `poll`, `dice`, `new_chat_members`, `left_chat_member`,
1000
1065
`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`
1003
1069
) VALUES (
1004
1070
:message_id, :user_id, :chat_id, :sender_chat_id, :date, :forward_from, :forward_from_chat, :forward_from_message_id,
1005
1071
:forward_signature, :forward_sender_name, :forward_date,
1006
1072
:reply_to_chat, :reply_to_message, :via_bot, :edit_date, :media_group_id, :author_signature, :text, :entities, :caption_entities,
1007
1073
:audio, :document, :animation, :game, :photo, :sticker, :video, :voice, :video_note, :caption, :contact,
1008
1074
:location, :venue, :poll, :dice, :new_chat_members, :left_chat_member,
1009
1075
: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
1012
1079
)
1013
1080
' );
1014
1081
@@ -1043,7 +1110,7 @@ public static function insertMessageRequest(Message $message): bool
1043
1110
$ sth ->bindValue (':reply_to_message ' , $ reply_to_message_id );
1044
1111
1045
1112
$ sth ->bindValue (':via_bot ' , $ via_bot_id );
1046
- $ sth ->bindValue (':edit_date ' , $ message ->getEditDate ());
1113
+ $ sth ->bindValue (':edit_date ' , self :: getTimestamp ( $ message ->getEditDate () ));
1047
1114
$ sth ->bindValue (':media_group_id ' , $ message ->getMediaGroupId ());
1048
1115
$ sth ->bindValue (':author_signature ' , $ message ->getAuthorSignature ());
1049
1116
$ sth ->bindValue (':text ' , $ message ->getText ());
@@ -1072,6 +1139,7 @@ public static function insertMessageRequest(Message $message): bool
1072
1139
$ sth ->bindValue (':group_chat_created ' , $ message ->getGroupChatCreated ());
1073
1140
$ sth ->bindValue (':supergroup_chat_created ' , $ message ->getSupergroupChatCreated ());
1074
1141
$ sth ->bindValue (':channel_chat_created ' , $ message ->getChannelChatCreated ());
1142
+ $ sth ->bindValue (':message_auto_delete_timer_changed ' , $ message ->getMessageAutoDeleteTimerChanged ());
1075
1143
$ sth ->bindValue (':migrate_to_chat_id ' , $ message ->getMigrateToChatId ());
1076
1144
$ sth ->bindValue (':migrate_from_chat_id ' , $ message ->getMigrateFromChatId ());
1077
1145
$ sth ->bindValue (':pinned_message ' , $ message ->getPinnedMessage ());
@@ -1080,6 +1148,9 @@ public static function insertMessageRequest(Message $message): bool
1080
1148
$ sth ->bindValue (':connected_website ' , $ message ->getConnectedWebsite ());
1081
1149
$ sth ->bindValue (':passport_data ' , $ message ->getPassportData ());
1082
1150
$ 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 ());
1083
1154
$ sth ->bindValue (':reply_markup ' , $ message ->getReplyMarkup ());
1084
1155
1085
1156
return $ sth ->execute ();
0 commit comments