如何为机器人响应添加延迟,使其在 Microsoft Bot Framework Node.js 中感觉更真实?
How to add a delay to bot responses, so it feels more real in Microsoft Bot Framework Node.js?
有没有办法让响应稍微延迟一点?所以机器人感觉更真实,就像它在打字一样?一点点。
现在测试人员的反应是它太快了。
这很好,但是……感觉太“冷”了。有一点时间看起来机器人正在打字,感觉会更加温暖和模糊::)
我需要在两条线之间添加延迟
session.send("Account created successfully");
session.send("Please login");
下面是完整代码
var restify = require('restify');
var builder = require('botbuilder');
var botbuilder_azure = require("botbuilder-azure");
// Setup Restify Server
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
// Create chat connector for communicating with the Bot Framework Service
var connector = new builder.ChatConnector({
appId: process.env.MicrosoftAppId,
appPassword: process.env.MicrosoftAppPassword,
openIdMetadata: process.env.BotOpenIdMetadata
});
// Listen for messages from users
server.post('/api/messages', connector.listen());
var bot = new builder.UniversalBot(connector);
bot.on('conversationUpdate', (message) => {
if (message.membersAdded) {
message.membersAdded.forEach(function (identity) {
if (identity.id === message.address.bot.id) {
bot.beginDialog(message.address, 'accountCheck');
}
});
}
});
bot.dialog('accountCheck', [
function (session, results, next) {
session.send("Account created successfully");
session.send("Please login");
}
]).endConversationAction("stop",
"",
{
matches: /^cancel$|^goodbye$|^exit|^stop|^close/i
// confirmPrompt: "This will cancel your order. Are you sure?"
}
);
您可以在客户端或后端使用 timeout
。
function (session, results, next) {
session.send("Account created successfully. Wait 10 seconds...");
setTimeout(function() {
session.send("Please login");
}, 10000); //10 seconds
}
您可以不添加延迟,而是发送一个输入指示符
session.sendTyping();
更多信息请见https://docs.microsoft.com/en-us/bot-framework/nodejs/bot-builder-nodejs-send-typing-indicator
您可以使用session.delay()
bot.dialog('accountCheck', [
function (session, results, next) {
session.send("Account created successfully");
// 0.5 sec delay between messages
session.delay(500)
session.send("Please login");
}
]).endConversationAction("stop",
"",
{
matches: /^cancel$|^goodbye$|^exit|^stop|^close/i
// confirmPrompt: "This will cancel your order. Are you sure?"
}
);
È=18=ÈтÈ=22=Èтбот 框架SDK вч:È=24=ÈтÈ=14=Èт
w=10=sh
w=18=shw=12=shw=14=sh
w=18=shw=22=shbot Framework SDK v3:
session.sendTyping()
我使用 nodejs SDK 4.0 实现的方法是在 SendActivities 中使用 ActivityTypes.Typing
,如下所示
await context.sendActivities([
{type: ActivityTypes.Typing},
{type: 'delay', value:2000},
{type: ActivityTypes.Message, text: 'Bot Response goes here is only text else send attachments as reply'}])
尝试在Change SendActivity to SendActivities with dealy中添加以上代码
尝试在模拟器中测试。
有没有办法让响应稍微延迟一点?所以机器人感觉更真实,就像它在打字一样?一点点。 现在测试人员的反应是它太快了。 这很好,但是……感觉太“冷”了。有一点时间看起来机器人正在打字,感觉会更加温暖和模糊::)
我需要在两条线之间添加延迟
session.send("Account created successfully");
session.send("Please login");
下面是完整代码
var restify = require('restify');
var builder = require('botbuilder');
var botbuilder_azure = require("botbuilder-azure");
// Setup Restify Server
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
// Create chat connector for communicating with the Bot Framework Service
var connector = new builder.ChatConnector({
appId: process.env.MicrosoftAppId,
appPassword: process.env.MicrosoftAppPassword,
openIdMetadata: process.env.BotOpenIdMetadata
});
// Listen for messages from users
server.post('/api/messages', connector.listen());
var bot = new builder.UniversalBot(connector);
bot.on('conversationUpdate', (message) => {
if (message.membersAdded) {
message.membersAdded.forEach(function (identity) {
if (identity.id === message.address.bot.id) {
bot.beginDialog(message.address, 'accountCheck');
}
});
}
});
bot.dialog('accountCheck', [
function (session, results, next) {
session.send("Account created successfully");
session.send("Please login");
}
]).endConversationAction("stop",
"",
{
matches: /^cancel$|^goodbye$|^exit|^stop|^close/i
// confirmPrompt: "This will cancel your order. Are you sure?"
}
);
您可以在客户端或后端使用 timeout
。
function (session, results, next) {
session.send("Account created successfully. Wait 10 seconds...");
setTimeout(function() {
session.send("Please login");
}, 10000); //10 seconds
}
您可以不添加延迟,而是发送一个输入指示符
session.sendTyping();
更多信息请见https://docs.microsoft.com/en-us/bot-framework/nodejs/bot-builder-nodejs-send-typing-indicator
您可以使用session.delay()
bot.dialog('accountCheck', [
function (session, results, next) {
session.send("Account created successfully");
// 0.5 sec delay between messages
session.delay(500)
session.send("Please login");
}
]).endConversationAction("stop",
"",
{
matches: /^cancel$|^goodbye$|^exit|^stop|^close/i
// confirmPrompt: "This will cancel your order. Are you sure?"
}
);
session.sendTyping()
我使用 nodejs SDK 4.0 实现的方法是在 SendActivities 中使用 ActivityTypes.Typing
,如下所示
await context.sendActivities([
{type: ActivityTypes.Typing},
{type: 'delay', value:2000},
{type: ActivityTypes.Message, text: 'Bot Response goes here is only text else send attachments as reply'}])
尝试在Change SendActivity to SendActivities with dealy中添加以上代码 尝试在模拟器中测试。