fix: telegram callback_data <64 bytes (BUTTON_DATA_INVALID) — recipe uuid only, resolve draft by chat; send before status update
This commit is contained in:
+18
-11
@@ -92,14 +92,17 @@ export async function sweepDrafts(): Promise<void> {
|
||||
for (const d of drafts) {
|
||||
const recipes = await query<any>('SELECT id, name FROM recipes ORDER BY is_default DESC, name LIMIT 8');
|
||||
const kb = new InlineKeyboard();
|
||||
recipes.forEach((r, i) => { kb.text(r.name, `r:${r.id}:${d.id}`); if (i % 2 === 1) kb.row(); });
|
||||
// Callback-Daten <64 Bytes: nur Rezept-UUID; der Draft wird beim Klick über den Chat gefunden.
|
||||
recipes.forEach((r, i) => { kb.text(r.name, `r:${r.id}`); if (i % 2 === 1) kb.row(); });
|
||||
const n = (d.file_refs || []).length;
|
||||
const compressed = (d.file_refs || []).some((f: any) => f.quality === 'compressed');
|
||||
await query(`UPDATE telegram_drafts SET status='awaiting_recipe' WHERE id=$1`, [d.id]);
|
||||
await b.api.sendMessage(d.chat_id,
|
||||
`${n} Bild${n > 1 ? 'er' : ''} empfangen. Welches Rezept?` +
|
||||
(compressed ? '\n⚠️ Als Foto gesendet (komprimiert). Für volle Qualität als *Datei* senden.' : ''),
|
||||
{ reply_markup: kb, parse_mode: 'Markdown' });
|
||||
try {
|
||||
await b.api.sendMessage(d.chat_id,
|
||||
`${n} Bild${n > 1 ? 'er' : ''} empfangen. Welches Rezept?` +
|
||||
(compressed ? '\n⚠️ Als Foto gesendet (komprimiert). Für volle Qualität als *Datei* senden.' : ''),
|
||||
{ reply_markup: kb, parse_mode: 'Markdown' });
|
||||
await query(`UPDATE telegram_drafts SET status='awaiting_recipe' WHERE id=$1`, [d.id]);
|
||||
} catch (e) { console.error('[telegram] sweep send:', e); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,15 +227,19 @@ function register(b: Bot) {
|
||||
});
|
||||
|
||||
b.on('callback_query:data', async (ctx) => {
|
||||
const [kind, a, bId] = ctx.callbackQuery.data.split(':');
|
||||
const [kind, recipeId] = ctx.callbackQuery.data.split(':');
|
||||
await ctx.answerCallbackQuery();
|
||||
if (kind === 'd') { // Standard-Rezept setzen
|
||||
await query(`UPDATE telegram_links SET default_recipe_id=$2 WHERE chat_id=$1`, [ctx.chat!.id, a]);
|
||||
await query(`UPDATE telegram_links SET default_recipe_id=$2 WHERE chat_id=$1`, [ctx.chat!.id, recipeId]);
|
||||
return ctx.editMessageText('Standard-Rezept gesetzt.');
|
||||
}
|
||||
if (kind === 'r') { // Rezept für Draft gewählt
|
||||
await ctx.editMessageText('Alles klar.');
|
||||
const b2 = await getBot(); if (b2) await dispatchDraft(ctx.chat!.id, bId, a, b2);
|
||||
if (kind === 'r') { // Rezept gewählt → offenen Draft dieses Chats verarbeiten
|
||||
const draft = await one<{ id: string }>(
|
||||
`SELECT id FROM telegram_drafts WHERE chat_id=$1 AND status='awaiting_recipe'
|
||||
ORDER BY last_received_at DESC LIMIT 1`, [ctx.chat!.id]);
|
||||
if (!draft) return ctx.editMessageText('Kein offener Bild-Stapel gefunden — bitte Bilder neu senden.');
|
||||
await ctx.editMessageText('Alles klar, los geht’s.');
|
||||
const b2 = await getBot(); if (b2) await dispatchDraft(ctx.chat!.id, draft.id, recipeId, b2);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user