1

Hello) I hope my question is written right)

I use node.js, nlp.js, direct conector. Right now working with this repository: https://github.com/jesus-seijas-sp/nlpjs-examples

I have task to make bot send messeges in the certain time. How to realize this?:

User: Work?
Bot: Yes
(pause 2 seconds)
Bot: work

I tried to use setTimeout and also make intervals in index.js and pipelines.md, but maybe i did it wrong. Nothing worked and sometimes code was broken.

There in folders quickstart/08.Webchat in file index.js i wrote this:

const { dockStart } = require('@nlpjs/basic');

(async () => { const dock = await dockStart({ use: ['Basic']});

const nlp = dock.get('nlp');

nlp.addLanguage('en');

nlp.addDocument('en', 'Jack', 'greetings.jack');
nlp.addAnswer('en', 'greetings.jack', 'Hi, Jack');

await nlp.train();

const response = await nlp.process('en', 'I should go now');
console.log(response);
})();

1 Answer 1

1

Here is an answer with timer and several responses in index.js:

const { dockStart } = require('@nlpjs/basic');

async function main(){
    const dock = await dockStart({ use: ['Basic']});
    const nlp = dock.get('nlp');
    await nlp.addCorpus('./frases.json');
    await nlp.train();
    console.log("Hello! I am bot!");
    console.log("Please write your message:");

    const stdin = process.openStdin();
    stdin.addListener("data", async (user_phrase) => {

        const {answer} = await nlp.process('en', user_phrase.toString().trim());
        console.log(`Bot: ${answer}`);

        const messages = answer.split("@@@");
        messages.forEach((msg) => {
            console.log(msg);
        })
        setTimeout(() => console.log(`Bot: ${messages[0]}`), NOTIFY_INTERVAL)
    });
}

In farses.json:

{
    "name": "Dialog",
    "locale": "en-US",
    "data": [
        {
          "intent": "dialog.isbotwork",
          "utterances": [
              "do you work?",
              "hey",
              "time to work"
            ],
            "answers": [
              {"answer": "Hello! I am working fine! Nice to see you!"},
              {"answer": "First answer!@@@Second answer@@@Third answer"}
            ]
        }
    ]
}

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.