Я пытаюсь получить данные с адаптивной карты в чат-боте, но я не знаю, как это сделать.
Я создал адаптивную карту с помощью адаптивного дизайнера карт, и она успешно отображается в чат-боте, но я хочу иметь возможность извлекать данные, введенные пользователем, после выбора «Отправить».
Я полагаю, что это как-то связано с тем, что у меня нет конечной точки для отправки сообщения, но я не уверен, как ее объявить.
Любая помощь приветствуется!
C #
private async Task choiceCAIAResult(IDialogContext context, IAwaitable<string> result)
{
string message = await result;
if (message == "Yes")
{
var replyMessage = context.MakeMessage();
CreateAdaptiveCardApplicationJson(context, result);
// replyMessage.Attachments = new List<Attachment> { attachment };
// await context.PostAsync(replyMessage);
}
if (message == "No")
{
var replyMessage = context.MakeMessage();
Attachment attachment = GetCAIAHeroCard();
replyMessage.Attachments = new List<Attachment> { attachment };
await context.PostAsync(replyMessage);
}
}
private async Task CreateAdaptiveCardApplicationJson(IDialogContext context, IAwaitable<string> result)
{
var returnMessage = context.MakeMessage();
var json = await GetCardText("adaptiveCard");
var results = AdaptiveCard.FromJson(json);
var card = results.Card;
returnMessage.Attachments.Add(new Attachment()
{
Content = card,
ContentType = AdaptiveCard.ContentType,
Name = "Card",
});
card.Actions.Add(new AdaptiveSubmitAction() {
Title = "Next",
});
Debug.WriteLine(returnMessage.Attachments[0].Content);
await context.PostAsync(returnMessage);
}
public async Task<string> GetCardText(string cardName)
{
var path = HostingEnvironment.MapPath($"/Dialogs/{cardName}.json");
if (!File.Exists(path))
return string.Empty;
using (var f = File.OpenText(path))
{
return await f.ReadToEndAsync();
}
}
JSON
{ "type": "AdaptiveCard", "body": [
{
"type": "TextBlock",
"horizontalAlignment": "Center",
"size": "Large",
"text": "Residential Aged Care Online Application Form",
"wrap": true
},
{
"type": "TextBlock",
"size": "Medium",
"text": "Applicant Details"
},
{
"type": "Input.Text",
"id": "firstName",
"placeholder": "First Name"
},
{
"type": "Input.Text",
"id": "lastName",
"placeholder": "Last Name"
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"horizontalAlignment": "Left",
"verticalContentAlignment": "Center",
"items": [
{
"type": "TextBlock",
"id": "dobTitle",
"horizontalAlignment": "Right",
"size": "Medium",
"text": "Date of Birth"
}
]
},
{
"type": "Column",
"items": [
{
"type": "Input.Date",
"id": "dob"
}
],
"width": "stretch"
}
]
},
{
"type": "Input.ChoiceSet",
"id": "gender",
"style": "compact",
"placeholder": "Gender",
"choices": [
{
"title": "Female",
"value": "female"
},
{
"title": "Male",
"value": "male"
},
{
"title": "Intersex",
"value": "intersex"
},
{
"title": "Indeterminate",
"value": "indeterminate"
},
{
"title": "Transgender - Female",
"value": "transFemale"
},
{
"title": "Transgender - Male",
"value": "transMale"
},
{
"title": "Other",
"value": "other"
}
]
},
{
"type": "Input.Text",
"id": "street1",
"title": "Street1",
"placeholder": "Street 1"
},
{
"type": "Input.Text",
"id": "city",
"title": "city",
"placeholder": "City"
},
{
"type": "Input.ChoiceSet",
"id": "state",
"style": "compact",
"title": "State",
"placeholder": "State",
"choices": [
{
"title": "SA",
"value": "SA"
},
{
"title": "ACT",
"value": "ACT"
},
{
"title": "NSW",
"value": "NSW"
},
{
"title": "NT",
"value": "NT"
},
{
"title": "QLD",
"value": "QLD"
},
{
"title": "TAS",
"value": "TAS"
},
{
"title": "VIC",
"value": "VIC"
},
{
"title": "WA",
"value": "WA"
},
{
"title": "N/A",
"value": "N/A"
}
]
},
{
"type": "Input.Text",
"id": "postCode",
"title": "PostCode",
"placeholder": "Post Code"
},
{
"type": "Input.Text",
"id": "phone",
"title": "Phone",
"placeholder": "Phone",
"style": "Tel"
},
{
"type": "Input.Text",
"id": "email",
"title": "Email",
"placeholder": "Email",
"style": "Email"
},
{
"type": "Input.ChoiceSet",
"id": "currentAccommodation",
"style": "compact",
"title": "CurrentAccommodation",
"placeholder": "Current Accommodation",
"choices": [
{
"title": "Home",
"value": "home"
},
{
"title": "Hospital",
"value": "hospital"
},
{
"title": "Aged Care",
"value": "agedCare"
},
{
"title": "Other",
"value": "other"
}
]
} ], "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", "version": "1.0"
}