Send message using telegram bot and api.
npm install telegram-message-sendThis library provides a simple class-based interface for sending messages and various media types to a Telegram bot.
#### With yarn
``bash`
yarn add telegram-message-send
#### With NPM
`bash`
npm install telegram-message-send
`typescript
import { TelegramBot } from 'telegram-message-send';
const botKey = 'YOUR_BOT_KEY';
const chatId = 'YOUR_CHAT_ID';
const bot = new TelegramBot(botKey, chatId);
async function sendMessages() {
await bot.sendMessage('Hello World');
await bot.sendPhoto('https://avatars.githubusercontent.com/u/100691616?s=200&v=4', 'Custom Caption');
await bot.sendAudio('https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3', 'Custom Caption');
await bot.sendDocument('https://s2.q4cdn.com/175719177/files/doc_presentations/Placeholder-PDF.pdf', 'Custom Caption');
await bot.sendLocation(41.084677113651814, 29.00455392606353);
await bot.sendContact('Ilker Balcilar', '+905555555555');
await bot.sendPoll('Which one would you prefer', ['Javascript', 'Typescript']);
await bot.sendDice('dice'); // or 'dart', 'basketball', etc.
}
sendMessages();
`
Create a Telegram bot with BotFather before connecting your bot to Telegram.
1. Start a new conversation with the BotFather.
2. Send /newbot to create a new Telegram bot.botKey
3. When asked, enter a name for the bot.
4. Copy and save the Telegram bot's access token (your ) for later steps.
1. In your Telegram account, search for “@myidbot” or open this link t.me/myidbot on your smartphone.
2. Start a conversation with that bot and type /getid. You will get a reply back with your user ID.chatId
3. Note the user ID (your ).
> In order to receive a message from the bot, you must first send a message to the bot and create a chat.
* botKey (string, required): Your Telegram bot's access token.
* chatId (string, required): The ID of the chat to send messages to.
* text (string, required): The message text to send.
* photoURL (string, required): URL of the photo to send.
* caption (string, optional): Photo caption.
* audioURL (string, required): URL of the audio file to send.
* caption (string, optional): Audio caption.
* documentURL (string, required): URL of the document to send.
* caption (string, optional): Document caption.
* videoURL (string, required): URL of the video to send.
* caption (string, optional): Video caption.
* gifURL (string, required): URL of the GIF to send.
* caption (string, optional): GIF caption.
* latitude (number, required): Latitude of the location.
* longitude (number, required): Longitude of the location.
* name (string, required): Contact's name.
* phoneNumber (string, required): Contact's phone number.
* question (string, required): Poll question.
* options (string[], required): Array of poll options.
* type (string, optional): Type of dice to send ('dice', 'dart', 'basketball', 'football', 'bowling', 'slot'). Defaults to 'dice'.
``