简体   繁体   中英

how to test Telegram bot built with NodeJS?

I made a Telegram bot with NodeJS (node-telegram-bot-api) but right now I am facing an issue is to how to test the bot. I want to test how the bot responds when a message is given to it, how can I simulate that using Node itself and write automated tests based on that. I feel this is not possible but is here anybody which achieved it? I have already tried researching the internet, didn't find anything satisfactory.

Its very simple if you use telegraf library. You will have all built in telegram api capability and its simple to code.

For example: this bot will respond "Hello There" to every text messages sent to the bot.

const { Telegraf } = require("telegraf");

const bot = new Telegraf("YOUR_BOT_TOKEN_HERE");

bot.on("text", async (ctx) => {
  ctx.reply("Hello There");
});

bot.launch();
process.once("SIGINT", () => bot.stop("SIGINT"));
process.once("SIGTERM", () => bot.stop("SIGTERM"));

You can make it smart and intelligent with hooking it up with NLP library.

I created a tutorial on how to create build a smart telegram chatbot with AI/ML capability that using WIT.AI as the NLP engine to help to inteprete message

https://youtu.be/YIeEermeXEU

You can download the source code as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM