我想从机器人"Are you there after X mins"发送一条消息,当他们没有进一步的用户输入到机器人时



我正在使用带有c#的Bot Framework v4,并部署到Slack通道。我想使用Azure功能在机器人程序中或外部创建一个计时器。在x分钟内没有用户输入的情况下,机器人应该发送一条消息,比如"你在吗?">

在互联网上读了很多文章后,我找不到想要的解决方案

我厌倦了遵循这个自动机器人显示评级卡几秒钟后采取用户反馈

但不完全理解这个人在那里说的话。有人能帮我吗?

我的方法适用于Directline Webchat,但您可能可以将此概念用于适用于Slack的解决方案。

当使用botframework网络聊天时,您可以设置一个自定义存储来跟踪不活动状态。在下面的示例中,我将页面标题"通知"与发送消息相结合。但您可以简单地设置间隔并发送消息,而不更改任何页面标题。

let interval;
var PageTitleNotification = {
Vars:{
OriginalTitle: document.title,
Interval: null
},    
On: function(notification, intervalSpeed){
var _this = this;
_this.Vars.Interval = setInterval(function(){
document.title = (_this.Vars.OriginalTitle == document.title)
? notification
: _this.Vars.OriginalTitle;
}, (intervalSpeed) ? intervalSpeed : 1000);
},
Off: function(){
clearInterval(this.Vars.Interval);
document.title = this.Vars.OriginalTitle;   
}
}
// We are using a customized store to add hooks to connect event
const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
if (action.type === 'WEB_CHAT/SEND_MESSAGE') {
// Message sent by the user
PageTitleNotification.Off();
clearTimeout(interval);
} else if (action.type === 'DIRECT_LINE/INCOMING_ACTIVITY' && action.payload.activity.name !== "inactive") {
// Message sent by the bot
clearInterval(interval);
interval = setTimeout(() => {
// Change title to flash the page
PageTitleNotification.On('Are you still there?');
// Notify bot the user has been inactive
dispatch({
type: 'WEB_CHAT/SEND_EVENT',
payload: {
name: 'inactive',
value: ''
}
});
}, 300000)
}
return next(action);
});

当你使用Slack频道时,面临的挑战是你不能在Slack客户端注入这样的东西,所以你需要从外部进行。我能给你的最好的指导是从主动通知样本开始。你需要通过turnContext.getConversationReference()之类的东西从turnContext获取会话引用并存储它。然后你可以将它发送到一个函数并启动一个计时器。如果函数在您指定的时间段内没有收到另一条参考消息,您可以发送主动消息。

我想你会想在你的机器人中作为一个本地功能来做这件事,而不是Azure功能,因为你想在每次用户发送新消息时重置计时器。我不知道你会如何使用外部Azure功能来跟踪它。希望这足以让你对在Slack频道中实现这一功能有一些想法。

相关内容

最新更新