Я пытаюсь создать множество сцен с помощью встроенной клавиатуры и возможностью перехода от одной сцены к другой после выбора опции.
У меня возникла ошибка с экзаменом.
>Ошибка: свойство «examId» не существует для типа «SceneSession».ts(2339)
Единственное свойство сеанса — __сцены
import { Telegraf, Scenes, session, Context, Markup } from 'telegraf';
// Define scene constants
const SCENES = {
EXAMS: 'exams-scene',
YEARS: 'years-scene',
} as const;
// Extend SceneSessionData to include custom fields
interface MySessionData extends Scenes.SceneSessionData {
examId?: number;
year?: string;
subject?: string;
paper?: string;
currentPage?: number;
lastActivity?: number;
}
interface MyContext extends Scenes.SceneContext {
session: Scenes.SceneSession;
scene: Scenes.SceneContextScene;
}
// Initialize scenes
const examsScene = new Scenes.BaseScene(SCENES.EXAMS);
const yearsScene = new Scenes.BaseScene(SCENES.YEARS);
// Exam selection scene
examsScene.enter(async (ctx) => {
const exams = [
{ id: 1, title: 'GCE O-Level' },
{ id: 2, title: 'GCE A-Level, BACALUREATE' },
{ id: 3, title: 'IGCSE' },
{ id: 4, title: 'SAT' },
];
const keyboard = Markup.inlineKeyboard([
...exams.map((exam) => [
Markup.button.callback(exam.title, `select_exam:${exam.id}`),
]),
[Markup.button.callback('« Main Menu', 'main_menu')],
]);
await ctx.reply('Select an exam:', keyboard);
});
// Handle exam selection
examsScene.action(/^select_exam:(\d+)$/, async (ctx) => {
ctx.session.examId = parseInt(ctx.match[1], 10); // Store examId in the session
await ctx.reply(`You selected exam ID: ${ctx.session.examId}`);
await ctx.scene.enter(SCENES.YEARS); // Proceed to the next scene
});
Подробнее здесь: https://stackoverflow.com/questions/793 ... typescript
Как исправить проблемы с ctx при переходе сцен в Telegraf и машинописном тексте? ⇐ Javascript
Форум по Javascript
1737392502
Anonymous
Я пытаюсь создать множество сцен с помощью встроенной клавиатуры и возможностью перехода от одной сцены к другой после выбора опции.
У меня возникла ошибка с экзаменом.
>Ошибка: свойство «examId» не существует для типа «SceneSession».ts(2339)
Единственное свойство сеанса — __сцены
import { Telegraf, Scenes, session, Context, Markup } from 'telegraf';
// Define scene constants
const SCENES = {
EXAMS: 'exams-scene',
YEARS: 'years-scene',
} as const;
// Extend SceneSessionData to include custom fields
interface MySessionData extends Scenes.SceneSessionData {
examId?: number;
year?: string;
subject?: string;
paper?: string;
currentPage?: number;
lastActivity?: number;
}
interface MyContext extends Scenes.SceneContext {
session: Scenes.SceneSession;
scene: Scenes.SceneContextScene;
}
// Initialize scenes
const examsScene = new Scenes.BaseScene(SCENES.EXAMS);
const yearsScene = new Scenes.BaseScene(SCENES.YEARS);
// Exam selection scene
examsScene.enter(async (ctx) => {
const exams = [
{ id: 1, title: 'GCE O-Level' },
{ id: 2, title: 'GCE A-Level, BACALUREATE' },
{ id: 3, title: 'IGCSE' },
{ id: 4, title: 'SAT' },
];
const keyboard = Markup.inlineKeyboard([
...exams.map((exam) => [
Markup.button.callback(exam.title, `select_exam:${exam.id}`),
]),
[Markup.button.callback('« Main Menu', 'main_menu')],
]);
await ctx.reply('Select an exam:', keyboard);
});
// Handle exam selection
examsScene.action(/^select_exam:(\d+)$/, async (ctx) => {
ctx.session.examId = parseInt(ctx.match[1], 10); // Store examId in the session
await ctx.reply(`You selected exam ID: ${ctx.session.examId}`);
await ctx.scene.enter(SCENES.YEARS); // Proceed to the next scene
});
Подробнее здесь: [url]https://stackoverflow.com/questions/79372113/how-to-fix-issues-with-ctx-when-transitioning-scenes-in-telegraf-and-typescript[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия