Skip to content

Commit f496f04

Browse files
committed
Merge branch 'develop'
2 parents 4586909 + f703f47 commit f496f04

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

src/bot/helpers/update.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,26 @@ export const withTextMessage: (
4040
}
4141
};
4242
};
43+
44+
/**
45+
* Middleware wrapper that only executes the given handler
46+
* if the current chat type matches one of the allowed types.
47+
*
48+
* This is useful for running middleware only in private chats,
49+
* groups, or supergroups without blocking other middleware in the chain.
50+
*
51+
* @param types - Allowed chat types (e.g. ['private'], ['group', 'supergroup'])
52+
* @param handler - The middleware to run if chat type matches
53+
* @returns Middleware function that filters by chat type
54+
*/
55+
export const withChatType = (
56+
types: Array<'private' | 'group' | 'supergroup' | 'channel'>,
57+
handler: MiddlewareFn<MyContext>,
58+
): MiddlewareFn<MyContext> => {
59+
return async (ctx, next) => {
60+
if (ctx.chat && 'type' in ctx.chat && types.includes(ctx.chat.type)) {
61+
return handler(ctx, next);
62+
}
63+
return next();
64+
};
65+
};

src/bot/index.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,11 @@ bot.start(async (ctx) => {
2323
]);
2424

2525
const message = `
26-
👋 Welcome! I'm here to help you interact with Telegram using some examples.
27-
2826
Here are the available commands:
2927
3028
/start - Start interaction with the bot
3129
/help - Display help information
3230
/settings - Display bot settings
33-
/example1 - Example 1: Inline keyboard with callback buttons
34-
/example2 - Example 2: Custom keyboard with text options
35-
/example3 - Example 3: A base scene with multi-step questions and basic navigation
36-
/example4 - Example 4: Wizard scene with multiple steps and user interaction
3731
/back - Go back to the previous step
3832
/cancel - Cancel the current operation
3933
`.trim();

src/main.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@ server.on('listening', async () => {
3131
{ command: '/start', description: 'Start interaction with the bot' },
3232
{ command: '/help', description: 'Display help information' },
3333
{ command: '/settings', description: 'Display bot settings' },
34-
{ command: '/example1', description: 'Example 1: Inline keyboard with callback buttons.' },
35-
{ command: '/example2', description: 'Example 2: Custom keyboard with text options.' },
36-
{
37-
command: '/example3',
38-
description: 'Example 3: A base scene with multi-step questions and basic navigation.',
39-
},
40-
{
41-
command: '/example4',
42-
description: 'Example 4: Wizard scene with multiple steps and user interaction.',
43-
},
4434
{
4535
command: '/back',
4636
description: 'Go back to the previous step',

src/types/telegraf.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export interface MySession extends Scenes.WizardSession<MyWizardSession> {
4848
}
4949

5050
export interface MyContext<U extends Update = Update> extends Context<U> {
51-
fullName?: string; // user's or bot's username
51+
fullName?: string; // user's or bot's full name
5252
scene: Scenes.SceneContextScene<MyContext, MyWizardSession>;
5353
wizard: Scenes.WizardContextWizard<MyContext>;
5454
session: MySession;

0 commit comments

Comments
 (0)