简体   繁体   English

新虚拟助手模板中 OnEventActivityAsync() 的替代方案

[英]Alternative for OnEventActivityAsync() in new Virtual Assistant Template

I am using a version of the Virtual Assistant Template based on SDK version 4.6 that implements Event Handling using OnEventActivityAsync().我正在使用基于 SDK 版本 4.6 的虚拟助手模板版本,该版本使用 OnEventActivityAsync() 实现事件处理。 I have been using this to implement Proactive Notifications.我一直在使用它来实现主动通知。 However after the latest update to the Virtual Assistant Solution template, the structure of the MainDialog has changed and I no longer see Event activities being handled.然而,在 Virtual Assistant Solution 模板的最新更新之后,MainDialog 的结构发生了变化,我不再看到正在处理的事件活动。 Is there an alternative in the new template that allows me to handle events, similar to the OnEventActivityAsync() method in the older template?新模板中是否有替代方法允许我处理事件,类似于旧模板中的 OnEventActivityAsync() 方法? My current setup is as follows:我目前的设置如下:

protected override async Task OnEventActivityAsync(DialogContext innerDc, CancellationToken cancellationToken = default)
    {
        var ev = innerDc.Context.Activity.AsEventActivity();
        var value = ev.Value?.ToString();

        switch (ev.Name)
        {
            ....
            case Events.Broadcast:
                {
                    var eventData = JsonConvert.DeserializeObject<EventData>(innerDc.Context.Activity.Value.ToString());

                    var proactiveModel = await _proactiveStateAccessor.GetAsync(innerDc.Context, () => new ProactiveModel());

                    var hashedUserId = MD5Util.ComputeHash(eventData.UserId);

                    var conversationReference = proactiveModel[hashedUserId].Conversation;

                    await innerDc.Context.Adapter.ContinueConversationAsync(_appCredentials.MicrosoftAppId, conversationReference, ContinueConversationCallback(innerDc.Context, eventData.Message), cancellationToken);
                    break;
                }
        }
    }

This entire method, is missing in the new version of the template, so is there any other way to implement this with the new VA template?新版本的模板中缺少整个方法,那么有没有其他方法可以使用新的 VA 模板实现这一点?

I am guessingthis is your question on the GitHub repo.我猜是你在 GitHub 存储库上的问题。 Adding the answer from the issue so that it helps others as well and for more visibility.添加问题的答案,以便它也有助于其他人并提高知名度。

You can process your events that do not need to be processed by the dialog stack in the DefaultActivityHandler.OnEventActivityAsync() method.您可以在DefaultActivityHandler.OnEventActivityAsync()方法中处理不需要由对话框堆栈处理的事件。

If your event needs to be processed by the dialog stack, for example a TokenResponse event, you can handle it in the MainDialog.RouteStepAsync() method.如果您的事件需要由对话堆栈处理,例如 TokenResponse 事件,您可以在MainDialog.RouteStepAsync()方法中处理它。

The documentation will be updated soon reflecting the above changes.文档将很快更新以反映上述更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM