How to send bold text using Telegram Python bot
Asked Answered
R

2

18

I am writing a telegram bot in Python. I want to send messages with bold letters. I tried to inclose message inside both * and **, but it does not solve the problem.

Is there a function for mark up or HTML formatting or a way to do it?

Rochelrochell answered 16/3, 2018 at 18:22 Comment(0)
U
34

You should use:

bot.send_message(chat_id=chat_id, text="*bold* Example message", 
                parse_mode=telegram.constants.ParseMode.MARKDOWN_V2)

Or:

bot.send_message(chat_id=chat_id, text='<b>Example message</b>', 
                  parse_mode=telegram.ParseMode.HTML)

More info

Ulmaceous answered 16/3, 2018 at 18:47 Comment(0)
C
4

This is a little bit late. But i hope to be helpful for others:

import telepot
token = 'xxxxxxxxxxxxxxx' # Your telegram token .
receiver_id = yyyyyyyy # Bot id, you can get this by using the next link :  
https://api.telegram.org/bot<TOKEN>/getUpdates. Note that you should 
replace <TOKEN> with your token. 

bot = telepot.Bot(token) 
message = "*YOUR MESSAGE YOU WENT TO SEND.*" #Any characters between ** will be 
send in bold format. 

bot.sendMessage(receiver_id, message , parse_mode= 'Markdown' )  
Cazzie answered 31/12, 2021 at 0:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.