{"_id":"@andcreations/telegram-bot","_rev":"3-bada784d7541397bd70a44a76e72995d","name":"@andcreations/telegram-bot","dist-tags":{"latest":"0.10.0"},"versions":{"0.8.0":{"name":"@andcreations/telegram-bot","version":"0.8.0","author":{"name":"AndCreations"},"license":"MIT","_id":"@andcreations/telegram-bot@0.8.0","maintainers":[{"name":"mikolajgucki","email":"mikolaj.gucki@gmail.com"}],"homepage":"https://github.com/andcreations/telegram-bot","bugs":{"url":"https://github.com/andcreations/telegram-bot/issues"},"dist":{"shasum":"49c475a6e3bcb8fc4b369603e58d67942710eb68","tarball":"https://registry.npmjs.org/@andcreations/telegram-bot/-/telegram-bot-0.8.0.tgz","fileCount":47,"integrity":"sha512-PVKZSyA3PclUs+fVZ8gpjFrjlPlZgiu17pNnI/2ZYVNnmkRr4qp73fRHnCMgW/I9zMM3Mp0g6+Jd+ebmCC83mg==","signatures":[{"sig":"MEQCIESkjM/z4cKD1BjJOl1+pLWFNkdUVJaI9N9F/ZHuQKdzAiBtvhoUBZ0mr2jUHEhMSRczS1ZVvDr8QR6pPsm1T8Wwtw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":30505},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"985b8b10af7c9e3950d2038ea1b10929a082261d","private":false,"scripts":{"build":"tsc","clean":"rm -rf dist && rm -rf node_modules","rebuild":"rm -rf dist && rm -rf node_modules && npm run build"},"_npmUser":{"name":"mikolajgucki","email":"mikolaj.gucki@gmail.com"},"repository":{"url":"git+https://github.com/andcreations/telegram-bot.git","type":"git"},"_npmVersion":"10.9.2","description":"Telegram bot client","directories":{},"_nodeVersion":"22.15.0","dependencies":{"axios":"^0.24.0","form-data":"^4.0.0","typescript":"^4.0.3","@andcreations/common":"^0.1.15"},"_hasShrinkwrap":false,"devDependencies":{"@types/node":"^14.11.5"},"_npmOperationalInternal":{"tmp":"tmp/telegram-bot_0.8.0_1765398800033_0.7250485750378217","host":"s3://npm-registry-packages-npm-production"}},"0.9.0":{"name":"@andcreations/telegram-bot","version":"0.9.0","author":{"name":"AndCreations"},"license":"MIT","_id":"@andcreations/telegram-bot@0.9.0","maintainers":[{"name":"mikolajgucki","email":"mikolaj.gucki@gmail.com"}],"homepage":"https://github.com/andcreations/telegram-bot","bugs":{"url":"https://github.com/andcreations/telegram-bot/issues"},"dist":{"shasum":"0294df72ae4dedee795eb1979d712f3cf70bb0fd","tarball":"https://registry.npmjs.org/@andcreations/telegram-bot/-/telegram-bot-0.9.0.tgz","fileCount":50,"integrity":"sha512-1JgZiqDOiSzf+yMm4QyYpqWG8nw9bnZoRwq78HSKR7C1o4qhLfVhZjGy+Nie4QnBDc9LhlRAMQv7dTfSsCEVfg==","signatures":[{"sig":"MEQCIGY1AD7yPwMHHcg9vIKaQ7Mb/+rEsTWUdP34df6R7nQ3AiBshXdXesrX9LFuA890afys471KGQGRvNES+VrulVuFww==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":33034},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"985b8b10af7c9e3950d2038ea1b10929a082261d","private":false,"scripts":{"build":"tsc","clean":"rm -rf dist && rm -rf node_modules","rebuild":"rm -rf dist && rm -rf node_modules && npm run build"},"_npmUser":{"name":"mikolajgucki","email":"mikolaj.gucki@gmail.com"},"repository":{"url":"git+https://github.com/andcreations/telegram-bot.git","type":"git"},"_npmVersion":"10.9.2","description":"Telegram bot client","directories":{},"_nodeVersion":"22.15.0","dependencies":{"axios":"^0.24.0","form-data":"^4.0.0","typescript":"^4.0.3","@andcreations/common":"^0.1.15"},"_hasShrinkwrap":false,"devDependencies":{"@types/node":"^14.11.5"},"_npmOperationalInternal":{"tmp":"tmp/telegram-bot_0.9.0_1771390892448_0.3090508471848574","host":"s3://npm-registry-packages-npm-production"}},"0.10.0":{"name":"@andcreations/telegram-bot","version":"0.10.0","description":"Telegram bot client","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc","clean":"rm -rf dist && rm -rf node_modules","rebuild":"rm -rf dist && rm -rf node_modules && npm run build"},"author":{"name":"AndCreations"},"license":"MIT","private":false,"dependencies":{"@andcreations/common":"^0.1.15","axios":"^0.24.0","form-data":"^4.0.0","typescript":"^4.0.3"},"devDependencies":{"@types/node":"^14.11.5"},"repository":{"type":"git","url":"git+https://github.com/andcreations/telegram-bot.git"},"bugs":{"url":"https://github.com/andcreations/telegram-bot/issues"},"homepage":"https://github.com/andcreations/telegram-bot","_id":"@andcreations/telegram-bot@0.10.0","gitHead":"14b687bbebf244d37a5786779acb4cf15e2b3702","_nodeVersion":"20.19.4","_npmVersion":"10.8.2","dist":{"integrity":"sha512-N2dTtdRkqjSPNHzfmPsbPE542P6cVPHQpzT834ptbFE6ef3GER7HSlF5PuzSCAXGF6AdhLMZrLXIUY283MYp3g==","shasum":"77e0d257b9045fb57d767b1a2e251b1c5fd9ed9e","tarball":"https://registry.npmjs.org/@andcreations/telegram-bot/-/telegram-bot-0.10.0.tgz","fileCount":56,"unpackedSize":36109,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDZwxVSN0FQKVPfTzGPn2/qKhKifytoZFFACAiQgYL6FAIgOA6JAxqzjoAHWc5/a4cwBhuLuIbCZifvcPL1mqtm8s4="}]},"_npmUser":{"name":"mikolajgucki","email":"mikolaj.gucki@gmail.com"},"directories":{},"maintainers":[{"name":"mikolajgucki","email":"mikolaj.gucki@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/telegram-bot_0.10.0_1775105078693_0.3644549635489305"},"_hasShrinkwrap":false}},"time":{"created":"2025-12-10T20:33:19.965Z","modified":"2026-04-02T04:44:38.985Z","0.8.0":"2025-12-10T20:33:20.174Z","0.9.0":"2026-02-18T05:01:32.598Z","0.10.0":"2026-04-02T04:44:38.838Z"},"bugs":{"url":"https://github.com/andcreations/telegram-bot/issues"},"author":{"name":"AndCreations"},"license":"MIT","homepage":"https://github.com/andcreations/telegram-bot","repository":{"type":"git","url":"git+https://github.com/andcreations/telegram-bot.git"},"description":"Telegram bot client","maintainers":[{"name":"mikolajgucki","email":"mikolaj.gucki@gmail.com"}],"readme":"# Telegram bot\n\nTelegram bot is a package allowing an application to act as a Telegram bot. The main class is `TelegramBot` which takes a bot token as argument:\n\n```javascript\nconst { TelegramBot } = require('@andcreations/telegram-bot');\n\nconst bot = new TelegramBot('123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11');\n```\n\n## Getting messages\n\nMessages entered by users can be retrived from Telegram servers either with [`getUpdates`](https://core.telegram.org/bots/api#getupdates) or via a [webhook](https://core.telegram.org/bots/api#setwebhook). Either of the methods of getting updates can be used at the same time.\n\nGetting updates in an interval manner is straightforward:\n\n```javascript\nasync function processUpdate(update) {\n  const { message } = update;\n  const { text } = message; // entered message\n  const { username } = message.from; // user who entered the message\n  const { id } = message.chat; // identifier of the chat\n  // process the message and send response here\n}\n\nlet offset = await restoreOffset();\nsetInterval(async () => {\n  const updates = await bot.getUpdates(offset);\n  for (const update of updates) {\n    await processUpdate(update);\n  }\n  offset = TelegramBot.getNextUpdateId(updates);\n  await storeOffset(offset);\n}, INTERVAL);\n```\n\nNote the `offset` variable passed to `getUpdates()`. This mechanism allows to get only new updates not yet processed. The offset can be undefined when getting updates for the first time. In the snippet above `restoreOffset()` can simply return undefined.\n\nIf a webhook has been previously set, it needs to be deleted using `deleteWebhook()`. Otherwise, the Telegram server will report an error:\n\n```javascript\nawait bot.deleteWebhook();\n```\n\n### Webhook\n\nA webhook requires a secure HTTPS endpoint publicly available. When a webhook is set, Telegram will send updates to the endpoint every time a user sends a message to the bot. The below snippet shows how to set a webhook:\n\n```javascript\nconst webhook = {\n  url: 'https://api.your-application.io/telegram/webhook?token=HoxIshyW8dEtrxvUYoUtJmKAhNqeIW43',\n  certificate: '/home/scott/.telegram-bot/ca.cert.pem'\n};\n\nawait bot.setWebhook(webhook);\n```\n\n`url` is the URL to which Telegram will send updates. `ceritifcate` is a path to a CA certificate used to sign the web server key and certificate. Telegram uses the CA certificate to verfiy that it talks to the proper web server.\n\nThe `token` parameter is a security token and should be kept secret. The handler of requests `/telegram/webhook` in the application should accept requests only with a valid token. This way only the Telegram server can talk to the endpoint and no one can send fake updates without the token.\n\nA webhook can be deleted using `deleteWebhook()`. From now on, the Telegram server will not send any updates.\n\n```javascript\nawait bot.deleteWebhook();\n```\n\n### Webhook information\n\nInformation on the currently set webhook can be retrieved using `getWebhookInfo()`. In particular, the webhook information provides the last error message which allows to troubleshoot setting up a webhook.\n\n```javascript\nconst info = await bot.getWebhookInfo();\n\nif (info.last_error_message) {\n  console.log(`Last error: ${info.last_error_message}`);\n}\nelse {\n  console.log('No last error');\n}\n```\n\n## Sending messages\n\nA message is sent to a user via the `sendMessage()` method. The method takes an object with three fields:\n* `chat_id`: identifier of a chat (user) to which to send a message,\n* `text`: text containing the message,\n* `entities`: entities allowing to format a message.\n\n### Message builder\n\nA message can be easily built using `TelegramMessageBuilder`. It supports normal, code and bold formatting. An example is given below. Note that it takes `username` and `chat_id` from an update.\n```javascript\nconst { TelegramMessageBuilder } = require('@andcreations/telegram-bot');\n\nconst builder = new TelegramMessageBuilder();\nbuilder\n  .normal('Hi ')\n  .bold(`${update.message.from.username}!`)\n  .newLine()\n  .normal('Make yourself comfortable.');\n\nawait bot.sendMessage({\n  chatId: update.message.chat.id,\n  ...builder.build(),\n});\n```\n\n## Deleting messages\n\nA single message or multiple messages from a single chat can be deleted using the following methods:\n\n```javascript\nconst chatId = 2333444555;\nconst msgId = 666;\nawait bot.deleteMessage(chatId, msgId);\n\nconst msgIds = [777, 888];\nawait bot.deleteMessages(chatId, msgIds);\n```\n\n## Telegram commands\n\nWhen a user starts a message with slash, Telegram displays matching bot commands. These can be set via the method `setCommands()`:\n```javascript\nawait bot.setCommands([\n  {\n    command: 'start',\n    description: 'Say Hi!',\n  },\n  {\n    command: 'ping',\n    description: 'Ping the server',\n  },\n  {\n    command: 'controllers',\n    description: 'List controllers',\n  },\n])\n```","readmeFilename":"README.md"}