I have tried this
elif command == 'bold':
telegram_bot.sendMessage (chat_id, str("*bold*"), reply_markup=markup)
But it is replying *bold*
instead of bold
I have tried this
elif command == 'bold':
telegram_bot.sendMessage (chat_id, str("*bold*"), reply_markup=markup)
But it is replying *bold*
instead of bold
You need to provide a parse_mode
Parameter (parse_mode="Markdown").
Or else you will not see any markdown style.
sendMessage(chat_id, "*this text is bold*", parse_mode= 'Markdown')
See
https://telepot.readthedocs.io/en/latest/reference.html#telepot.Bot.sendMessage
I had that same issue with Markdown parse_mode. I've written send_message on my own, without using telepot's sendMessage method. In this case, its much easier to understand how to deal with this problem:
url = 'https://api.telegram.org/bot<token>'
def send_message(chat_id, text='empty line', parse_mode = 'Markdown'):
URL = url + 'sendMessage'
answer = {'chat_id': chat_id, 'text': text, 'parse_mode': 'Markdown'}
r = requests.post(URL, json=answer)
return r.json()
if (text == '/bold'):
send_message(chat_id, 'Here comes the'+'*'+'bold'+'*'+'text!')
On the other hand, you could use curl for sending bold text:
if (text == '/bold'):
URL = url + 'sendMessage?chat_id='+chat_id+'&text=*Here comes the bold text*&parse_mode=Markdown'
answer = {'chat_id': chat_id, 'text': text}
r = requests.post(URL, json=answer)
abstracted from --> How can I write bold in python telegram bot
You should use:
bot.send_message(chat_id=chat_id, text="*bold* Example message",
parse_mode=telegram.ParseMode.MARKDOWN)
Or:
bot.send_message(chat_id=chat_id, text='<b>Example message</b>',
parse_mode=telegram.ParseMode.HTML)
More info at: https://github.com/python-telegram-bot/python-telegram-bot/wiki/Code-snippets#message-formatting-bold-italic-code-