import { Markup, 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;
}
const BOT_TOKEN = "7675148055:AAGBJcZ9bFfTW6fDF2r1CYxztTbmOyxzcGM";
const chatId = "-1002398010281";
const bot = new Telegraf(BOT_TOKEN);
let currentPage = 0;
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" }],
],
},
});
}
});
bot.action("answer50", async (ctx) => {
const fourMlArray = await getFiveMl();
bot.telegram.sendPhoto(chatId, fourMlArray[currentPage].image.url, {
caption: Привет\n@${ctx.from.username}\n${fourMlArray[currentPage].name}\n${fourMlArray[currentPage].description},
});
ctx.reply("С вами скоро свяжутся. Если у вас возникли вопросы", {
...Markup.inlineKeyboard([
Markup.button.url("Обращайтесь сюда", "https://t.me/konoshevskiy95"),
]),
});
});
bot.action("100", async (ctx) => {
const hundMlArray = await getHundredMl();
currentPage = 0;
ctx.replyWithPhoto(${hundMlArray[currentPage].image.url}, {
caption: ${hundMlArray[currentPage].name}\n${hundMlArray[currentPage].description},
reply_markup: {
inline_keyboard: [
[
{ text: "⬅️", callback_data: "Prev100" },
{ text: "➡️", callback_data: "Next100" },
],
[{ text: "Связаться 💬", callback_data: "answer100" }],
],
},
});
});
bot.action("Next100", async (ctx) => {
const hundMlArray = await getHundredMl();
if (currentPage + 1 <= hundMlArray.length - 1) {
currentPage += 1;
ctx.replyWithPhoto(${hundMlArray[currentPage].image.url}, {
caption: ${hundMlArray[currentPage].name}\n${hundMlArray[currentPage].description},
reply_markup: {
inline_keyboard: [
[
{ text: "⬅️", callback_data: "Prev100" },
{ text: "➡️", callback_data: "Next100" },
],
[{ text: "Связаться 💬", callback_data: "answer100" }],
],
},
});
} else {
currentPage = 0;
ctx.replyWithPhoto(${hundMlArray[currentPage].image.url}, {
caption: ${hundMlArray[currentPage].name}\n${hundMlArray[currentPage].description},
reply_markup: {
inline_keyboard: [
[
{ text: "⬅️", callback_data: "Prev100" },
{ text: "➡️", callback_data: "Next100" },
],
[{ text: "Связаться 💬", callback_data: "answer100" }],
],
},
});
}
});
bot.action("Prev100", async (ctx) => {
const hundMlArray = await getHundredMl();
if (currentPage - 1 >= 0) {
currentPage -= 1;
ctx.replyWithPhoto(${hundMlArray[currentPage].image.url}, {
caption: ${hundMlArray[currentPage].name} \n${hundMlArray[currentPage].description},
reply_markup: {
inline_keyboard: [
[
{ text: "⬅️", callback_data: "Prev100" },
{ text: "➡️", callback_data: "Next100" },
],
[{ text: "Связаться 💬", callback_data: "answer100" }],
],
},
});
} else {
currentPage = hundMlArray.length - 1;
ctx.replyWithPhoto(${hundMlArray[currentPage].image.url}, {
caption: ${hundMlArray[currentPage].name}\n${hundMlArray[currentPage].description},
reply_markup: {
inline_keyboard: [
[
{ text: "⬅️", callback_data: "Prev100" },
{ text: "➡️", callback_data: "Next100" },
],
[{ text: "Связаться 💬", callback_data: "answer100" }],
],
},
});
}
});
bot.action("answer100", async (ctx) => {
const hundMlArray = await getHundredMl();
bot.telegram.sendPhoto(chatId, hundMlArray[currentPage].image.url, {
caption: Привет\n@${ctx.from.username}\n${hundMlArray[currentPage].name}\n${hundMlArray[currentPage].description},
});
ctx.reply("С вами скоро свяжутся. Если у вас возникли вопросы", {
...Markup.inlineKeyboard([
Markup.button.url("Обращайтесь сюда", "https://t.me/konoshevskiy95"),
]),
});
});
bot.launch();
if (bot) {
console.log("bot start");
}
process.once("SIGINT", () => bot.stop("SIGINT"));
process.once("SIGTERM", () => bot.stop("SIGTERM"));