Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I bold text in telepot Telegram bot?

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

like image 258
SudoGuy Avatar asked Sep 04 '18 10:09

SudoGuy


People also ask

How do you text Mono on Telegram?

In the mobile version of Telegram on Android, the monospaced text is done as follows: select the typed text, click on the icon in the form of three horizontal dots and in the displayed list select the type of face "Mono". In iOS, also select the typed text, click "B / U", then select the type of face "Monospace".


2 Answers

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

like image 131
newsha Avatar answered Oct 01 '22 22:10

newsha


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)
like image 29
MrGreatdigger Avatar answered Oct 01 '22 21:10

MrGreatdigger