@@ -348,7 +348,8 @@ protected static function insertTelegramUpdate(
348
348
?string $ poll_id = null ,
349
349
?string $ poll_answer_poll_id = null ,
350
350
?string $ my_chat_member_updated_id = null ,
351
- ?string $ chat_member_updated_id = null
351
+ ?string $ chat_member_updated_id = null ,
352
+ ?string $ chat_join_request_id = null
352
353
): ?bool {
353
354
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 ) {
354
355
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 ' );
@@ -361,9 +362,19 @@ protected static function insertTelegramUpdate(
361
362
try {
362
363
$ sth = self ::$ pdo ->prepare ('
363
364
INSERT IGNORE INTO ` ' . TB_TELEGRAM_UPDATE . '`
364
- (`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`)
365
- VALUES
366
- (: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)
365
+ (
366
+ `id`, `chat_id`, `message_id`, `edited_message_id`,
367
+ `channel_post_id`, `edited_channel_post_id`, `inline_query_id`, `chosen_inline_result_id`,
368
+ `callback_query_id`, `shipping_query_id`, `pre_checkout_query_id`,
369
+ `poll_id`, `poll_answer_poll_id`, `my_chat_member_updated_id`, `chat_member_updated_id`,
370
+ `chat_join_request_id`
371
+ ) VALUES (
372
+ :id, :chat_id, :message_id, :edited_message_id,
373
+ :channel_post_id, :edited_channel_post_id, :inline_query_id, :chosen_inline_result_id,
374
+ :callback_query_id, :shipping_query_id, :pre_checkout_query_id,
375
+ :poll_id, :poll_answer_poll_id, :my_chat_member_updated_id, :chat_member_updated_id,
376
+ :chat_join_request_id
377
+ )
367
378
' );
368
379
369
380
$ sth ->bindValue (':id ' , $ update_id );
@@ -381,6 +392,7 @@ protected static function insertTelegramUpdate(
381
392
$ sth ->bindValue (':poll_answer_poll_id ' , $ poll_answer_poll_id );
382
393
$ sth ->bindValue (':my_chat_member_updated_id ' , $ my_chat_member_updated_id );
383
394
$ sth ->bindValue (':chat_member_updated_id ' , $ chat_member_updated_id );
395
+ $ sth ->bindValue (':chat_join_request_id ' , $ chat_join_request_id );
384
396
385
397
return $ sth ->execute ();
386
398
} catch (PDOException $ e ) {
@@ -547,6 +559,7 @@ public static function insertRequest(Update $update): bool
547
559
$ poll_answer_poll_id = null ;
548
560
$ my_chat_member_updated_id = null ;
549
561
$ chat_member_updated_id = null ;
562
+ $ chat_join_request_id = null ;
550
563
551
564
if (($ message = $ update ->getMessage ()) && self ::insertMessageRequest ($ message )) {
552
565
$ chat_id = $ message ->getChat ()->getId ();
@@ -578,6 +591,8 @@ public static function insertRequest(Update $update): bool
578
591
$ my_chat_member_updated_id = self ::$ pdo ->lastInsertId ();
579
592
} elseif (($ chat_member = $ update ->getChatMember ()) && self ::insertChatMemberUpdatedRequest ($ chat_member )) {
580
593
$ chat_member_updated_id = self ::$ pdo ->lastInsertId ();
594
+ } elseif (($ chat_join_request = $ update ->getChatJoinRequest ()) && self ::insertChatJoinRequestRequest ($ chat_join_request )) {
595
+ $ chat_join_request_id = self ::$ pdo ->lastInsertId ();
581
596
} else {
582
597
return false ;
583
598
}
@@ -597,7 +612,8 @@ public static function insertRequest(Update $update): bool
597
612
$ poll_id ,
598
613
$ poll_answer_poll_id ,
599
614
$ my_chat_member_updated_id ,
600
- $ chat_member_updated_id
615
+ $ chat_member_updated_id ,
616
+ $ chat_join_request_id
601
617
);
602
618
}
603
619
@@ -989,6 +1005,54 @@ public static function insertChatMemberUpdatedRequest(ChatMemberUpdated $chat_me
989
1005
}
990
1006
}
991
1007
1008
+ /**
1009
+ * Insert chat join request into database
1010
+ *
1011
+ * @param ChatJoinRequest $chat_join_request
1012
+ *
1013
+ * @return bool If the insert was successful
1014
+ * @throws TelegramException
1015
+ */
1016
+ public static function insertChatJoinRequestRequest (ChatJoinRequest $ chat_join_request ): bool
1017
+ {
1018
+ if (!self ::isDbConnected ()) {
1019
+ return false ;
1020
+ }
1021
+
1022
+ try {
1023
+ $ sth = self ::$ pdo ->prepare ('
1024
+ INSERT INTO ` ' . TB_CHAT_MEMBER_UPDATED . '`
1025
+ (`chat_id`, `user_id`, `date`, `bio`, `invite_link`, `created_at`)
1026
+ VALUES
1027
+ (:chat_id, :user_id, :date, :bio, :invite_link, :created_at)
1028
+ ' );
1029
+
1030
+ $ date = self ::getTimestamp ();
1031
+ $ chat_id = null ;
1032
+ $ user_id = null ;
1033
+
1034
+ if ($ chat = $ chat_join_request ->getChat ()) {
1035
+ $ chat_id = $ chat ->getId ();
1036
+ self ::insertChat ($ chat , $ date );
1037
+ }
1038
+ if ($ user = $ chat_join_request ->getFrom ()) {
1039
+ $ user_id = $ user ->getId ();
1040
+ self ::insertUser ($ user , $ date );
1041
+ }
1042
+
1043
+ $ sth ->bindValue (':chat_id ' , $ chat_id );
1044
+ $ sth ->bindValue (':user_id ' , $ user_id );
1045
+ $ sth ->bindValue (':date ' , self ::getTimestamp ($ chat_join_request ->getDate ()));
1046
+ $ sth ->bindValue (':bio ' , $ chat_join_request ->getBio ());
1047
+ $ sth ->bindValue (':invite_link ' , $ chat_join_request ->getInviteLink ());
1048
+ $ sth ->bindValue (':created_at ' , $ date );
1049
+
1050
+ return $ sth ->execute ();
1051
+ } catch (PDOException $ e ) {
1052
+ throw new TelegramException ($ e ->getMessage ());
1053
+ }
1054
+ }
1055
+
992
1056
/**
993
1057
* Insert Message request in db
994
1058
*
0 commit comments