11

How to send markdown text by telegram bot using telegraf library on nodejs?

xpt
  • 20,363
  • 37
  • 127
  • 216
hitt
  • 381
  • 1
  • 3
  • 14
  • 6
    Hi there, looks like you're new to StackOverflow. Welcome aboard! When asking a question we expect that you provide an example of what you have tried to solve the problem with. Please provide a [mcve] & check out the [How to Ask Page](https://stackoverflow.com/help/how-to-ask) for more info on how to create an awesome question. – admcfajn Oct 27 '18 at 17:18
  • Welcome to Stack Overflow! Other users marked your question for low quality and need for improvement. I re-worded/formatted your input to make it easier to read/understand. Please review my changes to ensure they reflect your intentions. But I think your question is still not answerable. **You** should [edit] your question now, to include your own efforts (see [help me is not a question](https://meta.stackoverflow.com/questions/284236/why-is-can-someone-help-me-not-an-actual-question) ). Feel free to drop me a comment in case you have further questions or feedback for me. – GhostCat Oct 27 '18 at 19:15

4 Answers4

13

With telegraf v4.3.0, I got it working using the following code:

const bot = new Telegraf(token);
bot.telegram.sendMessage('my chat id', 'my text', { parse_mode: 'MarkdownV2' });
Benny Code
  • 51,456
  • 28
  • 233
  • 198
8
const token = 'YOUR TOKEN';
const Telegraf = require('telegraf')
const extra = require('telegraf/extra')
const markup = extra.markdown()

const telegram = new Telegraf(token)

telegram.telegram.sendMessage('there chat id', 'your message', markup)
hitt
  • 381
  • 1
  • 3
  • 14
6
ctx.replyWithMarkdown(MESSAGE)
Kevin Meyer
  • 2,816
  • 4
  • 21
  • 33
Erick Wachira
  • 85
  • 1
  • 6
4

If you are using the context object ctx in imported modules to reply and don't want to import Telegraf, then you can use:

ctx.reply('some _text_', {reply_markup: 'markdown'})
K1DV5
  • 61
  • 1
  • 6