skip to Main Content
bot.on(/^/s (.+)$/, async function(msg, props) {
      let id = msg.chat.id;
      let message = await MyBot.getBySearchQuery(props.match[1]);
      let parse_mode = 'Markdown';
      return bot.sendMessage(id, message, { parse_mode });
    });

By /s <param> I want to get some hyperlink in telegram. But instead of that I’m getting [hyperlink](http://some_url).

What is going wrong here? The message here is always a string like [title](url).

2

Answers


  1. Are you using the node-telegram-bot-api npm module?

    I think you want to be using bot.onText method not .on. I’ve just tried with both, and when using .on the callback function never runs.

    bot.onText(/^/s (.+)$/, async function(msg, props) {
      let id = msg.chat.id;
      let message = await MyBot.getBySearchQuery(props.match[1]);
      let parse_mode = 'Markdown';
      return bot.sendMessage(id, message, { parse_mode });
    });
    
    

    Have you tried adding some kind of logging to this method to see if it ever actually runs, and that your getBySearchQuery(..) is returning the expected message?

    Login or Signup to reply.
  2. This reason yours isn’t working is because you called it parse_mode instead of parseMode (See doc)

    Try this, it should work.

    const TeleBot = require('telebot');
    
    const bot = new TeleBot('35353453:sfsdfsdffgrtyrty454646thfhfgfgh')
    
    bot.on(/^/s (.+)$/, async function(msg, props) {
      const id = msg.chat.id;
      const url = "https://google.com";
      const message = `Read more about [Google](${url}) now!!!!`;
    
      return bot.sendMessage(id, message, { parseMode: 'Markdown' });
    });
    
    bot.start();
    

    Okay, I tested it and it works well. I sent /s ert and here was the response:

    enter image description here

    So now let me click Google and you’ll see the popup:
    enter image description here

    THERE YOU GO. Hope it helps

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search