Skip to content

Commit

Permalink
Merge pull request #34 from beabee-communityrm/user-feedback/custom-k…
Browse files Browse the repository at this point in the history
…eyboard

feat(keyboard): Improvments from user feedback
  • Loading branch information
JumpLink authored Apr 30, 2024
2 parents 8e06c01 + 58ed3f4 commit 4e1f9b9
Show file tree
Hide file tree
Showing 43 changed files with 1,418 additions and 674 deletions.
2 changes: 0 additions & 2 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
},
"imports": {
"alosaur/": "https://deno.land/x/[email protected]/",
"grammy/": "https://deno.land/x/[email protected]/",
"grammy_types/": "https://deno.land/x/[email protected]/",
"std/": "https://deno.land/[email protected]/",
"typeorm": "npm:[email protected]",
"sqlite3": "https://deno.land/x/[email protected]/mod.ts",
Expand Down
2 changes: 1 addition & 1 deletion telegram-bot/commands/show.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class ShowCommand extends BaseCommand {
}

// Get the slug from the `/show slug` message text
const slug = ctx.message?.text?.split(" ")[1];
const slug = ctx.message?.text?.split(" ")[1]; // Alternatively, use ctx.match

if (!slug) {
await ctx.reply("Please specify a callout slug. E.g. `/show my-callout`");
Expand Down
16 changes: 11 additions & 5 deletions telegram-bot/commands/start.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CommunicationService } from "../services/communication.service.ts";
import { StateMachineService } from "../services/state-machine.service.ts";
import { MessageRenderer } from "../renderer/message.renderer.ts";
import { ChatState } from "../enums/index.ts";
import { ListCommand } from "./index.ts";
import { ListCommand, ResetCommand } from "./index.ts";

import type { AppContext } from "../types/index.ts";

Expand All @@ -24,16 +24,22 @@ export class StartCommand extends BaseCommand {
protected readonly messageRenderer: MessageRenderer,
protected readonly stateMachine: StateMachineService,
protected readonly listCommand: ListCommand,
protected readonly resetCommand: ResetCommand,
) {
super();
}

// Handle the /start command, replay with markdown formatted text: https://grammy.dev/guide/basics#sending-message-with-formatting
async action(ctx: AppContext): Promise<boolean> {
const session = await ctx.session;
const successful = await this.checkAction(ctx);
if (!successful) {
return false;

// Always allow the start command, automatically reset the session if it is not on the initial state
const startCanUsed = await this.checkAction(ctx, true);
if (!startCanUsed) {
// Send the welcome message before the reset command
await this.communication.send(ctx, this.messageRenderer.welcome());
// Execute the reset command
return await this.resetCommand.action(ctx);
}

await this.communication.send(ctx, this.messageRenderer.welcome());
Expand All @@ -53,6 +59,6 @@ export class StartCommand extends BaseCommand {
await this.messageRenderer.help(session.state),
);

return successful;
return true;
}
}
2 changes: 2 additions & 0 deletions telegram-bot/constants/characters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const CHECKMARK = "✓";
export const DOT = "•";
21 changes: 17 additions & 4 deletions telegram-bot/constants/events.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
// Event related constants
export const BUTTON_CALLBACK_PREFIX = "callback_query:data"; // Do not change this prefix
export const INLINE_BUTTON_CALLBACK_PREFIX = "callback_query:data";

// Note: We choose short strings here because the length of these strings is limited in the Telegram bot API
// and the slug is appended here.The max allowed size of a callback string is 64 bytes.
export const BUTTON_CALLBACK_SHOW_CALLOUT = "1";
export const BUTTON_CALLBACK_CALLOUT_INTRO = "2";
export const BUTTON_CALLBACK_CALLOUT_PARTICIPATE = "3";
export const INLINE_BUTTON_CALLBACK_SHOW_CALLOUT = "1";
export const INLINE_BUTTON_CALLBACK_CALLOUT_INTRO = "2";
export const INLINE_BUTTON_CALLBACK_CALLOUT_PARTICIPATE = "3";

/**
* Prefix for the callout response interaction events, used for skip and done inline buttons, perhaps useful for others.
* @example
* ```
* ${INLINE_BUTTON_CALLBACK_CALLOUT_RESPONSE}:skip
* ${INLINE_BUTTON_CALLBACK_CALLOUT_RESPONSE}:done
* ```
*/
export const INLINE_BUTTON_CALLBACK_CALLOUT_RESPONSE = "ibccr";

export const TRUTHY_MESSAGE_KEY = "yes";
export const FALSY_MESSAGE_KEY = "no";
1 change: 1 addition & 0 deletions telegram-bot/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./characters.ts";
export * from "./events.ts";
export * from "./html.ts";
export * from "./render.ts";
2 changes: 1 addition & 1 deletion telegram-bot/constants/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const EMPTY_RENDER: RenderEmpty = {
skipTexts: [],
},
parseType: ParsedResponseType.NONE,
removeKeyboard: true,
removeCustomKeyboard: true,
forceReply: false,
};

Expand Down
2 changes: 0 additions & 2 deletions telegram-bot/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
},
"imports": {
"alosaur/": "https://deno.land/x/[email protected]/",
"grammy/": "https://deno.land/x/[email protected]/",
"grammy_types/": "https://deno.land/x/[email protected]/",
"std/": "https://deno.land/[email protected]/",
"typeorm": "npm:[email protected]",
"sqlite3": "https://deno.land/x/[email protected]/mod.ts",
Expand Down
Loading

0 comments on commit 4e1f9b9

Please sign in to comment.