{"_id":"@didinsino/telegram-bot","_rev":"9-70bb4e2c0f80fc6b1008ec5d66396595","name":"@didinsino/telegram-bot","dist-tags":{"latest":"2.0.1"},"versions":{"2.0.0":{"name":"@didinsino/telegram-bot","version":"2.0.0","keywords":["telegram","bot","nodejs","javascript","typescript"],"author":{"name":"Didin Sino"},"license":"ISC","_id":"@didinsino/telegram-bot@2.0.0","maintainers":[{"name":"didinsino","email":"di2nsino@gmail.com"}],"homepage":"https://github.com/didinsino/telegram-bot#readme","bugs":{"url":"https://github.com/didinsino/telegram-bot/issues"},"dist":{"shasum":"117f1b345f2f246664679acefe34d22a57d2b97a","tarball":"https://registry.npmjs.org/@didinsino/telegram-bot/-/telegram-bot-2.0.0.tgz","fileCount":6,"integrity":"sha512-qm/9ryysEdVSuAVHd70LuCNYeSoFc8eqzU20cN/qYsCDOrhCpPZqYuy/D4diEfoSfPJFT5JaEE5K4qLft808Iw==","signatures":[{"sig":"MEUCIGMaTqLGbaJr0NMlVLt9/J7Z2IGJtce1hbgDrGPV8vi0AiEAnGlJtj57PA1XvygAImZCk9suydTzKGImdk5f0wWZgvI=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":28306,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkKbGyACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmq1GRAAk65mKA35YGb2xk+NMN4aE0ywHEju5mJ+Op6I2BsPPU1BunjE\r\nOUTsrzylizqaIczwxtHTHiYcBrT1MrjsxBylR+X657mZ1hGNz6MVurRSKaYp\r\nNf9gnpoUfW947XgYR/9zpxeDvYo99C6Jm4xAWRnq71V1mNJwF7N/IepnDtbk\r\nkGibToKGVNKyGzSaDx6ww21zr85uMC6p2kNenNOS7gYU0gp1Jd+Q73vT2cm/\r\n8+0mscQF0LaqwlKTnJo+e4w5UO5ceiA9zQzArL9+WbpQyJZfOiYwCYO5mfbG\r\nJEmMlBZtI22ouqCYp1HbRK/Cb8s18LwLD9ykWJKRm8B8SFu5FyhEwGHWEEuY\r\npXuQTdAngcoVMVhLUow7jk3PhphBVa9creYAJ4lLmRMeh28yhI6JDysL1vgK\r\nTUs1A6ysL5foEj0HhBf3yh+voxlsEcoP4l4evbrg5isAqkyN0GKpdB4ZoWCm\r\nA5R+gEYhUbGSZYxHvwM4Woo4ZBWGfq4X4abO/SkA/mdqR+QBtllUFDPifdj5\r\nHb5iygSXR27VQqcu+4W8SGFidzPjFghaV4VZBNz1m02o1Yd90IiXaNHf31ZC\r\n25xUxFPsObgs7gq3xw8DGocuc0/kTZpfa0/wofPgd9B7/Tp6gKnRENL/1epD\r\nzoF7NgLnsDbNKLrKIDXAb+6tZwqxToy8b78=\r\n=QshO\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/index.js","type":"commonjs","types":"dist/index.d.ts","gitHead":"ea4d2a0da975090d6c1afda4b378a3f81e0feb59","release":{"branches":["main"]},"scripts":{"build":"tsc && rm -rf dist/types.js","publish":"npm publish --access=public","build:watch":"tsc --watch"},"_npmUser":{"name":"didinsino","email":"di2nsino@gmail.com"},"repository":{"url":"git+https://github.com/didinsino/telegram-bot.git","type":"git"},"_npmVersion":"9.6.0","description":"Simple and lightweight NodeJS library for creating Telegram bots","directories":{},"_nodeVersion":"18.15.0","dependencies":{"axios":"^1.3.4","lodash":"^4.17.21","promise-events":"^0.2.4"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.0.3","@types/node":"^18.15.11","@types/lodash":"^4.14.192"},"_npmOperationalInternal":{"tmp":"tmp/telegram-bot_2.0.0_1680454065871_0.9450499718439438","host":"s3://npm-registry-packages"},"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."},"2.0.1":{"name":"@didinsino/telegram-bot","version":"2.0.1","keywords":["telegram","bot","nodejs","javascript","typescript"],"author":{"name":"Didin Sino"},"license":"ISC","_id":"@didinsino/telegram-bot@2.0.1","maintainers":[{"name":"didinsino","email":"di2nsino@gmail.com"}],"homepage":"https://github.com/didinsino/telegram-bot#readme","bugs":{"url":"https://github.com/didinsino/telegram-bot/issues"},"dist":{"shasum":"1f5ef35e5e2c9de5bd7279ce25af12da2f82c05a","tarball":"https://registry.npmjs.org/@didinsino/telegram-bot/-/telegram-bot-2.0.1.tgz","fileCount":5,"integrity":"sha512-ofaBP913FvJcmve+J9cOLI3zlZAOvNm/IZ81RG8QG8tOPgHLJLsZUqNwWk7TbIu7Vk99VCT7d2Q9tTnQijEzpw==","signatures":[{"sig":"MEYCIQD7TeQrvraj52lYuAFDMAhdRgkDOlE5Lt4DZwQ4artndAIhANXetxIyMZUCpfcjRHKdE5XTjbD4TUCeZb7SF4v8U5Z2","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":27731},"main":"dist/index.js","type":"commonjs","types":"dist/index.d.ts","gitHead":"3541c1a18e28a932c4876e6d4ce41b4a944f96fd","release":{"branches":["main"]},"scripts":{"build":"tsc && rm -rf dist/types.js","publish":"npm publish --access=public","build:watch":"tsc --watch"},"_npmUser":{"name":"didinsino","email":"di2nsino@gmail.com"},"repository":{"url":"git+https://github.com/didinsino/telegram-bot.git","type":"git"},"_npmVersion":"9.6.5","description":"Simple and lightweight NodeJS library for creating Telegram bots","directories":{},"_nodeVersion":"18.15.0","dependencies":{"axios":"^1.3.4","lodash":"^4.17.21","promise-events":"^0.2.4"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.0.3","@types/node":"^18.15.11","@types/lodash":"^4.14.192"},"_npmOperationalInternal":{"tmp":"tmp/telegram-bot_2.0.1_1687682145533_0.7909614149895343","host":"s3://npm-registry-packages"},"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."}},"time":{"created":"2023-04-02T16:47:45.801Z","modified":"2026-01-11T17:40:31.645Z","0.0.0":"2023-03-31T23:20:05.142Z","1.0.0":"2023-04-01T18:37:33.450Z","1.0.2":"2023-04-01T18:50:25.889Z","1.0.3":"2023-04-02T08:56:12.041Z","2.0.0":"2023-04-02T16:47:46.046Z","2.0.1":"2023-06-25T08:35:45.701Z"},"bugs":{"url":"https://github.com/didinsino/telegram-bot/issues"},"author":{"name":"Didin Sino"},"license":"ISC","homepage":"https://github.com/didinsino/telegram-bot#readme","keywords":["telegram","bot","nodejs","javascript","typescript"],"repository":{"url":"git+https://github.com/didinsino/telegram-bot.git","type":"git"},"description":"Simple and lightweight NodeJS library for creating Telegram bots","maintainers":[{"name":"didinsino","email":"di2nsino@gmail.com"}],"readme":"# Telegram Bot API\r\n\r\nSimple and lightweight NodeJS library for creating Telegram bots.\r\n\r\n## Installation\r\n\r\n```sh\r\nnpm install @didinsino/telegram-bot\r\n```\r\n\r\n## Getting started\r\n\r\n```ts\r\nconst { TelegramBot } = require('@didinsino/telegram-bot');\r\n\r\n// replace the value with the Telegram token you receive from @BotFather\r\nconst bot = new TelegramBot('YOUR_TELEGRAM_BOT_TOKEN');\r\n\r\n// Listen for any kind of message. Called first before any other events\r\nbot.on('update', ctx => {\r\n  ctx.name = ctx.message?.from.first_name ?? ctx.callback_query?.from.first_name;\r\n  console.log(JSON.stringify(ctx, null, 2));\r\n});\r\n\r\n// Handler for /start command or start button pressed\r\nbot.start(ctx => {\r\n  ctx.reply(`Welcome, ${ctx.name}. Which one do you prefer?`, {\r\n    buttons_column: 2,\r\n    buttons: [\r\n      {\r\n        text: 'JS',\r\n        callback_data: 'button_Javascript',\r\n      },\r\n      {\r\n        text: 'TS',\r\n        callback_data: 'button_Typescript',\r\n      },\r\n      {\r\n        text: 'Visit Github Repository',\r\n        url: 'https://github.com/didinsino/telegram-bot',\r\n      },\r\n    ],\r\n  });\r\n});\r\n\r\n// Listen for text message\r\nbot.on('text', ctx => {\r\n  ctx.reply(`What do you mean \"${ctx.message.text}?\"\\nTry /help for list of commands`);\r\n  // OR\r\n  // reply incoming message without make new http instance (webhook only)\r\n  // https://core.telegram.org/bots/faq#how-can-i-make-requests-in-response-to-updates\r\n  ctx.directReply(`What do you mean \"${ctx.message.text}?\"\\nTry /help for list of commands`);\r\n});\r\n\r\n// Matches \"/help\"\r\nbot.command('help', async ctx => {\r\n  await ctx.reply('There is no help here');\r\n  await ctx.reply('CAACAgIAAxkBAAMsZChpxIYkc2atNDVJulzOpUeZ_NYAAlIDAAK6wJUFlfhk3Qz2478vBA', null, 'sticker');\r\n});\r\n\r\n// Matches for \"button_aaa\", \"button_bbb\", etc\r\nbot.action(/button_(\\w+)/, ctx => {\r\n  const [, buttonNumber] = ctx.match;\r\n  bot.editMessageText(\r\n    ctx.callback_query.message.chat.id,\r\n    ctx.callback_query.message.message_id,\r\n    `✓ Your choice is: <b>${buttonNumber}</b>`,\r\n    { parse_mode: 'HTML' }\r\n  );\r\n});\r\n\r\nbot.catch(error => {\r\n  console.log(error);\r\n});\r\n\r\n\r\n/* Getting updates from Telegram bot server */\r\n\r\n// Using long polling\r\nbot.startPolling();\r\n\r\n// Using webhook (sample usage for Firebase Functions)\r\nexports.telegramWebhook = functions.https.onRequest(async (req, resp) => {\r\n  try {\r\n    await bot.handleUpdate(req.body);\r\n    const directReply = bot.getdirectReply();\r\n\r\n    if (directReply != null) {\r\n      resp.status(200).send(directReply);\r\n    } else {\r\n      resp.status(200).end();\r\n    }\r\n\r\n  } catch (error) {\r\n    functions.logger.error(error.message);\r\n    resp.status(200).end();\r\n  }\r\n});\r\n```\r\n\r\n\r\n## Usage\r\n\r\n```ts\r\n// Send text message\r\nbot.sendMessage('CHAT_ID', 'Hello there, how are you?')\r\n  .then(result => {\r\n    console.log(`Message sent successfully with ID: ${result.message_id}`);\r\n  })\r\n  .catch(error => {\r\n    console.log(`Error sending message:`, error.message);\r\n  });\r\n\r\n// Sends photo from URL\r\nbot.sendPhoto('CHAT_ID', 'https://images.unsplash.com/photo-1680193966159-e371dff0d82c?fit=crop&w=687&q=80', {\r\n  caption: 'A photo from unsplash.com',\r\n});\r\n\r\n// Sends photo using existing file_id\r\nbot.sendPhoto('CHAT_ID', 'AgACAgQAAxkDAANYZClugC2gtJxq3pbpAAHZYdchdBCcAAJesDEba4lNUfPh5zkPqgshAQADAgADeQADLwQ');\r\n\r\n// Sends document from local file\r\nbot.sendDocument('CHAT_ID', './sample-document.pdf', {\r\n  caption: 'Send document with caption'\r\n});\r\n\r\n// Sends document from buffer\r\nbot.sendDocument('CHAT_ID', fs.readFileSync('./sample-document.pdf'), {\r\n  caption: 'Send document from buffer',\r\n  file_name: 'Custom File Name.pdf',\r\n});\r\n\r\n// Sends stream \r\nbot.sendVideo('CHAT_ID', fs.createReadStream('./sample-video.mp4'));\r\nbot.sendAudio('CHAT_ID', fs.createReadStream('./sample-audio.mp3'));\r\n\r\n// Edit/delete message\r\nbot.editMessageText('CHAT_ID', 'MESSAGE_ID', 'New message text');\r\nbot.editMessageCaption('CHAT_ID', 'MESSAGE_ID', 'New message caption');\r\nbot.deleteMessage('CHAT_ID', 'MESSAGE_ID');\r\n\r\n// Set webhook\r\nbot.setWebhook('https://webhook.url');\r\n// OR\r\nbot.setWebhook({\r\n  url: 'https://webhook.url',\r\n  max_connections: 10,\r\n  ...otherOptions\r\n});\r\n\r\n// Get webhook info\r\nbot.getWebhookInfo();\r\n\r\n// Delete webhook\r\nbot.deleteWebhook(true);\r\n\r\n// Manually get updates\r\nbot.getUpdates({ offset: 12345, limit: 10}).then(updates => {\r\n  // updates.forEach()\r\n});\r\n\r\n// Make custom request\r\nbot.httpRequest(\r\n  'forwardMessage', \r\n  {\r\n    chat_id: 'CHAT_ID',\r\n    message_id: 'MESSAGE_ID'\r\n  }, \r\n  'post',\r\n  ...axiosConfig\r\n)\r\n```\r\n","readmeFilename":"README.md"}