gpt4 book ai didi

c# - 机器人框架V4 : how to send an event from the bot and catch it in react WebChat?

转载 作者:行者123 更新时间:2023-12-02 10:43:21 24 4
gpt4 key购买 nike

我从我的机器人 (.NET SDK) 发送一个名为“locationRequest”的事件

            Activity activity = new Activity
{
Type = ActivityTypes.Event,
Name = "locationRequest"
};
await stepContext.Context.SendActivityAsync(activity, cancellationToken);

我想在 WebChat 客户端应用程序中捕获此事件,基于 React 中编码的 minizable-web-chat,并将 bool 值 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”事件,然后检查传入事件是否具有适当的名称。有关更多详细信息,请查看下面的代码片段和 Incoming Event网络聊天示例。

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);
});

关于c# - 机器人框架V4 : how to send an event from the bot and catch it in react WebChat?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59986718/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com