diff --git a/csharp/simpleSendMessage/packages.config b/csharp/simpleSendMessage/packages.config index 28f1902..14b61b1 100644 --- a/csharp/simpleSendMessage/packages.config +++ b/csharp/simpleSendMessage/packages.config @@ -7,12 +7,12 @@ - + - + - + \ No newline at end of file diff --git a/csharp/simpleSendMessage/simpleSendMessage.csproj b/csharp/simpleSendMessage/simpleSendMessage.csproj index 7df0935..f301953 100644 --- a/csharp/simpleSendMessage/simpleSendMessage.csproj +++ b/csharp/simpleSendMessage/simpleSendMessage.csproj @@ -57,12 +57,16 @@ .\packages\Chronic.Signed.0.3.2\lib\net40\Chronic.dll True - - .\packages\Microsoft.Bot.Builder.3.3.2\lib\net46\Microsoft.Bot.Builder.dll + + packages\Microsoft.Bot.Builder.3.9.0.0\lib\net46\Microsoft.Bot.Builder.dll True - - .\packages\Microsoft.Bot.Builder.3.3.2\lib\net46\Microsoft.Bot.Connector.dll + + packages\Microsoft.Bot.Builder.3.9.0.0\lib\net46\Microsoft.Bot.Builder.Autofac.dll + True + + + packages\Microsoft.Bot.Builder.3.9.0.0\lib\net46\Microsoft.Bot.Connector.dll True @@ -70,8 +74,8 @@ .\packages\Microsoft.Diagnostics.Tracing.EventSource.Redist.1.1.28\lib\net46\Microsoft.Diagnostics.Tracing.EventSource.dll True - - .\packages\Microsoft.IdentityModel.Protocol.Extensions.1.0.2.206221351\lib\net45\Microsoft.IdentityModel.Protocol.Extensions.dll + + packages\Microsoft.IdentityModel.Protocol.Extensions.1.0.4.403061554\lib\net45\Microsoft.IdentityModel.Protocol.Extensions.dll True @@ -87,8 +91,8 @@ True - - .\packages\System.IdentityModel.Tokens.Jwt.4.0.2.206221351\lib\net45\System.IdentityModel.Tokens.Jwt.dll + + packages\System.IdentityModel.Tokens.Jwt.4.0.4.403061554\lib\net45\System.IdentityModel.Tokens.Jwt.dll True diff --git a/csharp/startNewDialog/Controllers/CustomWebAPIController.cs b/csharp/startNewDialog/Controllers/CustomWebAPIController.cs index bef90e8..5f89b2c 100644 --- a/csharp/startNewDialog/Controllers/CustomWebAPIController.cs +++ b/csharp/startNewDialog/Controllers/CustomWebAPIController.cs @@ -19,7 +19,7 @@ public async Task SendMessage() { try { - if (!string.IsNullOrEmpty(ConversationStarter.resumptionCookie)) + if (!string.IsNullOrEmpty(ConversationStarter.conversationReference)) { await ConversationStarter.Resume(); //We don't need to wait for this, just want to start the interruption here diff --git a/csharp/startNewDialog/ConversationStarter.cs b/csharp/startNewDialog/ConversationStarter.cs index 5019a65..b014614 100644 --- a/csharp/startNewDialog/ConversationStarter.cs +++ b/csharp/startNewDialog/ConversationStarter.cs @@ -8,6 +8,7 @@ using System.Threading; using System.Threading.Tasks; using System.Web; +using Newtonsoft.Json; namespace startNewDialog { @@ -16,14 +17,16 @@ public class ConversationStarter //Note: Of course you don't want this here. Eventually you will need to save this in some table //Having this here as static variable means we can only remember one user :) - public static string resumptionCookie; + public static string conversationReference; //This will interrupt the conversation and send the user to SurveyDialog, then wait until that's done public static async Task Resume() { - var message = ResumptionCookie.GZipDeserialize(resumptionCookie).GetMessage(); + var asReference = JsonConvert.DeserializeObject(conversationReference); + var message = asReference.GetPostToBotMessage(); var client = new ConnectorClient(new Uri(message.ServiceUrl)); + // Create a scope that can be used to work with state from bot framework. using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, message)) { var botData = scope.Resolve(); @@ -31,16 +34,16 @@ public static async Task Resume() //This is our dialog stack var stack = scope.Resolve(); - + //interrupt the stack. This means that we're stopping whatever conversation that is currently happening with the user //Then adding this stack to run and once it's finished, we will be back to the original conversation var dialog =new SurveyDialog(); - stack.Call(dialog.Void(), null); - await stack.PollAsync(CancellationToken.None); + stack.Call(dialog.Void(), null); + + await scope.Resolve().PollAsync(CancellationToken.None); - //flush dialog stack + // Flush the dialog stack back to its state store. await botData.FlushAsync(CancellationToken.None); - } } } diff --git a/csharp/startNewDialog/RootDialog.cs b/csharp/startNewDialog/RootDialog.cs index 2f8220d..7b0fbf0 100644 --- a/csharp/startNewDialog/RootDialog.cs +++ b/csharp/startNewDialog/RootDialog.cs @@ -12,6 +12,7 @@ using System.Xml.Linq; using System.Threading; using Newtonsoft.Json; +using Microsoft.Bot.Builder.ConnectorEx; namespace startNewDialog { @@ -30,7 +31,8 @@ public async Task StartAsync(IDialogContext context) public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable result) { var message = await result; - ConversationStarter.resumptionCookie = new ResumptionCookie(message).GZipSerialize(); + var conversationReference = message.ToConversationReference(); + ConversationStarter.conversationReference = JsonConvert.SerializeObject(conversationReference); //We will start a timer to fake a background service that will trigger the proactive message @@ -39,7 +41,7 @@ public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitabl var url = HttpContext.Current.Request.Url; await context.PostAsync("Hey there, I'm going to interrupt our conversation and start a survey in a few seconds. You can also make me send a message by accessing: " + - url.Scheme + "://" + url.Host + ":" + url.Port + "/api/CustomWebApi"); + url.Scheme + "://" + url.Host + ":" + url.Port + "/api/CustomWebApi"); context.Wait(MessageReceivedAsync); } public void timerEvent(object target) diff --git a/csharp/startNewDialog/packages.config b/csharp/startNewDialog/packages.config index 28f1902..14b61b1 100644 --- a/csharp/startNewDialog/packages.config +++ b/csharp/startNewDialog/packages.config @@ -7,12 +7,12 @@ - + - + - + \ No newline at end of file diff --git a/csharp/startNewDialog/startNewDialog.csproj b/csharp/startNewDialog/startNewDialog.csproj index 2d07368..5ae7779 100644 --- a/csharp/startNewDialog/startNewDialog.csproj +++ b/csharp/startNewDialog/startNewDialog.csproj @@ -57,12 +57,16 @@ .\packages\Chronic.Signed.0.3.2\lib\net40\Chronic.dll True - - .\packages\Microsoft.Bot.Builder.3.3.2\lib\net46\Microsoft.Bot.Builder.dll + + packages\Microsoft.Bot.Builder.3.9.0.0\lib\net46\Microsoft.Bot.Builder.dll True - - .\packages\Microsoft.Bot.Builder.3.3.2\lib\net46\Microsoft.Bot.Connector.dll + + packages\Microsoft.Bot.Builder.3.9.0.0\lib\net46\Microsoft.Bot.Builder.Autofac.dll + True + + + packages\Microsoft.Bot.Builder.3.9.0.0\lib\net46\Microsoft.Bot.Connector.dll True @@ -70,8 +74,8 @@ .\packages\Microsoft.Diagnostics.Tracing.EventSource.Redist.1.1.28\lib\net46\Microsoft.Diagnostics.Tracing.EventSource.dll True - - .\packages\Microsoft.IdentityModel.Protocol.Extensions.1.0.2.206221351\lib\net45\Microsoft.IdentityModel.Protocol.Extensions.dll + + packages\Microsoft.IdentityModel.Protocol.Extensions.1.0.4.403061554\lib\net45\Microsoft.IdentityModel.Protocol.Extensions.dll True @@ -87,8 +91,8 @@ True - - .\packages\System.IdentityModel.Tokens.Jwt.4.0.2.206221351\lib\net45\System.IdentityModel.Tokens.Jwt.dll + + packages\System.IdentityModel.Tokens.Jwt.4.0.4.403061554\lib\net45\System.IdentityModel.Tokens.Jwt.dll True @@ -142,7 +146,9 @@ - + + Designer + diff --git a/csharp/startNewDialogWithPrompt/Controllers/CustomWebAPIController.cs b/csharp/startNewDialogWithPrompt/Controllers/CustomWebAPIController.cs index 415166e..ff549ee 100644 --- a/csharp/startNewDialogWithPrompt/Controllers/CustomWebAPIController.cs +++ b/csharp/startNewDialogWithPrompt/Controllers/CustomWebAPIController.cs @@ -19,7 +19,7 @@ public async Task SendMessage() { try { - if (!string.IsNullOrEmpty(ConversationStarter.resumptionCookie)) + if (!string.IsNullOrEmpty(ConversationStarter.conversationReference)) { await ConversationStarter.Resume(); //We don't need to wait for this, just want to start the interruption here diff --git a/csharp/startNewDialogWithPrompt/ConversationStarter.cs b/csharp/startNewDialogWithPrompt/ConversationStarter.cs index 4e2cf5b..a7ac073 100644 --- a/csharp/startNewDialogWithPrompt/ConversationStarter.cs +++ b/csharp/startNewDialogWithPrompt/ConversationStarter.cs @@ -8,6 +8,7 @@ using System.Threading; using System.Threading.Tasks; using System.Web; +using Newtonsoft.Json; namespace startNewDialogWithPrompt { @@ -15,12 +16,13 @@ public class ConversationStarter { //Note: Of course you don't want this here. Eventually you will need to save this in some table //Having this here as static variable means we can only remember one user :) - public static string resumptionCookie; + public static string conversationReference; //This will interrupt the conversation and send the user to SurveyDialog, then wait until that's done public static async Task Resume() { - var message = ResumptionCookie.GZipDeserialize(resumptionCookie).GetMessage(); + var asReference = JsonConvert.DeserializeObject(conversationReference); + var message = asReference.GetPostToBotMessage(); var client = new ConnectorClient(new Uri(message.ServiceUrl)); @@ -33,7 +35,7 @@ public static async Task Resume() //interrupt the stack var dialog =new SurveyDialog(); stack.Call(dialog.Void(), null); - await stack.PollAsync(CancellationToken.None); + await scope.Resolve().PollAsync(CancellationToken.None); //flush dialog stack await botData.FlushAsync(CancellationToken.None); diff --git a/csharp/startNewDialogWithPrompt/RootDialog.cs b/csharp/startNewDialogWithPrompt/RootDialog.cs index 0e01b7d..39244e5 100644 --- a/csharp/startNewDialogWithPrompt/RootDialog.cs +++ b/csharp/startNewDialogWithPrompt/RootDialog.cs @@ -12,6 +12,7 @@ using System.Xml.Linq; using System.Threading; using Newtonsoft.Json; +using Microsoft.Bot.Builder.ConnectorEx; namespace startNewDialogWithPrompt { @@ -30,7 +31,8 @@ public async Task StartAsync(IDialogContext context) public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable result) { var message = await result; - ConversationStarter.resumptionCookie = new ResumptionCookie(message).GZipSerialize(); + var conversationReference = message.ToConversationReference(); + ConversationStarter.conversationReference = JsonConvert.SerializeObject(conversationReference); //Prepare the timer to simulate a background/asynchonous process t = new Timer(new TimerCallback(timerEvent)); diff --git a/csharp/startNewDialogWithPrompt/packages.config b/csharp/startNewDialogWithPrompt/packages.config index 28f1902..14b61b1 100644 --- a/csharp/startNewDialogWithPrompt/packages.config +++ b/csharp/startNewDialogWithPrompt/packages.config @@ -7,12 +7,12 @@ - + - + - + \ No newline at end of file diff --git a/csharp/startNewDialogWithPrompt/startNewDialogWithPrompt.csproj b/csharp/startNewDialogWithPrompt/startNewDialogWithPrompt.csproj index f7c7349..43c9de1 100644 --- a/csharp/startNewDialogWithPrompt/startNewDialogWithPrompt.csproj +++ b/csharp/startNewDialogWithPrompt/startNewDialogWithPrompt.csproj @@ -57,12 +57,16 @@ .\packages\Chronic.Signed.0.3.2\lib\net40\Chronic.dll True - - .\packages\Microsoft.Bot.Builder.3.3.2\lib\net46\Microsoft.Bot.Builder.dll + + packages\Microsoft.Bot.Builder.3.9.0.0\lib\net46\Microsoft.Bot.Builder.dll True - - .\packages\Microsoft.Bot.Builder.3.3.2\lib\net46\Microsoft.Bot.Connector.dll + + packages\Microsoft.Bot.Builder.3.9.0.0\lib\net46\Microsoft.Bot.Builder.Autofac.dll + True + + + packages\Microsoft.Bot.Builder.3.9.0.0\lib\net46\Microsoft.Bot.Connector.dll True @@ -70,8 +74,8 @@ .\packages\Microsoft.Diagnostics.Tracing.EventSource.Redist.1.1.28\lib\net46\Microsoft.Diagnostics.Tracing.EventSource.dll True - - .\packages\Microsoft.IdentityModel.Protocol.Extensions.1.0.2.206221351\lib\net45\Microsoft.IdentityModel.Protocol.Extensions.dll + + packages\Microsoft.IdentityModel.Protocol.Extensions.1.0.4.403061554\lib\net45\Microsoft.IdentityModel.Protocol.Extensions.dll True @@ -87,8 +91,8 @@ True - - .\packages\System.IdentityModel.Tokens.Jwt.4.0.2.206221351\lib\net45\System.IdentityModel.Tokens.Jwt.dll + + packages\System.IdentityModel.Tokens.Jwt.4.0.4.403061554\lib\net45\System.IdentityModel.Tokens.Jwt.dll True @@ -142,7 +146,9 @@ - + + Designer +