0

I'm learning how to make a telegram bot. If i navigate to my site https://telebot-delta.vercel.app/api/app , it permanently displays error 500. When I send a message to the bot, I only get a reply after i refresh the page. Is this a bug in serverless functions, or something to do with polling/webhooks maybe?

This is my code.

const TelegramBot = require("node-telegram-bot-api");

// Replace 'YOUR_TELEGRAM_BOT_TOKEN' with the token obtained from BotFather.
const token = "YOUR_TELEGRAM_BOT_TOKEN";

// Create a new Telegram bot instance
const bot = new TelegramBot(token, { polling: true });

// Listen for incoming messages
bot.on("message", (msg) => {
    const chatId = msg.chat.id;
    const message = msg.text;
    bot.sendMessage(msg.chat.id, "Hello dear user");
});

This is the error message in the logs.

error: [polling_error] {"code":"ETELEGRAM","message":"ETELEGRAM: 404 Not Found"}
error: [polling_error] {"code":"ETELEGRAM","message":"ETELEGRAM: 404 Not Found"}
No exports found in module "../api/replybot.js".
Did you forget to export a function or a server?
RequestId: 8a9ffc2a-876c-4183-b9ee-1241a4e90e95 Error: Runtime exited with error: exit status 1
Runtime.ExitError

This is the error shown in the terminal when deployed locally.

file:///C:/Users/myusername/AppData/Roaming/npm/node_modules/vercel/node_modules/@vercel/node/dist/serverless-functions/serverless-handler.mjs:69
        return listener(req, res);
               ^
TypeError: listener is not a function

This is the function throwing the error apparently, but i have no idea what it does. It is inside the vercel package from npm, and I don't know how I'm interacting with it that is causing this problem.

async function compileUserCode(entrypointPath, options) {
    const id = isAbsolute(entrypointPath)
        ? pathToFileURL(entrypointPath).href
        : entrypointPath;
    let listener = await import(id);
    /**
     * In some cases we might have nested default props due to TS => JS
     */
    for (let i = 0; i < 5; i++) {
        if (listener.default)
            listener = listener.default;
    }
    if (HTTP_METHODS.some(method => typeof listener[method] === 'function')) {
        if (NODE_MAJOR < 18) {
            throw new Error('Node.js v18 or above is required to use HTTP method exports in your functions.');
        }
        const { getWebExportsHandler } = await import('./helpers-web.js');
        return getWebExportsHandler(listener, HTTP_METHODS);
    }
    return async (req, res) => {
        if (options.shouldAddHelpers)
            await addHelpers(req, res);
        return listener(req, res);
    };
}

This is my file structure.

image

Dlorej
  • 83
  • 1
  • 5

0 Answers0