我如何更新从WebChat组件触发的对话更新事件的channelData?

问题描述 投票:0回答:1

我正在尝试使用Angular Client连接到bot服务。我能够连接到Bot服务,但是一旦我发布一条消息“活动”,WebChat客户端就会向Bot发送一个sessionUpdate事件,因此我收到了Bot的登录卡。 (如果我从客户端将firstMessage的channelData中的userToken发送到Bot Service,则不会获得登录卡。)>

[我正在尝试在channelData中发送一个带有userToken的活动,但是sessionUpdate事件在我的消息活动之前到达了Bot服务,并且收到了登录卡。

我需要发送自定义channelData并发送来自客户端的sessionUpdateUpdate事件。

使用反向通道机制,我能够发送自定义channelData来发布活动,但是这个sessionUpdate事件是从websocket内部触发的,我需要拦截此事件触发器。

下面是代码详细信息:

Index.html

]
<script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
<script src="https://unpkg.com/simple-update-in/dist/simple-update-in.production.min.js"></script>

app.component.ts

] >>

// after response from https://directline.botframework.com/v3/directline/conversations
createDirectLine(response: any) {
        this.directLine =  window.WebChat.createDirectLine({
            token: response.token,
            webSocket: true,
            streamUrl: response.streamUrl,
            conversationId: response.conversationId
          });
}

this.store = window.WebChat.createStore({},
            ({dispatch}) => next => action => {
                    if (action.type === 'DIRECT_LINE/POST_ACTIVITY') {
                     // add custom channelData to every postActivity
                     action = window.simpleUpdateIn(action, ['payload', 'activity', 'channelData', 'UserToken'], function () { return this.userToken; });
                    }
                    if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
                        // Send event to bot with custom data
                        dispatch({
                          type: 'WEB_CHAT/SEND_EVENT',
                          payload: {
                            activity: {
                                type : 'conversationUpdate',
                                channelData : { 'UserToken : this.userToken}
                                }
                            }
                        })
                    }
                  return next(action);
                });

renderWebChat() {
        window.WebChat.renderWebChat(
            {
                directLine: this.directLine,
                store: this.store
            },
            this.botWindowElement.nativeElement
        );
}

P.S。这不是完整的代码,我只添加了代码片段。

我正在尝试使用Angular Client连接到bot服务。我能够连接到Bot服务,但是一旦我发布一条消息Activity,WebChat客户端就会发送一个对话更新...

html angular typescript botframework direct-line-botframework
1个回答
0
投票

您不应该尝试使用Web Chat直接操纵Direct Line产生的对话更新活动。您可以在创建对话时通过提供用户ID来影响这些活动,但其余的事务不在您的掌控之中。尝试将令牌嵌入用户ID中可能不是一个好主意,但是您可以将令牌托管在机器人可以使用用户ID进行查找的位置。

我认为您真正想做的是将事件活动发送给机器人,该事件活动指示连接成功,然后使用该活动代替对话更新。您似乎已经走上了正确的道路,因为您试图响应中间件中的DIRECT_LINE / CONNECT_FULFILLED动作。只需尝试在此处关注示例:https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/04.api/a.welcome-event

© www.soinside.com 2019 - 2024. All rights reserved.