团队:调用 Webrequest 向团队发送 base64 字符串 (png) [英] Teams: Invoke-Webrequest sending base64 string (png) to Teams

查看:62
本文介绍了团队:调用 Webrequest 向团队发送 base64 字符串 (png)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一个 png 格式的 base64 字符串发送到我们的团队频道,该频道具有传入 Webhook"设置.

I am trying to send a base64-string which is a png to our Teams-channel which have an "Incoming Webhook" setup.

消息已发送到频道,但未显示图像,当我搜索此消息时,似乎无法将图像或任何其他类型的附件作为 base64 字符串发送到团队?

The message is sent to the channel but no image is displayed and when I searched for this it seems that I can't send an image or any other type of attachment as a base64-string to Teams?

对 json 非常陌生,并且通常使用/使用 rest api.

Extremely new to json and consuming / using rest api in general.

我不知道如何指示正文该字符串是 base64 字符串并且预期的输出应该是 png 文件.

I have no idea how to instruct the body that the string is a base64-string and the expected output should be a png-file.

试过这个:

$webhook = 'URLtoTeamsWebhook'
$base64 = "longBase64string"

$Body = @{
     "text" = "Hello World! from PowerShell"
     "imageData" = "$base64"
}

$params = @{
      Headers = @{'accept'='application/json'}
      Body = $Body | convertto-json
      Method = 'Post'
      URI = $webhook 
}

Invoke-RestMethod @params

但是没有用,还尝试了下面的代码,对正文进行了更改:

But it didn't work, also tried the code below with changes to the body:

$Body = @{
  "type" = "string",
  "contentEncoding" = "$base64",
  "contentMediaType" = "image/png"
}

它也不起作用.

无效"= 发布到团队但根本不显示图像.

"Didn't work" = Posting to Teams but not displaying the image at all.

更新:

能够解决这个问题,有点,但仍然希望得到答复;

Was able to figure this out, sort-of but would still appreciate a reply;

https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/cards/cards-reference

我想你可以只"使用他们的卡片通过他们的传入网络钩子"发送数据,我想使用的卡片是英雄卡片",因为数据是带有图形图像的警报,但是,使用连接器"时不支持它:(

I guess you can "only" use their cards to send in data through their "Incoming webhook" and the card I would like to use is the "Hero Card" since the data is an alarm with a image of a graph, HOWEVER it is not supported when using a "connector" :(

我找到了这个网站;

https://github.com/grafana/grafana/issues/13121

而且我已经使用了那里的示例,但是它要求我必须将图片(采用 base64 格式)发送到 S3,以便用户能够查看更大的图片.

and I've used the example there however that require me to have to send the picture (which is in a base64-format) to S3 in order for users to be able to view a larger picture.

推荐答案

Webhook 支持 Office 365 连接器卡.请发送以下留言卡 JSON,如果您遇到任何问题,请告诉我们.

Webhook support Office 365 connector card. Please send following message card JSON and let us know if you facing any issues.

 {
    "@type": "MessageCard",
    "text": "Here are test images",
    "sections": [
        {
            "images": [
                {
                    "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAANCAIAAAAmMtkJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAMeSURBVDhPLVJbTBRXAL135s7Ozs7Ozi6z7AK7sCobCa2rmBabAEGNBlgjCr6t1qS26RIbH0lLH3y1fLQJsdVojPGjtjGGhKgfJIZoIhhEEg2+wagsYmlE2Ar7mNkddmbunel+9CTn4+Tk/Jxz4F8/diKatiDE2MKE0JARmrcNdXfVrVuj6xoFTVWRWRvF2YCkJftLms+vjgFs+gxlzD+KPDxEiIaQIiZGmJRtOXTmyMG9O1ox1igAiaZiBhbcYiwfW/fzWPHHQNabxFR/WTxj+ihRdPAOBtEWwHp5Q+uFX7sOf7odY4xoQChap1lJ5CHDbqz/c+x9KPRuYTx07+ayGVMstXu89IFNdQQTy7IcxcsHnryocRBGcBc0RIydgQGUfySsOlD1E55KX6mVW+O9Wc1y8bbZqZdOl5t6rxgZFWs6TEghauKuFKhQc3mMTQYCn5Y+6W3vkDrAkxmgqB1n7+96vCLgZpHHf6731pvnz+gju6PeIoEvLZscuNS6tcXJmj6Jd7tYJ8k2lf8wmgswb+ZpB2dquaWiyqex4t09w21hc+AfJqnocG+0feb1dHIh9W8mKxMcrKhS0klRcLidRXhP10RkA4hPM/KSwYnA0Nnk4lZ3Orw4GqyO9F0fgf3Xh7/4vKPzxFfffHd8Lv4uWB0A/8Ms8M7kwvr7dpDJsPMpDTmAovh5JjE83LL+gxuDY/D3WCyyY3/saNfmVR+eunh6cjwuulyCSzSWTJVnNcR46Zz/ZmELyEzPYoYrVAsMAvIG5DgqEPQs3u7747fvJ1Lp7dG2moY1Ly8PPu0dwYCyZbO6RsZl1mpHPlveWFmOSB5YFsXbodNuaTIFKEQcnrl7g91f75OqVgdcFdGeL8M10tz41NDAKzSX5LLGtb/pxE5Xoz1tVIcRbVBqDhRygptKEZjVjEUdqsT65dzJzzq/hYWH1kfCK4WmtqqMQXOJ2aCS6n2oDbWVHhXe4nAl5ija0KzCl6ONG2zQMiB69WJK8PobW1oitXWNH9U279tV6uQldtYbCsoJ1Un0B/P48Ccla835q6DERABl1f8A6bloNT9MI68AAAAASUVORK5CYII="
                }
            ]
        }
    ]
}

这篇关于团队:调用 Webrequest 向团队发送 base64 字符串 (png)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