Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

316
Visualizações
integrate node-telegram-bot-api with nlp.js QnA

I'm creating a telegram bot. I want to integrate nlp.js to have a QnA. At the moment I have this code:

#!/usr/bin/env node

const TelegramBot = require('node-telegram-bot-api');
const process = require('process');
const path = require('path');
const { dockStart } = require('@nlpjs/basic');
const axios = require('axios').default;
//const qnaFile = path.dirname()

let chatId;
let currentUser; 
let incomingMessage;
let response;
let dock;
let nlp;

// replace the value below with the Telegram token you receive from @BotFather
const token = process.env.TELEGRAM_BOT_TOKEN || '5252802474:AA';
// Create a bot that uses 'polling' to fetch new updates
const bot = new TelegramBot(token, {polling: true});  

bot.onText(/\/echo(.+)/, async (msg, match) => {
  // 'msg' is the received Message from Telegram
  // 'match' is the result of executing the regexp above on the text content
  // of the message
  //const chatId = msg.chat.id;
  console.log(`CONSOLE LOG onText:  \n ${match, msg}`);
});

bot.on('message', async (msg) => {
  chatId = msg.chat.id;
  currentUser = msg.from.first_name;
  incomingMessage = msg.text;

  dock = await dockStart();
  const nlp = await dock.get('nlp');
  await nlp.train();
  response = await nlp.process('en', incomingMessage);
  
  // Listen for any kind of message. There are different kinds of messages.  
  console.log(response);
  console.log(msg);
  // send a message to the chat acknowledging receipt of their message
  await bot.sendMessage(chatId, `${response.answer}`);
});

How I can add new intents and utterances by using the user input incoming messages? From the documentation of the libary I don't see any reference about dynamically updating the corpus file?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda