@@ -348,7 +348,8 @@ protected static function insertTelegramUpdate(
348348 ?string $ poll_id = null ,
349349 ?string $ poll_answer_poll_id = null ,
350350 ?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
352353 ): ?bool {
353354 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 ) {
354355 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(
361362 try {
362363 $ sth = self ::$ pdo ->prepare ('
363364 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+ )
367378 ' );
368379
369380 $ sth ->bindValue (':id ' , $ update_id );
@@ -381,6 +392,7 @@ protected static function insertTelegramUpdate(
381392 $ sth ->bindValue (':poll_answer_poll_id ' , $ poll_answer_poll_id );
382393 $ sth ->bindValue (':my_chat_member_updated_id ' , $ my_chat_member_updated_id );
383394 $ sth ->bindValue (':chat_member_updated_id ' , $ chat_member_updated_id );
395+ $ sth ->bindValue (':chat_join_request_id ' , $ chat_join_request_id );
384396
385397 return $ sth ->execute ();
386398 } catch (PDOException $ e ) {
@@ -547,6 +559,7 @@ public static function insertRequest(Update $update): bool
547559 $ poll_answer_poll_id = null ;
548560 $ my_chat_member_updated_id = null ;
549561 $ chat_member_updated_id = null ;
562+ $ chat_join_request_id = null ;
550563
551564 if (($ message = $ update ->getMessage ()) && self ::insertMessageRequest ($ message )) {
552565 $ chat_id = $ message ->getChat ()->getId ();
@@ -578,6 +591,8 @@ public static function insertRequest(Update $update): bool
578591 $ my_chat_member_updated_id = self ::$ pdo ->lastInsertId ();
579592 } elseif (($ chat_member = $ update ->getChatMember ()) && self ::insertChatMemberUpdatedRequest ($ chat_member )) {
580593 $ 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 ();
581596 } else {
582597 return false ;
583598 }
@@ -597,7 +612,8 @@ public static function insertRequest(Update $update): bool
597612 $ poll_id ,
598613 $ poll_answer_poll_id ,
599614 $ my_chat_member_updated_id ,
600- $ chat_member_updated_id
615+ $ chat_member_updated_id ,
616+ $ chat_join_request_id
601617 );
602618 }
603619
@@ -989,6 +1005,54 @@ public static function insertChatMemberUpdatedRequest(ChatMemberUpdated $chat_me
9891005 }
9901006 }
9911007
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+
9921056 /**
9931057 * Insert Message request in db
9941058 *
0 commit comments