Skip to content

Commit e64d97b

Browse files
Store chat join requests in database for better tracking and processing
1 parent efb5c7c commit e64d97b

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

src/routes/telegram.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,39 @@ telegram.post('/webhook', async (c) => {
128128
date: new Date(joinRequest.date * 1000).toISOString()
129129
});
130130

131+
// Store the join request in all_messages_groups table
132+
try {
133+
const db = new D1DatabaseConnection(c.env.DB);
134+
const groupMessagesCrud = new AllMessagesGroupsCrud(db);
135+
136+
// Create a message-like structure for the join request
137+
const joinRequestMessage = {
138+
chat: joinRequest.chat,
139+
from: joinRequest.from,
140+
date: joinRequest.date,
141+
user_chat_id: joinRequest.user_chat_id,
142+
bio: joinRequest.bio,
143+
invite_link: joinRequest.invite_link,
144+
// Mark this as a join request
145+
message_type: 'chat_join_request'
146+
};
147+
148+
await groupMessagesCrud.storeMessage(
149+
joinRequestMessage,
150+
`Join request from ${firstName} ${lastName || ''} (@${username || 'no_username'})`
151+
);
152+
153+
console.log('Stored chat join request in database');
154+
} catch (storageError) {
155+
console.error('Failed to store chat join request:', storageError);
156+
}
157+
131158
// You can add your custom logic here to:
132159
// 1. Automatically approve/decline the request
133160
// 2. Check if user is in member sheets
134161
// 3. Send notification to admins
135-
// 4. Store the request for later processing
162+
// 4. Process the request based on your business logic
136163

137-
// Example: Log the request (you can extend this with your own logic)
138164
const telegramService = new TelegramService(c.env);
139165

140166
// Optionally approve the request automatically

0 commit comments

Comments
 (0)