diff --git a/README.md b/README.md index 395f58be..1722c906 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ const token = 'YOUR_TELEGRAM_BOT_TOKEN'; const bot = new TelegramBot(token, {polling: true}); // Matches "/echo [whatever]" -bot.onText(/\/echo (.+)/, (msg, match) => { +bot.onText(/^\/echo(?:@.*?)? (.+)/, (msg, match) => { // 'msg' is the received Message from Telegram // 'match' is the result of executing the regexp above on the text content // of the message diff --git a/examples/game/game.js b/examples/game/game.js index cd7a9d23..5b34c20b 100644 --- a/examples/game/game.js +++ b/examples/game/game.js @@ -33,7 +33,7 @@ if (url === '0') { } // Matches /start -bot.onText(/\/start/, function onPhotoText(msg) { +bot.onText(/^\/start(@.*|$)/, function onPhotoText(msg) { bot.sendGame(msg.chat.id, gameName); }); diff --git a/examples/polling.js b/examples/polling.js index 13f4cab0..364be757 100644 --- a/examples/polling.js +++ b/examples/polling.js @@ -14,7 +14,7 @@ const bot = new TelegramBot(TOKEN, options); // Matches /photo -bot.onText(/\/photo/, function onPhotoText(msg) { +bot.onText(/^\/photo(@.*|$)/, function onPhotoText(msg) { // From file path const photo = `${__dirname}/../test/data/photo.gif`; bot.sendPhoto(msg.chat.id, photo, { @@ -24,7 +24,7 @@ bot.onText(/\/photo/, function onPhotoText(msg) { // Matches /audio -bot.onText(/\/audio/, function onAudioText(msg) { +bot.onText(/^\/audio(@.*|$)/, function onAudioText(msg) { // From HTTP request const url = 'https://upload.wikimedia.org/wikipedia/commons/c/c8/Example.ogg'; const audio = request(url); @@ -33,7 +33,7 @@ bot.onText(/\/audio/, function onAudioText(msg) { // Matches /love -bot.onText(/\/love/, function onLoveText(msg) { +bot.onText(/^\/love(@.*|$)/, function onLoveText(msg) { const opts = { reply_to_message_id: msg.message_id, reply_markup: JSON.stringify({ @@ -48,14 +48,14 @@ bot.onText(/\/love/, function onLoveText(msg) { // Matches /echo [whatever] -bot.onText(/\/echo (.+)/, function onEchoText(msg, match) { +bot.onText(/^\/echo(?:@.*?)? (.+)/, function onEchoText(msg, match) { const resp = match[1]; bot.sendMessage(msg.chat.id, resp); }); // Matches /editable -bot.onText(/\/editable/, function onEditableText(msg) { +bot.onText(/^\/editable(@.*|$)/, function onEditableText(msg) { const opts = { reply_markup: { inline_keyboard: [