Fix JSON format issues with photos and add multi-photo gallery support

This commit is contained in:
2025-09-18 10:38:29 +09:00
parent bdd7d0424f
commit e275a9856b
13 changed files with 953 additions and 77 deletions

View File

@@ -0,0 +1,76 @@
import TelegramBot from 'node-telegram-bot-api';
import { ProfileService } from '../services/profileService';
import { MatchingService } from '../services/matchingService';
export class LikeBackHandler {
private bot: TelegramBot;
private profileService: ProfileService;
private matchingService: MatchingService;
constructor(bot: TelegramBot) {
this.bot = bot;
this.profileService = new ProfileService();
this.matchingService = new MatchingService();
}
// Функция для обработки обратного лайка из уведомления
async handleLikeBack(chatId: number, telegramId: string, targetUserId: string): Promise<void> {
try {
// Получаем информацию о пользователях
const [userId, targetProfile] = await Promise.all([
this.profileService.getUserIdByTelegramId(telegramId),
this.profileService.getProfileByUserId(targetUserId)
]);
if (!userId || !targetProfile) {
await this.bot.sendMessage(chatId, '❌ Не удалось найти профиль');
return;
}
// Проверяем, есть ли уже свайп
const existingSwipe = await this.matchingService.getSwipeBetweenUsers(userId, targetUserId);
if (existingSwipe) {
await this.bot.sendMessage(chatId, '❓ Вы уже оценили этот профиль ранее.');
return;
}
// Создаем свайп (лайк)
const result = await this.matchingService.createSwipe(userId, targetUserId, 'like');
if (result.isMatch) {
// Это матч!
await this.bot.sendMessage(
chatId,
'🎉 *Поздравляем! Это взаимно!*\n\n' +
`Вы и *${targetProfile.name}* понравились друг другу!\n` +
'Теперь вы можете начать общение.',
{
parse_mode: 'Markdown',
reply_markup: {
inline_keyboard: [
[{ text: '💬 Начать общение', callback_data: `start_chat:${targetUserId}` }],
[{ text: '👀 Посмотреть профиль', callback_data: `view_profile:${targetUserId}` }]
]
}
}
);
} else {
await this.bot.sendMessage(
chatId,
'❤️ Вам понравился профиль ' + targetProfile.name + '!\n\n' +
'Если вы также понравитесь этому пользователю, будет создан матч.',
{
reply_markup: {
inline_keyboard: [
[{ text: '🔍 Продолжить поиск', callback_data: 'start_browsing' }]
]
}
}
);
}
} catch (error) {
console.error('Error in handleLikeBack:', error);
await this.bot.sendMessage(chatId, '❌ Произошла ошибка при обработке лайка');
}
}
}