c# - BotFramework V4:如何从机器人发送事件并在反应 WebChat 中捕获它?
问题描述
我从我的机器人(.NET SDK)发送了一个名为“locationRequest”的事件
Activity activity = new Activity
{
Type = ActivityTypes.Event,
Name = "locationRequest"
};
await stepContext.Context.SendActivityAsync(activity, cancellationToken);
我想在 WebChat 客户端应用程序中捕获此事件,基于 React 中编码的 minizable-web-chat,并将布尔 locationRequested 设置为 True:
const store = createStore({}, ({ dispatch }) => next => action => {
if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
dispatch({
type: 'WEB_CHAT/SEND_EVENT',
payload: {
name: 'webchat/join',
}
});
}
else if(action.name == 'locationRequest'){
this.setState(() => ({
locationRequested: true
}));
}
return next(action);
});
我无法赶上这个活动,请问有什么想法吗?
解决方案
你走在正确的轨道上。基本上,您可以监视“DIRECT_LINE/INCOMING_ACTIVITY”事件,然后检查传入活动是否具有适当的名称。有关更多详细信息,请查看下面的代码片段和传入事件Web 聊天示例。
const store = createStore({}, ({ dispatch }) => next => action => {
if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
dispatch({
type: 'WEB_CHAT/SEND_EVENT',
payload: {
name: 'webchat/join',
}
});
}
else if(action.type === 'DIRECT_LINE/INCOMING_ACTIVITY'){
if (action.payload.activity.name === 'locationRequest') {
this.setState(() => ({
locationRequested: true
}));
}
}
return next(action);
});
推荐阅读
- excel - Excel 中的股票数据为同一股票提供了两种完全不同的结果。潜在的错误?
- asp.net - IIS Web.config 将一个子文件夹重定向到另一个
- python - TypeError:字符串索引必须是整数(在 lambda 函数中)
- c# - 如何以编程方式更新 Word 字段?
- python - 拆分包含“.”的字符串 不使用内置函数
- python-3.x - 如何将广播数据包发送到特定的 MAC 地址
- javascript - ASP.NET MVC 在按钮单击错误时调用 javascript 函数:“未捕获 RangeError:超出最大调用堆栈大小”
- laravel - 我无法通过 laravel-sendgrid-driver 传递自定义变量
- c# - 在 ASP.Net Core 中上传大文件时出现 CORS 失败
- python - 与 model.fit 不兼容的形状