使用 DirectLine 和网络聊天在 bot-framework v4 中发送打字提示 (Node.js)

Send a typing indicator in bot-framework v4 using DirectLine and webchat (Node.js)

Microsoft bot-framework 的官方文档 SDK v4 do not demonstrate how to send a typing indicator (whereas v3 has these instructions)。我正在使用 DirectLine 和 botframework-webchat。

我该怎么做?谢谢!

您可以通过发送类型为 typing 的 activity 来发送输入指示符。详细了解如何 send a typing indicator.

await context.sendActivities([
            { type: ActivityTypes.Typing },
            { type: 'delay', value: 3000 },
            { type: ActivityTypes.Message, text: 'Finished typing' }
        ]);

此外,showTypingMiddleware 可用于自动发送输入指示器。如果您正在寻找更多示例代码,此代码段还将展示如何发送输入指示器。

我相信你应该这样做

await context.sendActivities([
    { type: 'typing' },
    { type: 'delay', value: 2000 },
    { type: 'message', text: 'Your message here' }
]);

我认为你可以在 await 之前添加 OnTurnAsync 函数 base.OnTurnAsync(turnContext, cancellationToken); :

await turnContext.SendActivityAsync(new Activity { Type = ActivityTypes.Typing }, cancellationToken);