Didn't understood some code

Hi , Can you explain with another simple example about POST method? I never used these earlier that’s why I am asking. Also why we need to convert text data to json data using json.loads(). We didn’t decloared “ok” anywhere how does it contain boolean values?

def send_telegram_message(message):
        """Sends message via Telegram"""
        url = "https://api.telegram.org/" + conf.telegram_bot_id + "/sendMessage"
        data = {
            "chat_id": conf.telegram_chat_id,
            "text": message
        }
        try:
            response = requests.request(
                "POST",
                url,
                params=data
            )
            print("This is the Telegram response")
            print(response.text)
            telegram_data = json.loads(response.text)
            return telegram_data["ok"]
        except Exception as e:
            print("An error occurred in sending the alert message via Telegram")
            print(e)
            return False

requests.request is used to send the data to our Telegram channel. The POST is method is basically used to ‘post’ the data at the given URL (this is the opposite of the GET method, also a part of the request module in Python). In the end, it tries to post the data (contains the message we want to send and the channel id to which we need to send the message) via the URL, which requests the bot we created to do just that- send a message to our channel. Now, json.loads() returns a dictionary, of which one of the keys is ok. Depending on whether our request was successful or not, this key holds either True or False.
As for why we need to convert a String to JSON, JSON is similar to Python Dictionaries, so parsing becomes easier.

@kamramohit96 The POST request is used to send some data to a URL. In this case, we are sending the chat_id and the message to be posted in that chat.
The response from Telegram is stored in the “response” variable. The text data in the response is converted to JSON to allow for easier parsing.

Depending on the request we made, the response will contain a field with the name “ok” which lets us know if the request was successful or not. True means it was successful and False is for failure.