Skip to content

Changed example commands regex #1006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/game/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
10 changes: 5 additions & 5 deletions examples/polling.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand All @@ -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);
Expand All @@ -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({
Expand All @@ -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: [
Expand Down