@allias173

Как отправить сообщение в телеграм боте с помощью запроса?

Нужно отправить сообщение в боте с помощью запроса

Вот так я могу отправить обычное сообщение с текстом "тест"
r=requests.get('https://api.telegram.org/bottoken/sendmessage?chat_id='+str(chat_id)+'&text=тест.')


Но вместе с этим нужно еще отправить параметр reply_markup, что бы вместе с сообщением поменялись кнопки. То есть нужно вставить ReplyKeyboardMarkup и 1 кнопку, допустим с названием "test". Как такое можно сделать?

P.S: нужно именно запросом, без telebot и тд
  • Вопрос задан
  • 6370 просмотров
Решения вопроса 1
deepblack
@deepblack Куратор тега Python
requests.get зачем get если там должен быть post?
curl'ом вот так:
curl -X POST \
     -H 'Content-Type: application/json' \
     -d '{"chat_id": "888888", "text": "This is a test message from curl", "disable_notification": true}' \
     https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage


Python:
import requests
import json

proxy = {'https': 'socks5h://user:password@IP:1080'}

token = '8888:ABC'
chat_id = 88888

URL = 'https://api.telegram.org/bot' + token + '/sendMessage'
reply_markup ={ "keyboard": [["Yes", "No"], ["Maybe"], ["1", "2", "3"]], "resize_keyboard": True}
data = {'chat_id': chat_id, 'text': '123', 'reply_markup': json.dumps(reply_markup)}
r = requests.post(URL, data=data, proxies=proxy)

print(r.json())
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 1
@AlexArGC
Прошу прощения за невежество. Я только пытаюсь разобраться с телеграмм ботами и их прграммированием. Есть необходимость отправлять в группу сообщения в формате JSON. У меня есть WEB HOOK сервер который по указанному HTTP адресу отправляет POST в JSON формате типа:

