BotFramework V4:如何从漫游器发送事件并将其捕获到React WebChat中? [英] BotFramework V4: how to send an event from the bot and catch it in react WebChat?
问题描述
我从我的机器人(.NET SDK)发送了一个名为"locationRequest"的事件
I send an event named "locationRequest" from my bot (.NET SDK)
Activity activity = new Activity
{
Type = ActivityTypes.Event,
Name = "locationRequest"
};
await stepContext.Context.SendActivityAsync(activity, cancellationToken);
我想基于React中编码的minizable-web-chat在WebChat客户端应用程序中捕获此事件,并将布尔位置Requested设置为True:
I want to catch this event in the WebChat client application, based on the minizable-web-chat coded in React, and set a boolean locationRequested to 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);
});
我无法赶上这个活动,请问有什么想法吗?
I am unable to catch this event, any idea please ?
推荐答案
您正走上正确的道路.基本上,您可以监视"DIRECT_LINE/INCOMING_ACTIVITY"事件,然后检查传入的活动是否具有适当的名称.有关更多详细信息,请查看下面的代码段和
You're going down the right track. Basically, you can monitor for 'DIRECT_LINE/INCOMING_ACTIVITY' events and then check if the incoming activity has the appropriate name. For more details, take a look at the code snippet below and the Incoming Event Web Chat sample.
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);
});
这篇关于BotFramework V4:如何从漫游器发送事件并将其捕获到React WebChat中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!