Answer the question
In order to leave comments, you need to log in
TeleBot receiving and sending files, what is missing?
I've been learning Python for 2 weeks and came up with one small project that would help me at my current job. The fact is that I wrote an Excel file handler (takes data from the form, transfers it to an invoice and converts it to PDF, you understand the level ;D) I want to add this and / or to this Telegram bot. Those. example: a customer takes a form on the site, fills it out and sends it to the bot in a telegram. Next, my script is launched, and upon completion it sends the finished pdf file. Well, as I have not tried, how many lessons / articles, etc. I didn’t look, it doesn’t work out for me to make such a cycle. The only thing that happened was to download the file for yourself, but immediately after that the bot crashes =( Please tell me what to see / read. How to solve such a problem with the bot?
import telebot
import constant
bot = telebot.TeleBot(constant.token)
upd = bot.get_updates()
last_upd = upd[-1]
message_from_user = last_upd.message
@bot.message_handler(func=lambda message: message.document.mime_type == 'text/plain', content_types=['document'])
def handle_text_doc(message):
if message.text == 'Документ':
bot.send_text(message.from_user.id, constant.document)
#document.close
chat_id = message.chat.id
file_info = bot.get_file(message.document.file_id)
downloaded_file = bot.download_file(file_info.file_path)
src = u'C:\\Users\Hleb\\Python\\excel\\' + message.document.file_name
with open(src, 'wb') as new_file:
new_file.write(downloaded_file)
bot.reply_to(message, "Одну минутку...")
import tableTOtable
bot.send_document
bot.polling(none_stop=True, interval=0)
Answer the question
In order to leave comments, you need to log in
Some kind of mess.
What are you sending here?
if message.text == 'Document':
bot.send_text(message.from_user.id, constant.document)
Linking the library in the wrong place
Where are the parameters?bot.send_document
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question