I created a bot using QnA Maker, which depending on the answer I should return the same answer or call another service, which in my case is to assemble a form flow from a JSON.
But when calling this service I start a new Conversation, so it does not return to the emulator.
I'm creating a conversation in another conversation. There must be something missing.
RootDialog.cs:
[Serializable]
public class RootDialog : QnAMakerDialog
{
public RootDialog() : base(
new QnAMakerService(
new QnAMakerAttribute(
ConfigurationManager.AppSettings["QnaSubscriptionKey"],
ConfigurationManager.AppSettings["QnaKnowledgebaseId"],
"Não encontrei sua resposta",
0.5
)
)
)
{
}
protected override async Task RespondFromQnAMakerResultAsync(IDialogContext context, IMessageActivity message, QnAMakerResults result)
{
var primeiraResposta = result.Answers.First().Answer;
if (primeiraResposta.IndexOf("form") == -1)
{
await context.PostAsync(primeiraResposta);
return;
}
await Conversation.SendAsync(message, () => Chain.From(() => FormDialog.FromForm(() => Formulario.JsonForm.BuildJsonForm(), FormOptions.PromptFieldsWithValues)));
return;
}
}
MessagesController.cs
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
var connector = new ConnectorClient(new Uri(activity.ServiceUrl));
if (activity.Type == ActivityTypes.ConversationUpdate)
{
if (activity.MembersAdded.Any(o => o.Id == activity.Recipient.Id))
{
var reply = activity.CreateReply();
reply.Text = "Hello...";
await connector.Conversations.ReplyToActivityAsync(reply);
}
}
else if (activity.Type == ActivityTypes.Message)
{
// HEREE!!!
await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
}
else
{
HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
The response of emulator:
I could not send, Repeat
Copyright Notice:Content Author:「Romário Carvalho」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/49191894/bot-framework-conversation-in-another-conversation