G
G
Gleb Lukashonok2019-09-07 02:29:50
Python
Gleb Lukashonok, 2019-09-07 02:29:50

How to send a file from telegram bot?

Hello everyone, I really need your help with the code. Task: saving the file, running the script, sending the finished (remade) file. Well, I can't send the file. Guys, tell me these 3 lines :(

import telebot
import constant
bot = telebot.TeleBot(constant.API_TOKEN)
doc = open('C:\\Users\Hleb\\Python\\TeleBot_Final\\Счет-фактура.pdf', 'rb')

# Сохраняем присланый от пользователя файл
@bot.message_handler(content_types=['document'])
def handle_file(message):
    try:
        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\\TeleBot_Final\\' + message.document.file_name
        with open(src, 'wb') as new_file:
            new_file.write(downloaded_file)
        import delete
        import tableTOtable
        bot.reply_to(message, 'Одну минуточку...')
        bot.send_document(chat_id, constant.doc)
        bot.send_document(chat_id, "FILEID")
    except Exception as e:
        bot.reply_to(message, e)
bot.polling(none_stop=True, interval=0)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Danil K., 2019-10-30
@Danya_Violet

uis_pdf = open('files/' + uis_login + '.pdf', 'rb')
bot.send_document(message.chat.id, uis_pdf)
uis_pdf.close()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question