grammyjs / grammY

The Telegram Bot Framework.
https://grammy.dev
MIT License
2.04k stars 106 forks source link

Property 'wait' does not exist on type 'ConversationControls'.ts(2339) #568

Closed mikececco closed 2 weeks ago

mikececco commented 2 months ago
import axios from 'axios'
import { Bot, GrammyError, HttpError, Keyboard, Context, session, Middleware } from "grammy";
import { COMMANDS } from './commands/commands';
// import { Menu } from "@grammyjs/menu";
import { parserInstance } from './utils/parser';
import {
  type Conversation,
  type ConversationFlavor,
  conversations,
  createConversation,
} from "@grammyjs/conversations";

const bot = new Bot(import.meta.env.VITE_TELEGRAM_TOKEN || "");
// await bot.init();
bot.use(conversations());
bot.use(createConversation(greeting));
type MyContext = Context & ConversationFlavor;
type MyConversation = Conversation<MyContext>;

const greeting: Middleware<MyContext> = async (ctx) => {
  await ctx.reply("Hi there! What is your name?");
  const { message } = await ctx.conversation.wait();
  if (message) {
    await ctx.reply(`Welcome to the chat, ${message.text}!`);
  }
};

Trying to implement conversations but get errors also on bot.use(conversations()); saying Argument of type 'MiddlewareFn<Context & ConversationFlavor>' is not assignable to parameter of type 'Middleware'.

Any suggestion?

KnorpelSenf commented 2 months ago

You forgot to pass MyContext to Bot. It should be new Bot<MyContext>(..).

KnorpelSenf commented 2 weeks ago

Closing due to inactivity.