Update files
This commit is contained in:
parent
af063ecc7d
commit
cd7930699d
|
|
@ -106,13 +106,15 @@ const handleCommand = async (message) => {
|
|||
}
|
||||
}
|
||||
|
||||
// Использовать web_app с правильным URL миниаппа
|
||||
const miniappUrl = 'https://nakama.glpshchn.ru/';
|
||||
await sendMessage(chatId, startMessage, {
|
||||
reply_markup: {
|
||||
inline_keyboard: [[
|
||||
{
|
||||
text: '🚀 Открыть Nakama',
|
||||
web_app: {
|
||||
url: `https://t.me/${botUsername}`
|
||||
url: miniappUrl
|
||||
}
|
||||
}
|
||||
]]
|
||||
|
|
@ -153,6 +155,28 @@ const pollUpdates = async () => {
|
|||
isPolling = true;
|
||||
log('info', 'Основной бот запущен, опрос обновлений...');
|
||||
|
||||
// При первом запуске получить все обновления и установить offset на последний,
|
||||
// чтобы не отвечать на старые команды
|
||||
const initializeOffset = async () => {
|
||||
try {
|
||||
const response = await axios.get(`${TELEGRAM_API}/getUpdates`, {
|
||||
params: {
|
||||
timeout: 1,
|
||||
allowed_updates: ['message']
|
||||
}
|
||||
});
|
||||
|
||||
const updates = response.data.result || [];
|
||||
if (updates.length > 0) {
|
||||
// Установить offset на последний update_id + 1, чтобы пропустить все старые обновления
|
||||
offset = updates[updates.length - 1].update_id + 1;
|
||||
log('info', `Пропущено ${updates.length} старых обновлений, offset установлен на ${offset}`);
|
||||
}
|
||||
} catch (error) {
|
||||
log('warn', 'Не удалось инициализировать offset, начнем с 0', { error: error.message });
|
||||
}
|
||||
};
|
||||
|
||||
const poll = async () => {
|
||||
try {
|
||||
const response = await axios.get(`${TELEGRAM_API}/getUpdates`, {
|
||||
|
|
@ -179,7 +203,10 @@ const pollUpdates = async () => {
|
|||
}
|
||||
};
|
||||
|
||||
// Сначала инициализировать offset, затем начать опрос
|
||||
initializeOffset().then(() => {
|
||||
poll();
|
||||
});
|
||||
};
|
||||
|
||||
const startMainBot = () => {
|
||||
|
|
|
|||
|
|
@ -72,9 +72,21 @@ function AppContent() {
|
|||
// Запустить проверку initData только после успешной загрузки
|
||||
startInitDataChecker()
|
||||
|
||||
if (!startParamProcessed.current && tg?.startParam?.startsWith('post_')) {
|
||||
// Обработка start_param для открытия конкретного поста
|
||||
// startParam может быть в разных местах в зависимости от способа открытия
|
||||
const startParam = tg?.startParam || tg?.initDataUnsafe?.start_param || tg?.initDataUnsafe?.startParam
|
||||
|
||||
console.log('[App] Проверка start_param:', {
|
||||
startParam: tg?.startParam,
|
||||
initDataUnsafe_start_param: tg?.initDataUnsafe?.start_param,
|
||||
initDataUnsafe_startParam: tg?.initDataUnsafe?.startParam,
|
||||
final: startParam
|
||||
})
|
||||
|
||||
if (!startParamProcessed.current && startParam?.startsWith('post_')) {
|
||||
startParamProcessed.current = true
|
||||
const postId = tg.startParam.replace('post_', '')
|
||||
const postId = startParam.replace('post_', '')
|
||||
console.log('[App] Открытие поста из start_param:', postId)
|
||||
setTimeout(() => {
|
||||
navigate(`/feed?post=${postId}`, { replace: true })
|
||||
}, 200)
|
||||
|
|
|
|||
|
|
@ -122,6 +122,7 @@ export default function PostCard({ post, currentUser, onUpdate }) {
|
|||
const botName = import.meta.env.VITE_TELEGRAM_BOT_NAME || 'NakamaSpaceBot'
|
||||
|
||||
// Создать deeplink для открытия поста в миниапп
|
||||
// Используем startapp для миниаппов - это правильный формат для передачи параметра в миниапп
|
||||
const deeplink = `https://t.me/${botName}?startapp=post_${post._id}`
|
||||
|
||||
// Открыть нативное окно "Поделиться" в Telegram
|
||||
|
|
@ -184,19 +185,6 @@ export default function PostCard({ post, currentUser, onUpdate }) {
|
|||
<img src={images[currentImageIndex]} alt={`Image ${currentImageIndex + 1}`} />
|
||||
|
||||
{images.length > 1 && (
|
||||
<>
|
||||
{currentImageIndex > 0 && (
|
||||
<button className="carousel-btn prev" onClick={(e) => { e.stopPropagation(); setCurrentImageIndex(currentImageIndex - 1); }}>
|
||||
<ChevronLeft size={24} />
|
||||
</button>
|
||||
)}
|
||||
|
||||
{currentImageIndex < images.length - 1 && (
|
||||
<button className="carousel-btn next" onClick={(e) => { e.stopPropagation(); setCurrentImageIndex(currentImageIndex + 1); }}>
|
||||
<ChevronRight size={24} />
|
||||
</button>
|
||||
)}
|
||||
|
||||
<div className="carousel-dots">
|
||||
{images.map((_, index) => (
|
||||
<span
|
||||
|
|
@ -206,7 +194,6 @@ export default function PostCard({ post, currentUser, onUpdate }) {
|
|||
/>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Индикатор что можно открыть fullview */}
|
||||
|
|
|
|||
Loading…
Reference in New Issue