skip to Main Content

I wanted to send a Document via Telegram bot API and my document is stored locally. I tried:

https://api.telegram.org/botToken/sendDocument?chat_id=-5278798&document=C:UsersAdministratorDesktopfile.txt

But I got Error…

Bad Request: failed to get HTTP URL content

This method only works in remote URLs, how to send documents via bot API?

2

Answers


  1. You can’t use files local from your pc as I assume you have done via the document=C:UsersAdministratorDesktopfile.txt in your URL
    On the docs it states "Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet." Telegram media Documents
    Meaning you either have to use a file on the telegram servers or upload it to a website and send it via the URL you have uploaded it too.

    Login or Signup to reply.
  2. Using python-telegram-bot you can send a local file using send_document method

     c_id = '000011'   
     filename = '/tmp/googledoc.docx'
    
     context.bot.send_document(chat_id='c_id, document=open('googledoc.docx', 'rb'), filename="googledoc.docx")
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search