init: Initial commit

This commit is contained in:
Björn Benouarets
2026-01-19 14:14:54 +01:00
commit ee9903b704
15 changed files with 18072 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
class AdaptiveCard:
def __init__(self, body: list[dict] | None = None, actions: list[dict] | None = None) -> None:
self.__body = body if body else []
self.__actions = actions if actions else []
@property
def data(self) -> dict:
return {
"type": "AdaptiveCard",
"body": self.__body,
"actions": self.__actions,
"version": "1.6",
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json"
}

View File

@@ -0,0 +1,25 @@
import os
import json
import re
class Template:
def __init__(self, name: str) -> None:
self.__name = name
self.__path = "templates/" + name + ".json"
self.__template = json.load(open(self.__path))
def __str__(self) -> str:
return json.dumps(self.__template)
def replace_placeholders(self, data: dict) -> dict:
"""Return the template as a dictionary with placeholders replaced."""
template_str = json.dumps(self.__template)
for key, value in data.items():
template_str = template_str.replace(f'{{{{{key}}}}}', str(value))
return json.loads(template_str)
def render(self, data: dict) -> str:
"""Return the template as a JSON string with placeholders replaced."""
return json.dumps(self.replace_placeholders(data))

View File

@@ -0,0 +1,13 @@
import os
import json
from bot.msteams.adaptivecard.card import AdaptiveCard
from bot.msteams.adaptivecard.template import Template
class WebhookCard(AdaptiveCard):
def __init__(self, data: dict, template: Template) -> None:
super().__init__(body=template.replace_placeholders(data)["body"], actions=template.replace_placeholders(data)["actions"])
@property
def data(self) -> dict:
return super().data