Skip to content

Commit

Permalink
Add start button
Browse files Browse the repository at this point in the history
  • Loading branch information
kubk committed Dec 23, 2023
1 parent ce83830 commit 2a0ea82
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
9 changes: 7 additions & 2 deletions functions/server-bot/on-start.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { Context } from "grammy";
import { Context, InlineKeyboard } from "grammy";
import { EnvSafe } from "../env/env-schema.ts";
import { createUserAwareTranslator } from "../translations/create-user-aware-translator.ts";

export const onStart = (envSafe: EnvSafe) => async (ctx: Context) => {
await ctx.replyWithChatAction("typing");
const translator = await createUserAwareTranslator(envSafe, ctx);

return ctx.reply(translator.translate("start"));
return ctx.reply(translator.translate("start"), {
reply_markup: new InlineKeyboard().url(
translator.translate("start_button"),
envSafe.BOT_APP_URL_PLAIN,
),
});
};
9 changes: 6 additions & 3 deletions functions/translations/create-translator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Translator } from "../lib/translator/translator.ts";

const en = {
start: `Hello! I help improving memory with spaced repetition. You can learn languages, history or other subjects.\n\nClick "MemoCard" to start 👇`,
start: `Hello! I help improving memory with spaced repetition. You can learn languages, history or other subjects 👇`,
invalid_card_format:
"Please send a message in the format: `front \\- back`\n\n*Example:*\nMe gusta \\- I like it",
no_decks_created: `You don't have any personal decks yet. Create one in the app first 👇`,
Expand All @@ -21,12 +21,13 @@ const en = {
confirm_card_creation_front: `Create card?\n\n*Front:* `,
confirm_card_creation_back: `\n\n*Back:* `,
confirm_card_creation_example: `\n\n*Example:* `,
start_button: "Start bot",
};

type Translation = typeof en;

const ru: Translation = {
start: `Привет! Я помогаю улучшать память с помощью интервального повторения. Подхожу для изучения языки, истории и других предметов\n\nНажимай "MemoCard" для запуска 👇`,
start: `Привет! Я помогаю улучшать память с помощью интервального повторения. Подхожу для изучения языков, истории и других предметов 👇`,
invalid_card_format:
"Пожалуйста, отправь сообщение в формате: `вопрос \\- ответ`\n\n*Пример:*\nMe gusta \\- Мне нравится",
no_decks_created: `У тебя ещё нет личных колод. Создай колоду в приложении 👇`,
Expand All @@ -46,11 +47,12 @@ const ru: Translation = {
confirm_card_creation_back: `\n\n*Ответ:* `,
confirm_card_creation_example: `\n\n*Пример:* `,
confirm_card_creation_front: `Создать карточку?:\n\n*Вопрос:* `,
start_button: "Запустить бота",
};

const es: Translation = {
start:
'Hola! Te ayudo a mejorar la memoria con la repetición espaciada. Puedes aprender idiomas, historia u otras materias.\n\nHaz clic en "MemoCard" para comenzar 👇',
"Hola! Te ayudo a mejorar la memoria con la repetición espaciada. Puedes aprender idiomas, historia u otras materias 👇",
invalid_card_format:
"Envíe un mensaje en el formato: `pregunta \\- respuesta`\n\n*Ejemplo:*\nI like it \\- Me gusta",
no_decks_created: `Todavía no tienes mazos personales. Crea uno en la aplicación 👇`,
Expand All @@ -70,6 +72,7 @@ const es: Translation = {
bot_button_confirm: "✅ Crear",
confirm_card_creation_example: `\n\n*Ejemplo:* `,
confirm_card_creation_front: `Crear tarjeta?:\n\n*Pregunta:* `,
start_button: "Iniciar bot",
};

const translations = { en, ru, es } as const;
Expand Down

0 comments on commit 2a0ea82

Please sign in to comment.