![]() ![]() ![]() ![]() Here in a similar way, we need to extract the file id and pass it to the file_upload function. Step 22: Now in a similar way we can do it for audio and files.įor storing the audio we need to create a folder named “ music “.įor storing the documents we need to create a folder named “ documents “. On the server-side, you will see the print and JSON like this. Here in the function first we are trying to get our file path for the image that we had shared from a JSON.Īfter getting the file path we are trying to get the file from the telegram server by redirecting the file path to the “url_1”.įrom “url_1” we are trying to save the file to our computer. file_id = tel_parse_get_message(msg) tel_upload_file(file_id) We also need to call the function which we have created. from flask import Flask from flask import request from flask import Response import requests TOKEN = "" app = Flask(_name_) def parse_message(message): print("message->",message) chat_id = message txt = message print("chat_id->", chat_id) print("txt->", txt) return chat_id,txt def tel_send_message(chat_id, text): url = f' ' b = requests.get(url_1) file_content = b.content with open(file_pathh, "wb") as f: f.write(file_content) You can also add an extra parameter in send message for that you can follow the Documentation. We will write the code to get the response for the “hi” message from the user and if anything other than “hi” is imputed then response with “from webhook”. Step 11: send the text message from the bot. ![]() Here we can see that the message that we have written to the telegram bot we can get at the backend in text. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |