Node module which helps your bot to cache messages in Telegram chat

Usage no npm install needed!

<script type="module">
  import nodeTelegramCacheChatMessages from '';



Build Status

Node module which helps your bot to cache text messages in Telegram chat.


npm install node-telegram-cache-chat-messages


Node-telegram-cache-chat-messages initially works with node-telegram-bot-api.

const TelegramBot = require('node-telegram-bot-api');
const TelegramCacheChatMessages = require('node-telegram-cache-chat-messages');

const bot = new TelegramBot(BOT_TOKEN);
const casheMessages = new TelegramCacheChatMessages({
  all: true,
  edited: true

bot.onText(/command/, msg => {
  const chatId =;
  const messages = casheMessages.messages(chatId);
  // do something with messages. For example resend last message:
  const lastMessage = messages[messages.length - 1];

  bot.sendMessage(chatId, lastMessage);


new TelegramCacheChatMessages({
  bot: <you bot instance> // previously created bot via node-telegram-bot-api
  all: <boolean> // [default: false] false means that you cache only last message, true is that you cache all messages
  edited: <boolean> // [default: true] false means that you cache only messages, true is that you cache edited messages too


  • After using your commands cached messages will be cleared. This is done to avoid serious memory overflow
  • Node-telegram-cache-chat-messages doesn't process messages with non text content
  • Node-telegram-cache-chat-messages doesn't cache other bots messages