Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove Reply Keyboard (Telegram Bot)

I just need the url to remove the ReplyKeyboard.

I am using Python but not the Python BotLibrary. I do all the work with requests because I want the full flexibility.

like image 452
HTS Avatar asked Dec 21 '25 03:12

HTS


2 Answers

I looked it up and tested it in PHP:

$removeKeyboard = array('remove_keyboard' => true);
$removeKeyboardEncoded = json_encode($removeKeyboard);
file_get_contents("https://api.telegram.org/BOTTOKEN/sendmessage?chat_id=CHATID&reply_markup=".$removeKeyboardEncoded")

The URL logic is the same in Python as it is in PHP, you just have to adjust the JSON encode function (...).

Update

I learned Python in the last two years so here's the actual code:

import json
import urllib.request

removeKeyboard = {'remove_keyboard':True}
removeKeyboardEncoded = json.dumps(removeKeyboard)
urllib.request.urlopen("https://api.telegram.org/BOTTOKEN/sendmessage?chat_id=CHATID&text=MESSAGE&reply_markup=" + removeKeyboardEncoded).read()

In the current version of the Bot API you now have to add the text parameter -or else you get a Bad Request: message text is empty- but the rest works like it worked back then.

like image 143
creyD Avatar answered Dec 24 '25 01:12

creyD


You can sendMessage via HTTPS request with ReplyKeyboardRemove.

like image 38
Sean Avatar answered Dec 24 '25 01:12

Sean