import { Markup, session, Telegraf } from "telegraf"; import { message } from…
- User
import { Markup, session, Telegraf } from "telegraf"; import { message } from "telegraf/filters"; import { Context } from "telegraf"; import { button } from "telegraf/markup"; import getTest, { getHundredMl } from "./sanity"; import getFourMl from "./sanity"; import getFiveMl from "./sanity"; interface MyContext extends Context { myProp?: string; myOtherProp?: number; sesstion: { currantPage50: number; }; }
const BOT_TOKEN = "7675148055:AAGBJcZ9bFfTW6fDF2r1CYxztTbmOyxzcGM"; const chatId = "-1002398010281"; const bot = new Telegraf(BOT_TOKEN); let currentPage = 0; bot.use(session()); bot.start((ctx) => { ctx.reply("Привет, добро пожаловать в мой магазин, что хотите выбрать?", { ...Markup.inlineKeyboard([ Markup.button.callback("100мл", "100"), Markup.button.callback("50мл", "50"), Markup.button.url("Go to profile", "https://t.me/konoshevskiy95"), ]), }); });
bot.action("50", async (ctx) => { const fourMlArray = await getFiveMl(); currentPage = 0; ctx.replyWithPhoto(
${fourMlArray[currentPage].image.url}, { caption:${fourMlArray[currentPage].name}\n${fourMlArray[currentPage].description}, reply_markup: { inline_keyboard: [ [ { text: "⬅️", callback_data: "Prev50" }, { text: "➡️", callback_data: "Next50" }, ], [{ text: "Связаться 💬", callback_data: "answer50" }], ], }, }); });bot.action("Next50", async (ctx) => { const fourMlArray = await getFiveMl(); if (currentPage + 1 <= fourMlArray.length - 1) { currentPage += 1; ctx.replyWithPhoto(
${fourMlArray[currentPage].image.url}, { caption:${fourMlArray[currentPage].name}\n${fourMlArray[currentPage].description}, reply_markup: { inline_keyboard: [ [ { text: "⬅️", callback_data: "Prev50" }, { text: "➡️", callback_data: "Next50" }, ], [{ text: "Связаться 💬", callback_data: "answer50" }], ], }, }); } else { currentPage = 0; ctx.replyWithPhoto(${fourMlArray[currentPage].image.url}, { caption:${fourMlArray[currentPage].name}\n${fourMlArray[currentPage].description}, reply_markup: { inline_keyboard: [ [ { text: "⬅️", callback_data: "Prev50" }, { text: "➡️", callback_data: "Next50" }, ], [{ text: "Связаться 💬", callback_data: "answer50" }], ], }, }); } });bot.action("Prev50", async (ctx) => { const fourMlArray = await getFiveMl(); if (currentPage - 1 >= 0) { currentPage -= 1; ctx.replyWithPhoto(
${fourMlArray[currentPage].image.url}, { caption:${fourMlArray[currentPage].name}\n${fourMlArray[currentPage].description}, reply_markup: { inline_keyboard: [ [ { text: "⬅️", callback_data: "Prev50" }, { text: "➡️", callback_data: "Next50" }, ], [{ text: "Связаться 💬", callback_data: "answer50" }], ], }, }); } else { currentPage = fourMlArray.length - 1; ctx.replyWithPhoto(${fourMlArray[currentPage].image.url}, { caption:${fourMlArray[currentPage].name}\n${fourMlArray[currentPage].description}, reply_markup: { inline_keyboard: [ [ { text: "⬅️", callback_data: "Prev50" }, { text: "➡️", callback_data: "Next50" }, ], [{ text: "Связаться 💬", callback_data: "answer50" }], ], }, }); } }); - Assistant
- User
Cannot set properties of undefined (setting 'currentPage50')
- Assistant
- User
Argument of type 'MiddlewareFn<Context & { [key in P]?: C[P] | undefined; }>' is not assignable to parameter of type 'Middleware'. Type 'MiddlewareFn<Context & { [key in P]?: C[P] | undefined; }>' is not assignable to type 'MiddlewareFn<MyContext, Update>'. Type 'MyContext' is not assignable to type 'Context & { [key in P]?: C[P] | undefined; }'. Type 'MyContext' is not assignable to type '{ [key in P]?: C[P] | undefined; }'.ts(2345)
- Assistant