[英]AdaptiveCard 400 Bad Request C# when posting to Teams webhook
With the below code i am getting StatusCode: 400, ReasonPhrase: 'Bad Request'
but no further info:使用以下代码,我得到
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...
}
I have already setup the webhook in Teams, appreciate pointer in the right direction.我已经在 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);
}
}
The produced JSON is as follows:生产出来的JSON如下:
{
"type": "AdaptiveCard",
"version": "1.0",
"title": "test",
"body": [
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"items": [
{
"type": "TextBlock",
"text": "one"
}
]
}
]
}
]
}
I have also tried by adding a container type (as i cannot find the attatchment element as below) and get the same errror.我还尝试通过添加容器类型(因为我找不到下面的附件元素)并得到相同的错误。
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);
Gives the following json:给出以下 json:
{
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "Container",
"items": [
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"items": [
{
"type": "TextBlock",
"text": "one"
}
]
}
]
}
]
}
]
}
I've not tried this myself, but from what I can see in the docs, the adaptive card needs to be wrapped as an "attachment" element inside a container.我自己没有尝试过,但从我在文档中看到的内容来看,自适应卡需要包装为容器内的“附件”元素。 See The flow for sending adaptive cards via an incoming webhook is as follows , step 2
请参阅通过传入 webhook 发送自适应卡片的流程如下,步骤 2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.