Skip to content

Instantly share code, notes, and snippets.

@felinto-dev
Created April 15, 2021 07:53
Show Gist options
  • Save felinto-dev/a2169bf2f1e2a2dd8658c73a6889c79b to your computer and use it in GitHub Desktop.
Save felinto-dev/a2169bf2f1e2a2dd8658c73a6889c79b to your computer and use it in GitHub Desktop.
Get commands args from context in Telegram
import { deunionize } from 'telegraf';
import { Context } from '../interfaces';
export const getCommandArgs = (ctx: Context): string => {
const messageText = deunionize(ctx.message).text;
const argsFromCommandRegex = /\/(?:\w+)(?:@\w+?_bot)? (?<args>.*)/i;
const args = argsFromCommandRegex.exec(messageText);
if (!args) {
return '';
}
return args.groups.args.trim();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment