使用下面的代码,我得到 StatusCode: 400, ReasonPhrase: 'Bad Request'
但没有更多信息:
response = {StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
Cache-Control: no-cache
Pragma: no-cache
Server: Microsoft-IIS/10.0
request-id: 5a296706-4079-47ed-aa57-e50eb3dd78fb...
}
我已经在 Teams 中设置了 webhook,感谢正确方向的指针。
var card = new AdaptiveCard(new AdaptiveSchemaVersion(1,0));
var columnSet = new AdaptiveColumnSet();
var column = new AdaptiveColumn();
var text = new AdaptiveTextBlock("one");
column.Items.Add(text);
columnSet.Columns.Add(column);
card.Body.Add(columnSet);
try
{
var httpContent = new StringContent(card.ToJson(), Encoding.UTF8, AdaptiveCard.ContentType);
var response = await httpClient
.PostAsync(settings.TeamsWebhook,httpContent)
.ConfigureAwait(false);
if (response.StatusCode == HttpStatusCode.OK)
{
// Do something with response. Example get content:
// var responseContent = await response.Content.ReadAsStringAsync ().ConfigureAwait (false);
}
}
生成的JSON如下:
{
"type": "AdaptiveCard",
"version": "1.0",
"title": "test",
"body": [
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"items": [
{
"type": "TextBlock",
"text": "one"
}
]
}
]
}
]
}
我也尝试过添加容器类型(因为我找不到如下所示的附件元素)并得到相同的错误。
var card = new AdaptiveCard(new AdaptiveSchemaVersion(1,2));
var columnSet = new AdaptiveColumnSet();
var column = new AdaptiveColumn();
var text = new AdaptiveTextBlock("one");
var container = new AdaptiveContainer();
column.Items.Add(text);
columnSet.Columns.Add(column);
container.Items.Add(columnSet);
card.Body.Add(container);
给出以下 json:
{
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "Container",
"items": [
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"items": [
{
"type": "TextBlock",
"text": "one"
}
]
}
]
}
]
}
]
}
答案 0 :(得分:1)
我自己没有尝试过,但从我在文档中看到的情况来看,自适应卡需要包装为容器内的“附件”元素。请参阅The flow for sending adaptive cards via an incoming webhook is as follows,第 2 步