Reputation: 13
currently I'm trying to migrate my v3 bot to v4 and I'm a little stuck how to migrate the v3 IDialog
. What is the equivalent in v4 and how to use them? Also, how can I do an Activity forwarding in v4? In v3 this would have been something like await context.Forward(…)
?
Many Thanks & Best Regards Fabian
Upvotes: 1
Views: 953
Reputation: 8292
A good place to start when converting a V3 dialog to V4 involves changing:
IDialog
->
Dialog
or ComponentDialog
(depending)
StartAsyc
->
BeginDialogAsync
MessageReceivedAsync
->
ContinueDialogAsync
IDialogContext
->
DialogContext
The Microsoft Bot Builder V3 .net sdk used AutoFac extensively, and dialog stack was generally more invisible to developers than it is in Bot Builder V4. V3 developers use .Call
and .Forward
to push dialogs onto the stack, and .EndDialog
to pop them. In V3, fields on dialogs are automatically serialized/deserialized and scoped to PrivateConversationData
. There was no need to configure dialog state specifically, the sdk added this for every bot and assumed the developer had registered a valid IBotDataStore<BotData>
implementation with autofac. Access to the PrivateConversationData
, ConversationData
and UserData
is automatic from IDialogContext
.
With Bot Builder V4, dialog stack and state setup is more in the hands of the developer. Within the BeginDialogAsync
and ContinueDialogAsync
methods, the DialogContext
has a BeginDialogAsync
method that will start that dialog as a child of the current dialog (similar to .Forward
in V3). Resuming after a dialog completes, and utilizing the value returned from the child dialog, is different and involves using DialogTurnResult.Result
DialogContext
also has references to the TurnContext
and DialogInstance
in V4 is the dialogContext.ActiveDialog
. From the DialogInstance
you can retrieve the DialogState
object, which is an IDictionary<string, object>
implementation that is json serialized into/out of the store configured in Startup.cs V4 retains the concepts of UserData
, ConversationData
and PivateConversationData
. Setup is a little different, but these data buckets are still scoped as they were:
The user state creates a key using the channel ID and from ID.
{Activity.ChannelId}/users/{Activity.From.Id}#YourPropertyName
The conversation state creates a key using the channel ID and the conversation ID.
{Activity.ChannelId}/conversations/{Activity.Conversation.Id}#YourPropertyName
The private conversation state creates a key using the channel ID, from ID and the conversation ID.
{Activity.ChannelId}/conversations/{Activity.Conversation.Id}/users/{Activity.From.Id}#YourPropertyName
State accessors are configured in Startup's ConfigureServices
method.
Documentation assisting developers with this process of V3 to V4 bot and dialog migration is in the works.
Some links for further reading on v4 dialogs and state:
Gather user input using a dialog prompt
Save user and conversation data
Implement custom storage for your bot
Upvotes: 4