botframework-sdk
botframework-sdk copied to clipboard
[Question] Context.Call() Does nothing and throws "Stack is Empty" Exception?
Bot Info
- App ID: 4005729d-4113-4095-880b-82792a4aac83
- SDK Platform: .NET
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Autofac" version="4.6.2" targetFramework="net46" />
<package id="Chronic.Signed" version="0.3.2" targetFramework="net46" />
<package id="EntityFramework" version="6.1.3" targetFramework="net46" />
<package id="Microsoft.AspNet.WebApi" version="5.2.3" targetFramework="net46" />
<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.Azure.DocumentDB" version="1.11.0" targetFramework="net46" />
<package id="Microsoft.Azure.KeyVault.Core" version="1.0.0" targetFramework="net46" />
<package id="Microsoft.Bot.Builder" version="3.11.0" targetFramework="net46" />
<package id="Microsoft.Bot.Builder.Azure" version="3.2.4" targetFramework="net46" />
<package id="Microsoft.Bot.Builder.CognitiveServices" version="1.1.1" targetFramework="net46" />
<package id="Microsoft.Bot.Builder.History" version="3.0.6" targetFramework="net46" />
<package id="Microsoft.Bot.Connector" version="3.11.1" targetFramework="net46" />
<package id="Microsoft.Data.Edm" version="5.6.4" targetFramework="net46" />
<package id="Microsoft.Data.OData" version="5.6.4" targetFramework="net46" />
<package id="Microsoft.Data.Services.Client" version="5.6.4" targetFramework="net46" />
<package id="Microsoft.IdentityModel.Protocol.Extensions" version="1.0.4.403061554" targetFramework="net46" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.10" targetFramework="net46" />
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="3.2.3" targetFramework="net46" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net46" />
<package id="System.IdentityModel.Tokens.Jwt" version="4.0.4.403061554" targetFramework="net46" />
<package id="System.Spatial" version="5.6.4" targetFramework="net46" />
<package id="WindowsAzure.Storage" version="7.2.1" targetFramework="net46" />
</packages>
- Active Channels: Bot Framework Channel Emulator
- Deployment Environment: VS17 everything updated
Issue Description
Context.Call() Won't initiate a child dialog.
Code Example
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
}
else
{
await HandleSystemMessageAsync(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
using System;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
using BotPoc.Dialogs.Payments;
using System.Threading;
namespace BotPoc.Dialogs
{
[Serializable]
public class RootDialog : IDialog<object>
{
public async Task StartAsync(IDialogContext context)
{
context.Wait(this.MessageReceivedAsync);
}
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
{
var message = await result;
if (message.Text.ToLower() == "payments")
{
await this.InitiatePaymentsDialog(context);
}
await context.PostAsync($"DONE");
context.Done(this);
}
private async Task InitiatePaymentsDialog(IDialogContext context)
{
context.Call(new PaymentsDialog(), this.ResumeAfterDialog);
}
private async Task ResumeAfterDialog(IDialogContext context, IAwaitable<object> result)
{
try
{
var message = await result;
}
catch (Exception ex)
{
await context.PostAsync($"Failed with message: {ex.Message}");
}
finally
{
context.Done(this);
}
}
}
}
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
namespace BotPoc.Dialogs.Payments
{
[Serializable]
public class PaymentsDialog : IDialog<object>
{
public async Task StartAsync(IDialogContext context)
{
await context.PostAsync("testing");
context.Wait(this.MessageReceivedAsync);
}
public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
{
var message = await result;
context.Done(this);
}
}
}
Expected Behavior
To get "testing" message to the client.
Actual Results
Only "DONE"
I don't think you want to end your MessageRecievedAsync method with context.Done(this). Since you've already done a context.Call() in the InitiatePaymentsDialog method, you've already given control of the context, so to speak, to the child dialog. Continuing on to do context.Done in the parent dialog seems incorrect if your intention is to leave the child dialog on the top of the stack for execution.