Reputation: 1
import { TelegramBot, UpdateType } from "https://deno.land/x/telegram_chatbot/mod.ts"; <--- ERROR
import "https://deno.land/x/[email protected]/load.ts"
const TOKEN = ("MYTOKENID");
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,
});
[{ "resource": "/Users/bgrnaymane/Documents/GitHub/crypto_price_api/telegrambot.ts", "owner": "typescript", "code": "2691", "severity": 8, "message": "Ein Importpfad darf nicht mit einer Erweiterung ".ts" enden. Importieren Sie ggf. stattdessen "https://deno.land/x/telegram_chatbot/mod".", "source": "ts", "startLineNumber": 2, "startColumn": 41, "endLineNumber": 2, "endColumn": 86 }]
Ein Importpfad darf nicht mit einer Erweiterung ".ts" enden. Importieren Sie ggf. stattdessen "https://deno.land/x/telegram_chatbot/mod".
Upvotes: 0
Views: 514
Reputation: 71
I don't know much about the library you are using currently but there is a much better option availaible for making telegram bots and it's written in deno and typescript, but it supports deno and node both due to transpiling. The library is called grammy also it has a ton of plugins and a wonderful team of devs working to improve it.
A code snippet from the official docs to show how cleaner the code is in grammy.
import { Bot } from "https://deno.land/x/grammy/mod.ts";
// Create an instance of the `Bot` class and pass your authentication token to it.
const bot = new Bot(""); // <-- put your authentication token between the ""
// You can now register listeners on your bot object `bot`.
// grammY will call the listeners when users send messages to your bot.
// Handle the /start command.
bot.command("start", (ctx) => ctx.reply("Welcome! Up and running."));
// Handle other messages.
bot.on("message", (ctx) => ctx.reply("Got another message!"));
// Now that you specified how to handle messages, you can start your bot.
// This will connect to the Telegram servers and wait for messages.
// Start the bot.
bot.start();
you can give it a try if you want ...also the link to the community chat.
Upvotes: 4