JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 8745
  • Score
    100M100P100Q130659F
  • License MIT

Conversational interfaces for grammY

Package Exports

  • @grammyjs/conversations
  • @grammyjs/conversations/out/mod.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@grammyjs/conversations) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

grammY conversations


The grammY conversations plugin lets you create powerful conversational interfaces with ease.

This is version 2 of the plugin. Version 2 is a complete rewrite from scratch. If you are still using version 1.x, check out the migration guide. (The old docs are no longer be updated but they can still be found here.)

You should check out the official documentation of the plugin, but here is a quickstart for you to get up and running.

Quickstart

Run npm i @grammyjs/conversations and paste the following code:

import { Bot, type Context } from "grammy";
import {
    type Conversation,
    type ConversationFlavor,
    conversations,
    createConversation,
} from "@grammyjs/conversations";

type MyContext = ConversationFlavor<Context>;
type MyConversationContext = Context;

type MyConversation = Conversation<MyContext, MyConversationContext>;

const bot = new Bot<MyContext>("");

/** Defines the conversation */
async function greeting(
    conversation: MyConversation,
    ctx: MyConversationContext,
) {
    await ctx.reply("Hi there! What is your name?");
    const { message } = await conversation.wait();
    await ctx.reply(`Welcome to the chat, ${message.text}!`);
}

bot.use(conversations());
bot.use(createConversation(greeting));

bot.command("enter", async (ctx) => {
    await ctx.reply("Entering conversation!");
    // enter the function "greeting" you declared
    await ctx.conversation.enter("greeting");
});

bot.command("start", (ctx) => ctx.reply("Hi! Send /enter"));
bot.use((ctx) => ctx.reply("What a nice update."));

bot.start();

Nifty!