Skip to content

Commit 237f416

Browse files
committed
Added proper ending for commands
1 parent ff1cffe commit 237f416

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const token = 'YOUR_TELEGRAM_BOT_TOKEN';
4141
const bot = new TelegramBot(token, {polling: true});
4242
4343
// Matches "/echo [whatever]"
44-
bot.onText(/^\/echo (.+)/, (msg, match) => {
44+
bot.onText(/^\/echo(?:@.*?)? (.+)/, (msg, match) => {
4545
// 'msg' is the received Message from Telegram
4646
// 'match' is the result of executing the regexp above on the text content
4747
// of the message

examples/game/game.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ if (url === '0') {
3333
}
3434

3535
// Matches /start
36-
bot.onText(/^\/start/, function onPhotoText(msg) {
36+
bot.onText(/^\/start(@.*|$)/, function onPhotoText(msg) {
3737
bot.sendGame(msg.chat.id, gameName);
3838
});
3939

examples/polling.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const bot = new TelegramBot(TOKEN, options);
1414

1515

1616
// Matches /photo
17-
bot.onText(/^\/photo/, function onPhotoText(msg) {
17+
bot.onText(/^\/photo(@.*|$)/, function onPhotoText(msg) {
1818
// From file path
1919
const photo = `${__dirname}/../test/data/photo.gif`;
2020
bot.sendPhoto(msg.chat.id, photo, {
@@ -24,7 +24,7 @@ bot.onText(/^\/photo/, function onPhotoText(msg) {
2424

2525

2626
// Matches /audio
27-
bot.onText(/^\/audio/, function onAudioText(msg) {
27+
bot.onText(/^\/audio(@.*|$)/, function onAudioText(msg) {
2828
// From HTTP request
2929
const url = 'https://upload.wikimedia.org/wikipedia/commons/c/c8/Example.ogg';
3030
const audio = request(url);
@@ -33,7 +33,7 @@ bot.onText(/^\/audio/, function onAudioText(msg) {
3333

3434

3535
// Matches /love
36-
bot.onText(/^\/love/, function onLoveText(msg) {
36+
bot.onText(/^\/love(@.*|$)/, function onLoveText(msg) {
3737
const opts = {
3838
reply_to_message_id: msg.message_id,
3939
reply_markup: JSON.stringify({
@@ -48,14 +48,14 @@ bot.onText(/^\/love/, function onLoveText(msg) {
4848

4949

5050
// Matches /echo [whatever]
51-
bot.onText(/^\/echo (.+)/, function onEchoText(msg, match) {
51+
bot.onText(/^\/echo(?:@.*?)? (.+)/, function onEchoText(msg, match) {
5252
const resp = match[1];
5353
bot.sendMessage(msg.chat.id, resp);
5454
});
5555

5656

5757
// Matches /editable
58-
bot.onText(/^\/editable/, function onEditableText(msg) {
58+
bot.onText(/^\/editable(@.*|$)/, function onEditableText(msg) {
5959
const opts = {
6060
reply_markup: {
6161
inline_keyboard: [

0 commit comments

Comments
 (0)