From bfb602efe6f32d430d2acab5428dac5a09804c47 Mon Sep 17 00:00:00 2001 From: Eluda <111eluda111@gmail.com> Date: Sat, 5 Nov 2022 22:21:07 +0100 Subject: [PATCH] Replace /about and /start and fallback responses to an introduction message. --- src/bot.ts | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/bot.ts b/src/bot.ts index 2995f273..3b6db62a 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -8,11 +8,10 @@ import type { Variant as TextEffectVariant } from "./textEffects"; // Create a bot using the Telegram token const bot = new Bot(process.env.TELEGRAM_TOKEN || ""); -// Handle the /start and /yo commands -bot.command("start", (ctx) => ctx.reply("Welcome! Up and running.")); +// Handle the /yo command to greet the user bot.command("yo", (ctx) => ctx.reply(`Yo ${ctx.from?.username}`)); -// Handle the /effect command +// Handle the /effect command to apply text effects using an inline keyboard type Effect = { code: TextEffectVariant; label: string }; const allEffects: Effect[] = [ { @@ -157,28 +156,32 @@ const aboutUrlKeyboard = new InlineKeyboard().url( "Host your own bot for free.", "https://cyclic.sh/" ); -bot.command("about", (ctx) => - ctx.reply( - `Hello! I'm a Telegram bot.\nI'm powered by Cyclic, the next-generation serverless computing platform.`, - { - reply_markup: aboutUrlKeyboard, - } - ) -); // Suggest commands in the menu bot.api.setMyCommands([ - { command: "start", description: "Start the bot" }, { command: "yo", description: "Be greeted by the bot" }, - { command: "about", description: "Learn more about the bot" }, { command: "effect", description: "Apply text effects on the text. (usage: /effect [text])", }, ]); -// Handle all other messages -bot.on("message", (ctx) => ctx.reply("Got another message!")); +// Handle all other messages and the /start command +const introductionMessage = `Hello! I'm a Telegram bot. +I'm powered by Cyclic, the next-generation serverless computing platform. + +Commands +/yo - Be greeted by me +/effect [text] - Show a keyboard to apply text effects to [text]`; + +const replyWithIntro = (ctx: any) => + ctx.reply(introductionMessage, { + reply_markup: aboutUrlKeyboard, + parse_mode: "HTML", + }); + +bot.command("start", replyWithIntro); +bot.on("message", replyWithIntro); // Start the server if (process.env.NODE_ENV === "production") {