简体   繁体   English

Azure Logic App不会将附件发送到松弛状态

[英]Azure Logic App not sending Attachments to slack

Using Logic App in Azure to post message to slack. 使用Azure中的Logic App将消息发布到松弛。 This works fine with standard text message. 这适用于标准文本消息。 When I change to also post attachment nothing gets sent: 当我更改为发布附件时,没有发送任何内容:

                    "inputs": {
                        "host": {
                            "connection": {
                                "name": "@parameters('$connections')['slack']['connectionId']"
                            }
                        },
                        "method": "post",
                        "path": "/chat.postMessage",
                        "queries": {
                            "attachments": [
                                {
                                    "color": "danger",
                                    "fallback": "Azure alert attachment.",
                                    "fields": [
                                        {
                                            "title": "Check list"
                                        },
                                        {
                                            "value": "Check services on VM0 and VM1"
                                        },
                                        {
                                            "value": "If you cannot fix this issue make sure someone else can"
                                        }
                                    ],
                                    "pretext": "<!channel> Action required",
                                    "text": "`'@{triggerBody()['context']['name']}'` API down - '@{triggerBody()['context']['resourceName']}' Details: @{body('Http')['id']}",
                                    "ts": 123456789
                                }
                            ],
                            "channel": "#devops",
                            "text": "SYST ALERT"
                        }
                    }

Looking into this, it seems that Logic Apps does not support Attachment type. 考虑到这一点,似乎Logic Apps不支持附件类型。 Please upvote in uservoice @ 请在uservoice @ upvote

https://feedback.azure.com/forums/287593-logic-apps/suggestions/31896379-add-support-for-attachments-with-slack-post-messag https://feedback.azure.com/forums/287593-logic-apps/suggestions/31896379-add-support-for-attachments-with-slack-post-messag

So with that being the case, how do we do this today. 那么就是这样,我们今天如何做到这一点。 Slack Supports Incoming Webhooks as well as APIs. Slack支持传入的Webhooks以及API。 I enabled this in Logic Apps using chat.PostMessage API for more details on the API look at : 我使用chat.PostMessage API在Logic Apps中启用了此功能,以获取有关API的更多详细信息:

https://api.slack.com/methods/chat.postMessage/test https://api.slack.com/methods/chat.postMessage/test

The basic problem in this approach is the requirement for a token, in my sample i used a test token from 这种方法的基本问题是需要一个令牌,在我的样本中我使用了一个测试令牌

https://api.slack.com/custom-integrations/legacy-tokens https://api.slack.com/custom-integrations/legacy-tokens

This isn't the best approach (but i was having some issues using the Incoming WebHook will continue trying that approach and post if i have success there) from a Security PoV but does get the Job done. 这不是最好的方法(但我有一些问题,使用Incoming WebHook将继续尝试这种方法,如果我在那里取得成功,则发布)来自安全PoV,但确实完成了工作。 Final working code is as following : 最终工作代码如下:

{
    "$connections": {
        "value": {
            "office365": {
                "connectionId": "<ConnectionID",
                "connectionName": "office365",
                "id": "<ID>"
            }
        }
    },
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Condition_3": {
                "actions": {
                    "HTTP": {
                        "inputs": {
                            "body": "?token=<Token>&channel=C8270DY6L&attachments=%5B%7B%22fallback%22%3A%22Requiredplain-textsummaryoftheattachment.%22%2C%22color%22%3A%22%2336a64f%22%2C%22pretext%22%3A%22Optionaltextthatappearsabovetheattachmentblock%22%2C%22author_name%22%3A%22BobbyTables%22%2C%22author_link%22%3A%22http%3A%2F%2Fflickr.com%2Fbobby%2F%22%2C%22author_icon%22%3A%22http%3A%2F%2Fflickr.com%2Ficons%2Fbobby.jpg%22%2C%22title%22%3A%22SlackAPIDocumentation%22%2C%22title_link%22%3A%22https%3A%2F%2Fapi.slack.com%2F%22%2C%22text%22%3A%22Optionaltextthatappearswithintheattachment%22%2C%22fields%22%3A%5B%7B%22title%22%3A%22Priority%22%2C%22value%22%3A%22High%22%2C%22short%22%3Afalse%7D%5D%2C%22image_url%22%3A%22http%3A%2F%2Fmy-website.com%2Fpath%2Fto%2Fimage.jpg%22%2C%22thumb_url%22%3A%22http%3A%2F%2Fexample.com%2Fpath%2Fto%2Fthumb.png%22%2C%22footer%22%3A%22SlackAPI%22%2C%22footer_icon%22%3A%22https%3A%2F%2Fplatform.slack-edge.com%2Fimg%2Fdefault_application_icon.png%22%2C%22ts%22%3A123456789%7D%5D&pretty=1",
                            "method": "POST",
                            "uri": "https://slack.com/api/chat.postMessage"
                        },
                        "runAfter": {},
                        "type": "Http"
                    }
                },
                "expression": "@equals(triggerBody()?['HasAttachment'], True)",
                "runAfter": {},
                "type": "If"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {
            "$connections": {
                "defaultValue": {},
                "type": "Object"
            }
        },
        "triggers": {
            "When_a_new_email_arrives": {
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['office365']['connectionId']"
                        }
                    },
                    "method": "get",
                    "path": "/Mail/OnNewEmail",
                    "queries": {
                        "folderPath": "Inbox",
                        "importance": "Normal"
                    }
                },
                "recurrence": {
                    "frequency": "Minute",
                    "interval": 3
                },
                "splitOn": "@triggerBody()?['value']",
                "type": "ApiConnection"
            }
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过azure逻辑应用程序以松弛状态通知@channel - notifying @channel in slack via azure logic app 如何在Azure Logic App上使用Gmail附件 - How to work with Gmail attachments on Azure Logic App Azure逻辑应用程序:如何下载电子邮件附件 - Azure Logic App: How to download email attachments 如何使用将消息发布到 Slack 的 ARM 模板将逻辑应用程序部署到 Azure? - How to deploy Logic App to Azure with ARM template that posts messages to Slack? 调用Slack Webhook的Azure Logic应用将永远运行 - Azure Logic App calling a Slack Webhook runs forever 使用 Azure Logic App 处理和发送数据 - Data manipulation and sending it with Azure Logic App 在Azure逻辑应用程序中阅读附件时如何比较电子邮件附件扩展名? - How to compare email attachment extension while reading attachments in azure logic app? Azure Logic 应用程序:如何在从 Blob 存储中获取内容后发送带有一个或多个附件的电子邮件? - Azure Logic app : How to Send an Email with one or more attachments after getting the content from Blob storage? 如何在Azure Logic App中执行“获取电子邮件”操作后迭代电子邮件附件? - How to iterate email attachments after Get Emails action in Azure Logic App? 用于监控 Azure VM 的逻辑应用程序未发送预期的电子邮件 - Logic App to Monitor Azure VM not sending expected emails
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM