如何解析自适应卡中的提交操作值?我知道附近某处但无法解决。如果手动输入文本,我将前进到瀑布模型中的新对话框
Cards.json
{
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"id": "textBlock",
"text": "CREATE AN INCIDENT. "
},
{
"type": "Input.Text",
"id": "username",
"placeholder": "Enter your email address"
},
{
"type": "Input.Text",
"id": "shortdescription",
"placeholder": "Enter a short description"
},
{
"type": "Input.Number",
"id": "phonenumber",
"placeholder": "Enter your phonenumber"
}
],
"actions": [
{
"type": "Action.Submit",
"id": "submit",
"title": "Submit",
"data":{
"action": "mychoices"
}
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.0"
}
RequestDialog.cs
var askforSelectionSteps = new WaterfallStep[]
{
askForSelection,
askForSelectionResult,
CreateTicketFor_InstallSoftware
};
public async Task<DialogTurnResult> askForSelection(WaterfallStepContext sc, CancellationToken cancellationToken)
{
_state = new GenericRequestState();
await _accessor.SetAsync(sc.Context, _state);
//return await sc.PromptAsync(choiceprompt, new PromptOptions()
//{
// Prompt = MessageFactory.Text("Can you please let me know if the request is for you or someone else?"),
// Choices = new List<Choice> { new Choice("MySelf"), new Choice("Someone Else") },
// RetryPrompt = MessageFactory.Text("Please enter MySelf or Someone Else."),
//});
return await sc.PromptAsync(TextPrompt, new PromptOptions()
{
Prompt = CardHelper.GenericRequestIncidentChoices(sc, cancellationToken),
});
}
public async Task<DialogTurnResult> askForSelectionResult(WaterfallStepContext sc, CancellationToken cancellationToken)
{
var isSuccess = sc.Result.ToString().ToLower();
if (isSuccess == "incident" || isSuccess == "inc")
{
//return await sc.BeginDialogAsync(GenericRequestationStep_OneId);
return await sc.PromptAsync(TextPrompt, new PromptOptions()
{
Prompt = CardHelper.GenericCreateIncident(sc, cancellationToken),
});
}}
我已经研究了一些示例和stackoverflow本身,但是无法将Submit操作传递回对话框。任何帮助将不胜感激!
答案 0 :(得分:1)
protected override async Task OnEventAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
{
var value = dc.Context.Activity.Value;
if (value.GetType() == typeof(JObject))
{
var result = await dc.ContinueDialogAsync();
return;
}
}
您是否如上所述在OnEventAsync中编写了JObject处理?
请查看链接
How to retrieve Adaptive Card's form submission in subsequent waterfall step
答案 1 :(得分:0)
想知道如何处理JToken吗?如果是这样,请参见下面的代码。
var token = JToken.Parse(turnContext.Activity.ChannelData.ToString());
if (token["postBack"].Value<bool>())
{
JToken commandToken = JToken.Parse(turnContext.Activity.Value.ToString());
var data = commandToken["Your_Data_ID"].Value<Your_Data_Type>();
}
“您的数据ID”是电话号码,简短说明等... Your_Data_Type是int,字符串等...