Request Body:
{"site_name": "\u041f\u043e\u0432\u0431\u043a\u0430)", "description": "\u041a\u043b, 63\u0430 - \u0421\u0430\u043d\u044f", "camera_number": 2088894996, "agent_uid": "P7RKZU*****************7I5DBLFZQ", "alert_list": "\u0421\u0412\u041e\u0418", "group": {"epoch_start": 16241******11, "camera_id": 2088894996, "frame_start": 5562034, "agent_uid": "P7RKZU82SGESI**********************I5DBLFZQ", "best_confidence": 93.59634399414062, "vehicle_crop_jpeg": "/9j/4AAQSkZJRgABA*********************bClscdfY570hn//Z", "company_id": "f23f5e56-6c37-4609-9677-7cf1f92a6392", "version": 2, "agent_type": "alprd", "best_plate": {"plate": "A464BM19", "confidence": 93.59634399414062, "region_confidence": 99, "vehicle_region": {"y": 0, "x": 711, "height": 571, "width": 571}, "region": "ru-sve", "plate_index": 0, "processing_time_ms": 24.905000686645508, "candidates": [{"matches_template": 1, "plate": "A464BM19", "confidence": 93.59634399414062}, {"matches_template": 1, "plate": "A464BM19", "confidence": 83.66334533691406}, {"matches_template": 0, "plate": "A464M19", "confidence": 83.66307830810547}, {"matches_template": 0, "plate": "A44BM19", "confidence": 83.66167449951172}, {"matches_template": 0, "plate": "464BM19", "confidence": 83.55057525634766}, {"matches_template": 0, "plate": "A64BM19", "confidence": 83.44303894042969}, {"matches_template": 0, "plate": "A46BM19", "confidence": 83.33016204833984}, {"matches_template": 0, "plate": "A464B19", "confidence": 83.32933807373047}, {"matches_template": 1, "plate": "A444BM19", "confidence": 83.20530700683594}, {"matches_template": 1, "plate": "A434BM19", "confidence": 83.16360473632812}], "coordinates": [{"y": 361, "x": 911}, {"y": 343, "x": 1081}, {"y": 385, "x": 1082}, {"y": 404, "x": 913}], "matches_template": 1, "plate_crop_jpeg": "/9j/4AAQSkZJRgA*******************.yrn+KigaP/9k=", "requested_topn": 10}, "vehicle": {"orientation": [{"confidence": 42.404842376708984, "name": "180"}, {"confidence": 29.746288299560547, "name": "225"}, {"confidence": 13.728647232055664, "name": "135"}, {"confidence": 10.803092956542969, "name": "0"}, {"confidence": 0.9642230272293091, "name": "270"}], "color": [{"confidence": 45.002071380615234, "name": "black"}, {"confidence": 26.961315155029297, "name": "green"}, {"confidence": 9.427495002746582, "name": "silver-gray"}, {"confidence": 4.327577590942383, "name": "blue"}, {"confidence": 3.7774503231048584, "name": "yellow"}], "make": [{"confidence": 31.201509475708008, "name": "jeep"}, {"confidence": 11.26911449432373, "name": "bmw"}, {"confidence": 6.81608247756958, "name": "land-rover"}, {"confidence": 5.410823345184326, "name": "suzuki"}, {"confidence": 4.836752414703369, "name": "harley-davidson"}], "body_type": [{"confidence": 69.87979125976562, "name": "motorcycle"}, {"confidence": 23.956607818603516, "name": "suv-crossover"}, {"confidence": 1.8700754642486572, "name": "tractor-trailer"}, {"confidence": 1.469692349433899, "name": "sedan-wagon"}, {"confidence": 0.9568098783493042, "name": "suv-standard"}], "year": [{"confidence": 30.567466735839844, "name": "2010-2014"}, {"confidence": 21.354726791381836, "name": "2015-2019"}, {"confidence": 19.367538452148438, "name": "2005-2009"}, {"confidence": 14.571271896362305, "name": "2000-2004"}, {"confidence": 4.477270603179932, "name": "1980-1984"}], "make_model": [{"confidence": 60.285865783691406, "name": "jeep_wrangler"}, {"confidence": 2.2076680660247803, "name": "land-rover_defender"}, {"confidence": 1.4812829494476318, "name": "jeep_cj-7"}, {"confidence": 1.4478868246078491, "name": "toyota_fj-cruiser"}, {"confidence": 0.7809848189353943, "name": "toyota_land-cruiser"}]}, "best_uuid": "P7RKZU82SGESIFZHHPE87HXIWIVCS187I5DBLFZQ-2088894996-1624120829062", "epoch_end": 1624120837415, "best_image_width": 2304, "data_type": "alpr_group", "best_image_height": 1296, "frame_end": 5562318, "is_parked": false, "best_region": "ru-sve", "uuids": ["P7RKZU82SGESIFZHHPE87HXIWIVCS187I5DBLFZQ-**************-1624120823211", ""P7RKZU82SGESIFZHHPE87HXIWIVCS187I5DBLFZQ-**************-1624120837415"], "plate_indexes": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "travel_direction": 210.373291015625, "country": "ru", "best_plate_number": "A464BM19", "best_region_confidence": 97.6282730102539, "matches_template": true, "agent_version": "2.7.101", "candidates": [{"matches_template": 1, "plate": "A464BM19", "confidence": 93.59634399414062}, {"matches_template": 0, "plate": "A464M19", "confidence": 81.7954330444336}, {"matches_template": 0, "plate": "A44BM19", "confidence": 80.50580596923828}, {"matches_template": 1, "plate": "A464BM19", "confidence": 80.4317398071289}, {"matches_template": 0, "plate": "A64BM19", "confidence": 79.40831756591797}, {"matches_template": 0, "plate": "A46BM19", "confidence": 77.89496612548828}, {"matches_template": 0, "plate": "A464B19", "confidence": 77.77008056640625}, {"matches_template": 1, "plate": "A444BM19", "confidence": 77.35125732421875}, {"matches_template": 1, "plate": "A434BM19", "confidence": 72.791259765625}, {"matches_template": 0, "plate": "464B


Из него хочется отправить в группу несколько полей: best_plate_number (текст) и vehicle_crop_jpeg (картинка jpeg). Ну или все если это можно обработать в одной строке HTTP типа:
https://api.telegram.org/bot400000393:AAF2ZmXoDG***************ijNRs/sendMessage?chat_id=-1000000000099&text="json(best_plate_number)"


Вообще это возможно? Может пнете что почитать...
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
18 апр. 2024, в 07:58
500 руб./в час
18 апр. 2024, в 07:22
45000 руб./за проект
18 апр. 2024, в 01:12
150000 руб./за проект