[英]How to send answers in chat bot at the certain time node.js nlp.js direct conector
你好)我希望我的问题写对了)
我使用 node.js,nlp.js,直接连接器。 现在正在使用这个存储库: https://github.com/jesus-seijas-sp/nlpjs-examples
我的任务是让机器人在特定时间发送消息。 如何实现这一点?:
用户:工作?
机器人:是的
(停顿 2 秒)
机器人:工作
我尝试使用 setTimeout 并在 index.js 和 pipelines.md 中设置间隔,但也许我做错了。 没有任何效果,有时代码被破坏了。
在 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);
})();
这是一个带有计时器的答案和 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)
});
}
在 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.