如何增加网络聊天中打字动画的显示时间?

bil*_*ton 1 botframework

当我的机器人在文本之间有多行要说时,我想显示打字指示器。我正在使用ActivityTypes.Typing,但在网络聊天(和模拟器)中消失得太快,我什至看不到它。在 Teams 中存在的时间较长,但不多。有没有办法设置动画出现的时间,或者至少有办法让它持续更长时间?在我的代码中,我将其作为离散活动发送,如下所示:

async getEmployeeTitle(step) {
    await step.context.sendActivity('OK, first I will need some additional information about the employee.');
    await step.context.sendActivity({ type: ActivityTypes.Typing });
    return await step.prompt(TEXT_PROMPT, `What is the employee's **Job Title**?`);
}
Run Code Online (Sandbox Code Playgroud)

tdu*_*ord 5

在 Web Chat v4.5 中,无法设置打字指示器持续时间;然而,在月底发布的 v4.6 中,您可以在网络聊天的样式选项中设置打字指示器持续时间。

网络聊天 v4

const styleOptions = {
  typingAnimationDuration: 5000
};

window.WebChat.renderWebChat(
  {
     directLine: window.WebChat.createDirectLine({ token }),
     styleOptions
  },
  document.getElementById('webchat')
);

Run Code Online (Sandbox Code Playgroud)

默认情况下,网络聊天会显示键入指示器5000 毫秒,或者直到收到来自机器人的另一个活动。如果您想在活动之间添加更多时间,我建议在发送活动之间添加延迟。

BotFramework SDK v4(节点)

async getEmployeeTitle(step) {
    await step.context.sendActivity('OK, first I will need some additional information about the employee.');
    await step.context.sendActivity({ type: ActivityTypes.Typing });
    await context.sendActivity({ type: 'delay', value: 3000 });  // Delay 3000 milliseconds
    return await step.prompt(TEXT_PROMPT, `What is the employee's **Job Title**?`);
}
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助!