Skip to content
This repository was archived by the owner on Jan 14, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions csharp/simpleSendMessage/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net46" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net46" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net46" />
<package id="Microsoft.Bot.Builder" version="3.3.2" targetFramework="net46" />
<package id="Microsoft.Bot.Builder" version="3.9.0.0" targetFramework="net46" />
<package id="Microsoft.Diagnostics.Tracing.EventSource.Redist" version="1.1.28" targetFramework="net46" />
<package id="Microsoft.IdentityModel.Protocol.Extensions" version="1.0.2.206221351" targetFramework="net46" />
<package id="Microsoft.IdentityModel.Protocol.Extensions" version="1.0.4.403061554" targetFramework="net46" />
<package id="Microsoft.Net.Compilers" version="1.3.2" targetFramework="net46" developmentDependency="true" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.2" targetFramework="net46" />
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="3.2.1" targetFramework="net46" />
<package id="Newtonsoft.Json" version="9.0.2-beta1" targetFramework="net46" />
<package id="System.IdentityModel.Tokens.Jwt" version="4.0.2.206221351" targetFramework="net46" />
<package id="System.IdentityModel.Tokens.Jwt" version="4.0.4.403061554" targetFramework="net46" />
</packages>
20 changes: 12 additions & 8 deletions csharp/simpleSendMessage/simpleSendMessage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,25 @@
<HintPath>.\packages\Chronic.Signed.0.3.2\lib\net40\Chronic.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Bot.Builder, Version=3.3.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>.\packages\Microsoft.Bot.Builder.3.3.2\lib\net46\Microsoft.Bot.Builder.dll</HintPath>
<Reference Include="Microsoft.Bot.Builder, Version=3.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Bot.Builder.3.9.0.0\lib\net46\Microsoft.Bot.Builder.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Bot.Connector, Version=3.3.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>.\packages\Microsoft.Bot.Builder.3.3.2\lib\net46\Microsoft.Bot.Connector.dll</HintPath>
<Reference Include="Microsoft.Bot.Builder.Autofac, Version=3.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Bot.Builder.3.9.0.0\lib\net46\Microsoft.Bot.Builder.Autofac.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Bot.Connector, Version=3.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Bot.Builder.3.9.0.0\lib\net46\Microsoft.Bot.Connector.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.Diagnostics.Tracing.EventSource, Version=1.1.28.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>.\packages\Microsoft.Diagnostics.Tracing.EventSource.Redist.1.1.28\lib\net46\Microsoft.Diagnostics.Tracing.EventSource.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.IdentityModel.Protocol.Extensions, Version=1.0.2.33, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>.\packages\Microsoft.IdentityModel.Protocol.Extensions.1.0.2.206221351\lib\net45\Microsoft.IdentityModel.Protocol.Extensions.dll</HintPath>
<Reference Include="Microsoft.IdentityModel.Protocol.Extensions, Version=1.0.40306.1554, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.IdentityModel.Protocol.Extensions.1.0.4.403061554\lib\net45\Microsoft.IdentityModel.Protocol.Extensions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
Expand All @@ -87,8 +91,8 @@
<Private>True</Private>
</Reference>
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.IdentityModel.Tokens.Jwt, Version=4.0.20622.1351, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>.\packages\System.IdentityModel.Tokens.Jwt.4.0.2.206221351\lib\net45\System.IdentityModel.Tokens.Jwt.dll</HintPath>
<Reference Include="System.IdentityModel.Tokens.Jwt, Version=4.0.40306.1554, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\System.IdentityModel.Tokens.Jwt.4.0.4.403061554\lib\net45\System.IdentityModel.Tokens.Jwt.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async Task<HttpResponseMessage> 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

Expand Down
17 changes: 10 additions & 7 deletions csharp/startNewDialog/ConversationStarter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using Newtonsoft.Json;

namespace startNewDialog
{
Expand All @@ -16,31 +17,33 @@ 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>(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<IBotData>();
await botData.LoadAsync(CancellationToken.None);

//This is our dialog stack
var stack = scope.Resolve<IDialogStack>();

//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<object, IMessageActivity>(), null);
await stack.PollAsync(CancellationToken.None);
stack.Call(dialog.Void<object, IMessageActivity>(), null);

await scope.Resolve<IDialogTask>().PollAsync(CancellationToken.None);

//flush dialog stack
// Flush the dialog stack back to its state store.
await botData.FlushAsync(CancellationToken.None);

}
}
}
Expand Down
6 changes: 4 additions & 2 deletions csharp/startNewDialog/RootDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Xml.Linq;
using System.Threading;
using Newtonsoft.Json;
using Microsoft.Bot.Builder.ConnectorEx;

namespace startNewDialog
{
Expand All @@ -30,7 +31,8 @@ public async Task StartAsync(IDialogContext context)
public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> 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

Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions csharp/startNewDialog/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net46" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net46" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net46" />
<package id="Microsoft.Bot.Builder" version="3.3.2" targetFramework="net46" />
<package id="Microsoft.Bot.Builder" version="3.9.0.0" targetFramework="net46" />
<package id="Microsoft.Diagnostics.Tracing.EventSource.Redist" version="1.1.28" targetFramework="net46" />
<package id="Microsoft.IdentityModel.Protocol.Extensions" version="1.0.2.206221351" targetFramework="net46" />
<package id="Microsoft.IdentityModel.Protocol.Extensions" version="1.0.4.403061554" targetFramework="net46" />
<package id="Microsoft.Net.Compilers" version="1.3.2" targetFramework="net46" developmentDependency="true" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.2" targetFramework="net46" />
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="3.2.1" targetFramework="net46" />
<package id="Newtonsoft.Json" version="9.0.2-beta1" targetFramework="net46" />
<package id="System.IdentityModel.Tokens.Jwt" version="4.0.2.206221351" targetFramework="net46" />
<package id="System.IdentityModel.Tokens.Jwt" version="4.0.4.403061554" targetFramework="net46" />
</packages>
24 changes: 15 additions & 9 deletions csharp/startNewDialog/startNewDialog.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,25 @@
<HintPath>.\packages\Chronic.Signed.0.3.2\lib\net40\Chronic.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Bot.Builder, Version=3.3.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>.\packages\Microsoft.Bot.Builder.3.3.2\lib\net46\Microsoft.Bot.Builder.dll</HintPath>
<Reference Include="Microsoft.Bot.Builder, Version=3.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Bot.Builder.3.9.0.0\lib\net46\Microsoft.Bot.Builder.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Bot.Connector, Version=3.3.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>.\packages\Microsoft.Bot.Builder.3.3.2\lib\net46\Microsoft.Bot.Connector.dll</HintPath>
<Reference Include="Microsoft.Bot.Builder.Autofac, Version=3.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Bot.Builder.3.9.0.0\lib\net46\Microsoft.Bot.Builder.Autofac.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Bot.Connector, Version=3.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Bot.Builder.3.9.0.0\lib\net46\Microsoft.Bot.Connector.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.Diagnostics.Tracing.EventSource, Version=1.1.28.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>.\packages\Microsoft.Diagnostics.Tracing.EventSource.Redist.1.1.28\lib\net46\Microsoft.Diagnostics.Tracing.EventSource.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.IdentityModel.Protocol.Extensions, Version=1.0.2.33, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>.\packages\Microsoft.IdentityModel.Protocol.Extensions.1.0.2.206221351\lib\net45\Microsoft.IdentityModel.Protocol.Extensions.dll</HintPath>
<Reference Include="Microsoft.IdentityModel.Protocol.Extensions, Version=1.0.40306.1554, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.IdentityModel.Protocol.Extensions.1.0.4.403061554\lib\net45\Microsoft.IdentityModel.Protocol.Extensions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
Expand All @@ -87,8 +91,8 @@
<Private>True</Private>
</Reference>
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.IdentityModel.Tokens.Jwt, Version=4.0.20622.1351, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>.\packages\System.IdentityModel.Tokens.Jwt.4.0.2.206221351\lib\net45\System.IdentityModel.Tokens.Jwt.dll</HintPath>
<Reference Include="System.IdentityModel.Tokens.Jwt, Version=4.0.40306.1554, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\System.IdentityModel.Tokens.Jwt.4.0.4.403061554\lib\net45\System.IdentityModel.Tokens.Jwt.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net" />
Expand Down Expand Up @@ -142,7 +146,9 @@
<Compile Include="RootDialog.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="packages.config" />
<Content Include="packages.config">
<SubType>Designer</SubType>
</Content>
<None Include="Properties\PublishProfiles\CreateNewConversationBot20161114045632 - Web Deploy.pubxml" />
<None Include="Properties\PublishProfiles\PresenterBot - Web Deploy.pubxml" />
<None Include="Web.Debug.config">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async Task<HttpResponseMessage> 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

Expand Down
8 changes: 5 additions & 3 deletions csharp/startNewDialogWithPrompt/ConversationStarter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using Newtonsoft.Json;

namespace startNewDialogWithPrompt
{
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>(conversationReference);
var message = asReference.GetPostToBotMessage();
var client = new ConnectorClient(new Uri(message.ServiceUrl));


Expand All @@ -33,7 +35,7 @@ public static async Task Resume()
//interrupt the stack
var dialog =new SurveyDialog();
stack.Call(dialog.Void<object, IMessageActivity>(), null);
await stack.PollAsync(CancellationToken.None);
await scope.Resolve<IDialogTask>().PollAsync(CancellationToken.None);

//flush dialog stack
await botData.FlushAsync(CancellationToken.None);
Expand Down
4 changes: 3 additions & 1 deletion csharp/startNewDialogWithPrompt/RootDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Xml.Linq;
using System.Threading;
using Newtonsoft.Json;
using Microsoft.Bot.Builder.ConnectorEx;

namespace startNewDialogWithPrompt
{
Expand All @@ -30,7 +31,8 @@ public async Task StartAsync(IDialogContext context)
public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> 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));
Expand Down
6 changes: 3 additions & 3 deletions csharp/startNewDialogWithPrompt/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net46" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net46" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net46" />
<package id="Microsoft.Bot.Builder" version="3.3.2" targetFramework="net46" />
<package id="Microsoft.Bot.Builder" version="3.9.0.0" targetFramework="net46" />
<package id="Microsoft.Diagnostics.Tracing.EventSource.Redist" version="1.1.28" targetFramework="net46" />
<package id="Microsoft.IdentityModel.Protocol.Extensions" version="1.0.2.206221351" targetFramework="net46" />
<package id="Microsoft.IdentityModel.Protocol.Extensions" version="1.0.4.403061554" targetFramework="net46" />
<package id="Microsoft.Net.Compilers" version="1.3.2" targetFramework="net46" developmentDependency="true" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.2" targetFramework="net46" />
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="3.2.1" targetFramework="net46" />
<package id="Newtonsoft.Json" version="9.0.2-beta1" targetFramework="net46" />
<package id="System.IdentityModel.Tokens.Jwt" version="4.0.2.206221351" targetFramework="net46" />
<package id="System.IdentityModel.Tokens.Jwt" version="4.0.4.403061554" targetFramework="net46" />
</packages>
Loading