Skip to content

Commit

Permalink
Replace /about and /start and fallback responses to an introduction m…
Browse files Browse the repository at this point in the history
…essage.
  • Loading branch information
youneslaa7878 committed Nov 5, 2022
1 parent 6aa4e92 commit bfb602e
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [
{
Expand Down Expand Up @@ -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.
<b>Commands</b>
/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") {
Expand Down

0 comments on commit bfb602e

Please sign in to comment.