Send markdown text with telegram bot (telegraf), nodejs
Asked Answered
S

4

13

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

Sugarplum answered 27/10, 2018 at 14:28 Comment(2)
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 minimal reproducible example & check out the How to Ask Page for more info on how to create an awesome question.Sophister
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 ). Feel free to drop me a comment in case you have further questions or feedback for me.Quillon
S
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)
Sugarplum answered 27/10, 2018 at 15:38 Comment(1)
this one is old old old, not working notMathers
G
15

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' });
Germicide answered 22/3, 2021 at 11:33 Comment(1)
Can be used in more simplest way: ctx.replyWithMarkdownV2(message), your code will be under the hood.Unciform
S
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)
Sugarplum answered 27/10, 2018 at 15:38 Comment(1)
this one is old old old, not working notMathers
M
6
ctx.replyWithMarkdown(MESSAGE)
Maje answered 6/12, 2020 at 2:39 Comment(0)
A
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'})
Amenity answered 4/12, 2019 at 9:33 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.