简体   繁体   中英

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(). 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. Is there an alternative in the new template that allows me to handle events, similar to the OnEventActivityAsync() method in the older template? 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?

I am guessingthis is your question on the GitHub repo. 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.

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.

The documentation will be updated soon reflecting the above changes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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