I
I
Ilya Pechersky2018-11-24 19:06:55
Python
Ilya Pechersky, 2018-11-24 19:06:55

How to read photos in telegram bot? What should be in the get_photo function and what libraries are needed?

import requests

token = ""
URL = "https://api.telegram.org/bot" + token + "/"


def get_updates():
    url = URL + "getupdates"
    r = requests.get(url)
    return r.json()


def get_updates_photo():
    url = URL + "update"
    #TODO


def get_photo():
    file = get_updates_photo()


def get_message():
    data = get_updates()
    chat_id = data["result"][-1]["message"]["chat"]["id"]
    message = data["result"][-1]["message"]["text"]
    message = {"chat_id": chat_id,
               "text": message}

    return message


def send_message(chat_id, text="..."):
    url = URL + 'sendmessage?chat_id={}&text={}'.format(chat_id, text)
    requests.get(url)


def main():
    answer = get_message()
    chat_id = answer["chat_id"]
    text = answer["text"]

    if (text == "Проверить подпись"):
        send_message(chat_id, "Отправьте фото")
        get_photo()
    else:
        send_message(chat_id, "Я вас не понимаю")


if __name__ == '__main__':
    main()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2018-11-25
@dimonchik2013

you pobyriku or detail?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question