[英]How to send answers in chat bot at the certain time node.js nlp.js direct conector
Hello) I hope my question is written right)你好)我希望我的问题写对了)
I use node.js, nlp.js, direct conector.我使用 node.js,nlp.js,直接连接器。 Right now working with this repository: https://github.com/jesus-seijas-sp/nlpjs-examples
现在正在使用这个存储库: 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) (停顿 2 秒)
Bot: work机器人:工作
I tried to use setTimeout and also make intervals in index.js and pipelines.md, but maybe i did it wrong.我尝试使用 setTimeout 并在 index.js 和 pipelines.md 中设置间隔,但也许我做错了。 Nothing worked and sometimes code was broken.
没有任何效果,有时代码被破坏了。
There in folders quickstart/08.Webchat in file index.js i wrote this:在 index.js 文件中的 quickstart/08.Webchat 文件夹中,我写道:
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);
})();
Here is an answer with timer and several responses in index.js:这是一个带有计时器的答案和 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:在 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"}
]
}
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.