新虚拟助手模板中 OnEventActivityAsync() 的替代方法
Alternative for OnEventActivityAsync() in new Virtual Assistant Template
我正在使用基于 SDK 版本 4.6 的虚拟助手模板版本,该版本使用 OnEventActivityAsync() 实现事件处理。我一直在使用它来实现主动通知。但是,在对虚拟助手解决方案模板进行最新更新后,MainDialog 的结构发生了变化,我不再看到正在处理的事件活动。新模板中是否有替代方法允许我处理事件,类似于旧模板中的 OnEventActivityAsync() 方法?我目前的设置如下:
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;
}
}
}
新版本的模板中缺少这整个方法,那么有没有其他方法可以使用新的 VA 模板来实现它?
我猜 this 是你在 GitHub 回购协议中提出的问题。添加问题的答案,以便它也可以帮助其他人并提高知名度。
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.
文档将很快更新以反映上述更改。
我正在使用基于 SDK 版本 4.6 的虚拟助手模板版本,该版本使用 OnEventActivityAsync() 实现事件处理。我一直在使用它来实现主动通知。但是,在对虚拟助手解决方案模板进行最新更新后,MainDialog 的结构发生了变化,我不再看到正在处理的事件活动。新模板中是否有替代方法允许我处理事件,类似于旧模板中的 OnEventActivityAsync() 方法?我目前的设置如下:
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;
}
}
}
新版本的模板中缺少这整个方法,那么有没有其他方法可以使用新的 VA 模板来实现它?
我猜 this 是你在 GitHub 回购协议中提出的问题。添加问题的答案,以便它也可以帮助其他人并提高知名度。
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.
文档将很快更新以反映上述更改。