A simple Node.js module to send messages to Telegram chats using a bot.
Install the package with NPM:
npm install telegram-snippet-post
To use this module, you will need a Telegram bot token and the chat ID of the recipient chat. Then, you can send a message as follows:
const sendTelegramPost = require('telegram-snippet-post');
const token = 'YOUR_TELEGRAM_BOT_TOKEN'; // Replace with your Telegram bot token
const chatId = 'YOUR_CHAT_ID'; // Replace with your chat ID
const message = 'Your message here';
sendTelegramPost(token, chatId, message)
.then((response) => console.log('Message sent:', response))
.catch((error) => console.error('Error:', error));
This module exports a single function sendTelegramPost
:
Sends a message to a Telegram chat.
token
- String - Your Telegram bot token.chatId
- String - The chat ID where the message will be sent.message
- String - The content of the message to be sent.
- A Promise that resolves to the response data from Telegram.
If the message fails to send, the function will throw an error with the message "Failed to send message to Telegram: [Error message]".