Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

Node.js Bot.sendDocument() Method

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The Bot.sendDocument() method is used in the Node.js Telegram Bot API. This Node.js module interacts with the official Telegram Bot API. This method is used to send Documents having extensions like .pdf, .docx, .txt, etc.


TelegramBot.sendDocument(chatId, location) 

Parameters: This method accepts two parameters as mentioned above and described below:

  • chatId: A chatId is a unique identifier for a chat, that can be either private, group, supergroup, or channel whereas a userId is a unique identifier for a user or bot only. Every Client’s Message contains chatId.
  • Location: Location of the document which we want to send in String format.

Return Type: The return type of the function is void.

Installing Module: Install the module using the following command: 

npm i telegram-bot-api

Steps to get the keys: 

First, get the GET BOT_TOKEN from BOTFATHER in telegram. Just search for BOTFATHER in Telegram and select the verified one as shown below: 

Type /start and then click on /newbot as shown below: 

Now type the name of the bot and that must be unique. 

Now just copy the token From the BotFather. And for deleting the token simply search /delete the token in BotFather. 

Project structure:  

Filename: bot.js 


const token = 'Enter the token';
const TelegramBot = require('node-telegram-bot-api');
const bot = new TelegramBot(token, { polling: true });
// Matches "/echo [whatever]"
bot.onText(/\/echo(.+)/, (msg, match) => {
    // The 'msg' is the received Message from Telegram
    // and 'match' is the result of executing the regexp
    // above on the text content of the message
    const chatId =;
    // The captured "whatever"
    const resp = match[1];
    // Reply to the Bot
    bot.sendMessage(chatId, "Your Document is")
    // Sending the document
    bot.sendDocument(chatId, "document.pdf");

Run the bot.js file using the following command:

node bot.js


My Personal Notes arrow_drop_up
Last Updated : 05 Apr, 2023
Like Article
Save Article
Similar Reads
Related Tutorials