botframework-solutions icon indicating copy to clipboard operation
botframework-solutions copied to clipboard

Alternative for OnEventActivityAsync() in new VA Template

Open manish-95 opened this issue 6 years ago • 11 comments

User Story

The recent update to the Virtual Assistant Template has changed the base class for MainDialog. As a result, the OnEventActivityAsync() method, which was available in the older version of the template, is now missing. The documentation available here, still pertains to the older version of the template. Due to this, using the new Template, I am unable to handle Proactive Scenarios, which was available in the older version of the template. The new template needs to be updated to be able to handle Event activities, since it is a loss of functionality provided by the older template.

Acceptance Criteria

  • Upgrade the new VA Template to be able to handle event activities, as provided by the older VA Template.

manish-95 avatar Feb 14 '20 05:02 manish-95

Hi @manish-95, 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.

We will take an action to update the documentation reflecting this change.

lauren-mills avatar Feb 14 '20 19:02 lauren-mills

What about events that want to set property in skillcontext and what about events that have to be propagate to a skill? in this case the current active skill is a Dialog in the dialog stack?

guru98 avatar Feb 23 '20 22:02 guru98

@guru98, the current active skill is always a Dialog in the stack. If you receive an event that you want to forward to the current active skill, you can add a handler for it in the DefaultActivityHandler.OnEventActivityAsync method like this one for TokensResponse, that catches the event, then calls dialog.Run(). This will pass the event to the waiting dialog.

For scenarios when you would have used the skillContext before, the Bot Builder SDK has introduced Actions in the 4.7 Skill Protocol as a replacement. You can find details on how to implement action support here.

lauren-mills avatar Feb 28 '20 17:02 lauren-mills

So your suggestion is call an action that set the skillcontext skill side? What about use SkillDialogArgs.Value in the BeginDialogAsync? It'is supported? I make a first try without luck

guru98 avatar Feb 28 '20 17:02 guru98

Ok SkillDialogArgs works

guru98 avatar Feb 28 '20 19:02 guru98

Great!

darrenj avatar Mar 02 '20 17:03 darrenj

@lauren-Mills / @darrenj can you please point to the docs that explain how to handle e.g. action events from adaptive cards in the new bot structure?

OnEventActivityAsync was moved from MainDialog to DefaultActivityHandler and in its new form it it is not possible to call BeginDialogAsync (lack of dialog context access).

You say that you can also handle it in RouteStepAsync but I cannot find a good example how to do that properly.

hansmbakker avatar May 01 '20 15:05 hansmbakker

If you are inside a Dialog flow it doen't change you can use, for example, EventPrompt. On the Virtual assistant in the DefaultActivityHandler you have to forward the event to the dialog waiting in the stack using await _dialog.RunAsync(turnContext, _dialogStateAccessor, cancellationToken). If you have a skill that have to send an event to the client you have to intercept it in the DefaultActivityHandler in the VA and explicitally send it to the client using SendActivityAsync

guru98 avatar May 01 '20 16:05 guru98

Ok, so my question is - how to properly use the forwarded event?

Is there any documentation or a sample for that?

Use case: I have a download event that should trigger a new DownloadDialog. This DownloadDialog should perform several actions and send several messages to the user that sent the event. Before, this was possible from the MainDialog event handling function since there was access to DialogContext which you could use for BeginDialogAsync.

hansmbakker avatar May 01 '20 16:05 hansmbakker

if understand well you hav to manage it inside the main dialog in the RouteStepAsync method checking activity.Type==Event and then calling BeginDialogAsync. e.g. case "SampleAction": { SampleActionInput actionData = null;

                            if (ev.Value is JObject eventValue)
                            {
                                actionData = eventValue.ToObject<SampleActionInput>();
                            }

                            // Invoke the SampleAction dialog passing input data if available
                            return await stepContext.BeginDialogAsync(nameof(SampleAction), actionData);
                        }

You have to doublecheck that in DefaultActivityHandler you forward the event to the main dialog: e.g. return _dialog.RunAsync(turnContext, _dialogStateAccessor, cancellationToken);

guru98 avatar May 02 '20 12:05 guru98

@guru98 I tried it, and it might work for normal events but in the past, VA used RouterDialog. RouterDialog contained this workaround to treat postBack events from Adaptive Cards as real events (instead of messages).

VA does not use RouterDialog anymore and therefore handling of Adaptive Card Buttons is now broken. Furthermore, the postBack activities they send (with activity type = message) contain no text so they break VA since it is being sent to LUIS instead.

This is not described in the Migration documentation. Instead, the sample how to handle these button events is simply removed from VA.

@darrenj @lauren-mills could you please help with this?

hansmbakker avatar May 07 '20 10:05 hansmbakker