saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:
https://repo.saltproject.io/
Apache License 2.0
14.09k stars 5.47k forks source link

[msteam post suggestion] #66863

Open arnebjarne opened 2 weeks ago

arnebjarne commented 2 weeks ago

Is your feature request related to a problem? Please describe. Microsoft have changed their Microsoft Teams integration and now require a Workflow integration

Describe the solution you'd like I have a code suggestion for a temporary fix which ofc should be extended by someone

Describe alternatives you've considered Since MS has revoked their integration there is not really other alternatives

Additional context code diff:

--- /opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/msteams.py.bak        2024-08-30 11:23:50.394257716 +0000
+++ /opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/msteams.py    2024-08-30 12:53:05.265724774 +0000
@@ -68,7 +68,37 @@
     if not message:
         log.error("message is a required option.")

-    payload = {"text": message, "title": title, "themeColor": theme_color}
+    payload = {
+        "type": "message",
+        "attachments": [
+            {"contentType": "application/vnd.microsoft.card.adaptive",
+             "contentUrl": None,
+             "content": {
+                "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
+                "type": "AdaptiveCard",
+                "version": "1.2",
+                "msteams": {
+                    "width": "Full"
+                },
+                "body": [
+                    {
+                        "type":   "TextBlock",
+                        "text":   title,
+                        "color":  theme_color,
+                        "weight": "bolder",
+                        "size":   "large",
+                        "wrap":   True
+                    },
+                    {
+                        "type":   "CodeBlock",
+                        "codeSnippet":   message,
+                        "language":   "PlainText"
+                    }
+                ]
+            }
+        }
+        ]
+    }

     headers = {
         "Content-Type": "application/json",
@@ -82,7 +112,7 @@
         status=True,
     )

-    if result["status"] <= 201:
+    if result["status"] <= 202:
         return True
     else:
         return {"res": False, "message": result.get("body", result["status"])}

Please Note If this feature request would be considered a substantial change or addition, this should go through a SEP process here https://github.com/saltstack/salt-enhancement-proposals, instead of a feature request.

max-arnold commented 2 weeks ago

As of Salt 3008 (upcoming), the msteams state/module no longer will be shipped with Salt (see https://github.com/saltstack/salt/pull/65971). If you want to fix the module and continue using it, please consider porting it to a Salt extension so it can be developed and released independently and much faster.

The Salt extensions community created a new guide and tooling for extension maintainers https://salt-extensions.github.io/salt-extension-copier/

If you need some help or encounter difficulties in using the tools on a Windows machine, feel free to join the #salt-extensions channel on Discord and ask there.