How can I bold text in telepot Telegram bot?

Viewed 24512

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

3 Answers

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)
Related