Skip to content

Commit 1a92945

Browse files
authored
Merge pull request #32 from gabeklavans/feature/update-start
Update start command to display explanatory welcome message
2 parents ba1d538 + f021d25 commit 1a92945

File tree

4 files changed

+57
-19
lines changed

4 files changed

+57
-19
lines changed

package-lock.json

Lines changed: 32 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"@fastify/cors": "^8.4.0",
4040
"@fastify/swagger": "^8.12.0",
4141
"@fastify/swagger-ui": "^1.10.1",
42+
"@grammyjs/parse-mode": "^1.10.0",
4243
"correct-frequency-random-letters": "^1.0.1",
4344
"date-fns": "^3.6.0",
4445
"dictionary-en": "^3.2.0",

src/bot.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
import { Bot, GrammyError, InlineKeyboard } from "grammy";
2-
import { GAME_LIST, GAME_START_BUTTON_TEXT } from "./constants";
1+
import { Bot, Context, GrammyError, InlineKeyboard } from "grammy";
2+
import { GAME_LIST, GAME_START_BUTTON_TEXT, WELCOME_MESSAGE } from "./constants";
33
import { getSessionId, throwIfSessionExpired } from "./server/utils";
44
import { SessionExpiredError } from "./server/errors";
5+
import { ParseModeFlavor, hydrateReply } from "@grammyjs/parse-mode";
56

67
if (!process.env.BOT_API_KEY) {
78
console.error("environment misconfigured");
89
}
910

1011
if (process.env.BOT_API_KEY == null) throw Error("Telegram bot API token is missing.");
11-
export const bot = new Bot(process.env.BOT_API_KEY!);
12+
export const bot = new Bot<ParseModeFlavor<Context>>(process.env.BOT_API_KEY!);
13+
14+
bot.use(hydrateReply);
1215

1316
const startingInlineKeyboard = new InlineKeyboard().game(GAME_START_BUTTON_TEXT);
1417

15-
bot.command("start", (ctx) => ctx.reply("Welcome! Up and running."));
18+
bot.command(
19+
"start",
20+
async (ctx) => await ctx.replyFmt(WELCOME_MESSAGE, { link_preview_options: { is_disabled: true } }),
21+
);
1622

1723
bot.command("game", async (ctx) => {
1824
await ctx.replyWithGame(process.env.WORD_HUNT_SHORTNAME as string, {

src/constants.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { code, fmt, link } from "@grammyjs/parse-mode";
2+
13
export enum Game {
24
WORD_HUNT,
35
}
@@ -21,7 +23,18 @@ export const TURN_MAX: { [key in Game]: number } = {
2123
[Game.WORD_HUNT]: Number.MAX_VALUE,
2224
};
2325

24-
export const GAME_START_BUTTON_TEXT = "Play now!"
26+
export const GAME_START_BUTTON_TEXT = "Play now!";
2527

2628
export const MAX_SESSIONS = 10000;
2729
export const NUM_DAYS_SESSION_EXPIRED = 3;
30+
31+
export const WELCOME_MESSAGE = fmt`Welcome!
32+
33+
This bot is best used in ${link(
34+
"Inline Mode",
35+
"https://telegram.org/blog/inline-bots",
36+
)}. Just go to your chat then type the name of the bot with a space at the end: ${code(
37+
"@gamejaybot ",
38+
)} and a list of games should show up! You can search through the games by continuing to type your search query. Then, tap on the one you want to start and it will send a new game to the chat you're in.
39+
40+
Currently, Word Hunt Online is the only game available for GameJay, but more are planned to be added!`;

0 commit comments

Comments
 (0)