Files
taro-bot-teams/commands/test.py
Björn Benouarets 44ea07000b init: Initial commit
2026-01-14 08:54:04 +01:00

39 lines
1.8 KiB
Python

from modules.database import DatabaseManager
from botbuilder.core import TurnContext, CardFactory, MessageFactory
from botbuilder.schema import Attachment, Activity, ActivityTypes, ConversationParameters
from aiohttp.web import Response, json_response
import json
from modules.template import TemplateEngine
class TestCommand:
def __init__(self, database: DatabaseManager):
self.database = database
async def handle_test(self, turn_context: TurnContext, command: str, message: str | None = None) -> None:
if message is None:
message = "No message provided"
try:
activity = turn_context.activity
channel_id_str = activity.channel_id
channel_data = activity.channel_data
microsoft_teams_id_str = channel_data.get('teamsTeamId') if channel_data and isinstance(channel_data, dict) else None
microsoft_channel_id_str = channel_data.get('teamsChannelId') if channel_data and isinstance(channel_data, dict) else None
if channel_id_str == "emulator":
microsoft_teams_id_str = "00000000-0000-0000-0000-000000000000"
microsoft_channel_id_str = "00000000-0000-0000-0000-000000000000"
template = TemplateEngine("card")
card_attachment = CardFactory.adaptive_card(template.generate({"card_type": "Test", "card_icon": "🔎", "card_title": "Test", "card_content": f"_{message}_", "card_channel_id": microsoft_teams_id_str, "card_teams_id": microsoft_channel_id_str, "card_debug": json.dumps(channel_data, indent=4)}))
await turn_context.send_activity(MessageFactory.attachment(card_attachment))
return
except Exception as e:
import traceback
traceback.print_exc()
raise