I am using very simple Telegram bot, that only sends messages, so to make it simple I only send POST request to sendMessage API via Python's requests library. But I cannot understand how to add flags to this call properly. Basically I only need to add no_webpage and silent flags.
Is this even possible? I really don't want to use more advanced tech, because this will require registering an app as well, and its just an overkill.
My URL looks like this:
https://api.telegram.org/botTOKEN/sendMessage?chat_id=CHAT&parse_mode=HTML&flags=1
I send text in the post body (not sure if it's even helpful, because of the 4096 symbols limit)
I tried to bit-encode flags field, but it doesn't seem to work.
You are looking at the wrong documentation, the link in your comment refers to the core-api, since you are using a BOT, you should only look at the BOT API.
If you look at the sendMessage method, you'll see the parameter:
link_preview_options
Link preview generation options for the message
Check the LinkPreviewOptions
for all the options, seems like you're looking for the is_disabled
flag.
An python example showing how to pass this:
import json
import urllib.parse
import requests
url = "https://api.telegram.org/bot<MY-Bot0TOKEN>/sendMessage"
query_string = '?' + urllib.parse.urlencode({
'chat_id': 12345,
'text': 'Hello this is a [link](https://stackoverflow.com/questions/77986367/how-to-add-flags-to-messages-sendmessage-call-to-telegram-rest-api-call-via-url)',
'parse_mode': 'markdown',
'link_preview_options': json.dumps({
'is_disabled': True
})
})
response = requests.request("POST", url + query_string)
print(response.text.encode('utf8'))
The first message is with false
and the second with true
on is_disabled
: