deno-telegram-bot-api
🦕 wrapper for Telegram Bot API
Join Discord channel https://discord.gg/6VMcmxAnT8
Features
- Fully typed API follows the official Telegram API (v5.0)
- Minimal domain-specific knowledge required
- Polling and Webhook server for getting updates
- A simple way for sending media files
Examples
For all examples check the examples directory
Send Text Message
import { TelegramBot, UpdateType } from "https://deno.land/x/telegram_bot_api/mod.ts"
import "https://deno.land/x/dot_env@0.2.0/load.ts"
const TOKEN = Deno.env.get("TOKEN");
if (!TOKEN) throw new Error("Bot token is not provided");
const bot = new TelegramBot(TOKEN);
bot.on(UpdateType.Message, async (message: any) => {
const text = message.message.text || "I can't hear you";
await bot.sendMessage({ chat_id: message.message.chat.id, text: `echo ${text}` })
});
bot.run({
polling: true,
});
Send Text File
The example of a bot which responds with a file containing a user message inside.
import { TelegramBot, UpdateType } from "https://deno.land/x/telegram_bot_api/mod.ts"
import "https://deno.land/x/dot_env@0.2.0/load.ts"
const TOKEN = Deno.env.get("TOKEN");
if (!TOKEN) throw new Error("Bot token is not provided");
const bot = new TelegramBot(TOKEN);
bot.on(UpdateType.Message, async (message: any) => {
const text = message.message.text || "I can't hear you";
await bot.sendDocument({
chat_id: message.message.chat.id,
document: new File([text], "echo.txt"),
});
});
bot.run({
polling: true,
});
Let's run the example above right from the terminal:
# MacOS, Linux
TOKEN=your-bot-token deno run --allow-net --allow-env https://deno.land/x/telegram_bot_api/examples/sending-files/01-simple-media.ts
# Windows
set TOKEN=your-bot-token && deno run --allow-net --allow-env https://deno.land/x/telegram_bot_api/examples/sending-files/01-simple-media.ts