我的卑微目标是在 Teams 中完成使用 Slack Webhooks 可以轻松完成的事情,如下所示:
await fetch(slackWebhook, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
text: s
})
});
当我通过此 webhook 发送一长串文本(不是 HTML)(包括 URL)时,URL 是可单击的并且所有文本都会显示。就好像有人打字一样。有道理吧?
但是,当我尝试使用 Teams Webhook 执行此操作时,仅显示一行文本,然后它就被剪掉了。没有扩展按钮,什么都没有。
我的第一次尝试是这样的:
await fetch(teamsWebhook, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
"type": "message",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"contentUrl": null,
"content": {
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.2",
"body": [
{
"type": "TextBlock",
"text": s
}
]
}
}
]
})
});
但这被剪得很短。所以我根据谷歌搜索尝试了这种冗长的内容:
await fetch(teamsWebhook, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
"type": "message",
"summary": "Deployment",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.2",
"msteams": {
"width": "Full"
},
"body": [
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "TextBlock",
"text": s
},
]
}
]
}
]
}
}
]
})
});
这给了我一行全角文本...但它仍然被剪掉,无法访问文本的其余部分。
如何通过 Teams Webhook 传递多行文本,使其全部可见?最好有有效的 URL?理想情况下就像有人打字一样?
谢谢。
我不确定您为什么专门使用 Adaptive Cards v1.2 - Teams 至少支持 1.5。无论如何,关于您的实际查询,请尝试将
wrap
上的 true
设置为 TextBlock
,如下所示:
await fetch(teamsWebhook, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
"type": "message",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"contentUrl": null,
"content": {
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.2",
"body": [
{
"type": "TextBlock",
"text": s,
"wrap": true
}
]
}
}
]
})
});