init: Initial commit
This commit is contained in:
44
commands/help.py
Normal file
44
commands/help.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from botbuilder.core import TurnContext, MessageFactory, CardFactory
|
||||
from botbuilder.schema import Attachment
|
||||
|
||||
from modules.database import DatabaseManager
|
||||
from modules.template import TemplateEngine
|
||||
|
||||
class HelpCommand:
|
||||
def __init__(self, turn_context: TurnContext, database: DatabaseManager) -> None:
|
||||
self.turn_context = turn_context
|
||||
self.database = database
|
||||
|
||||
async def handle_help(self) -> None:
|
||||
template = TemplateEngine("help-command-card")
|
||||
card = template.json_dict({
|
||||
"card_title": "Help",
|
||||
"card_icon": "🚨",
|
||||
"card_description": "You can use the following commands to interact with the bot:",
|
||||
})
|
||||
commands = [
|
||||
{
|
||||
"title": "**/help**",
|
||||
"value": "Show this help message"
|
||||
},
|
||||
{
|
||||
"title": "**/test** <message>",
|
||||
"value": "Test the bot"
|
||||
},
|
||||
{
|
||||
"title": "**/webhooks** create",
|
||||
"value": "Create a new webhook"
|
||||
},
|
||||
{
|
||||
"title": "**/webhooks** delete",
|
||||
"value": "Delete a webhook"
|
||||
},
|
||||
{
|
||||
"title": "**/webhooks** list",
|
||||
"value": "List all webhooks"
|
||||
}
|
||||
]
|
||||
card["body"][2]["facts"] = commands
|
||||
card_attachment = CardFactory.adaptive_card(card)
|
||||
await self.turn_context.send_activity(MessageFactory.attachment(card_attachment))
|
||||
return
|
||||
@@ -10,32 +10,28 @@ class TestCommand:
|
||||
def __init__(self, database: DatabaseManager):
|
||||
self.database = database
|
||||
|
||||
async def handle_test(self, turn_context: TurnContext, message: str) -> None:
|
||||
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
|
||||
# conversation_reference = TurnContext.get_conversation_reference(turn_context.activity)
|
||||
|
||||
# Check if the channel is a Microsoft Teams channel (msteams) or emulator (for testing)
|
||||
channel_id_str = activity.channel_id
|
||||
|
||||
channel_data = activity.channel_data
|
||||
|
||||
# channel_data is a dictionary, access it as such
|
||||
teams_id = channel_data.get('teamsTeamId') if channel_data and isinstance(channel_data, dict) else None
|
||||
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":
|
||||
teams_id = "00000000-0000-0000-0000-000000000000"
|
||||
microsoft_teams_id_str = "00000000-0000-0000-0000-000000000000"
|
||||
microsoft_channel_id_str = "00000000-0000-0000-0000-000000000000"
|
||||
|
||||
# Load template and prepare data
|
||||
template = TemplateEngine("card")
|
||||
|
||||
# Create and send the Adaptive Card
|
||||
card_attachment = CardFactory.adaptive_card(template.generate({"card_type": "Test", "card_title": "Test", "card_content": message}))
|
||||
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)}))
|
||||
|
||||
# Send the attachment as a reply to the post in the channel
|
||||
result = await turn_context.send_activity(MessageFactory.attachment(card_attachment))
|
||||
await turn_context.send_activity(MessageFactory.attachment(card_attachment))
|
||||
return
|
||||
except Exception as e:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
@@ -16,29 +16,23 @@ class WebhookCommand:
|
||||
async def handle_list_webhooks(self, turn_context: TurnContext) -> None:
|
||||
try:
|
||||
activity = turn_context.activity
|
||||
# conversation_reference = TurnContext.get_conversation_reference(turn_context.activity)
|
||||
|
||||
# Check if the channel is a Microsoft Teams channel (msteams) or emulator (for testing)
|
||||
channel_id_str = activity.channel_id
|
||||
|
||||
channel_data = activity.channel_data
|
||||
|
||||
# channel_data is a dictionary, access it as such
|
||||
teams_id = channel_data.get('teamsTeamId') if channel_data and isinstance(channel_data, dict) else None
|
||||
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":
|
||||
teams_id = "00000000-0000-0000-0000-000000000000"
|
||||
microsoft_teams_id_str = "00000000-0000-0000-0000-000000000000"
|
||||
microsoft_channel_id_str = "00000000-0000-0000-0000-000000000000"
|
||||
|
||||
# Get the actual channel UUID from the database
|
||||
channel_uuid = None
|
||||
webhook_count = 0
|
||||
|
||||
if microsoft_channel_id_str:
|
||||
try:
|
||||
from uuid import UUID
|
||||
# Try to get channel by Microsoft Teams channel ID
|
||||
microsoft_channel_id = UUID(microsoft_channel_id_str) if isinstance(microsoft_channel_id_str, str) else microsoft_channel_id_str
|
||||
channel_obj = self.database.get_channel_by_microsoft_channel_id(str(microsoft_channel_id))
|
||||
if channel_obj:
|
||||
@@ -47,14 +41,10 @@ class WebhookCommand:
|
||||
except (ValueError, TypeError) as e:
|
||||
webhook_count = 0
|
||||
|
||||
# Load template and prepare data
|
||||
template = TemplateEngine("webhook-overview-card" if webhook_count > 0 else "webhook-overview-no-webhooks-card")
|
||||
|
||||
# Create and send the Adaptive Card
|
||||
card_attachment = self.create_webhooks_card(template, {"webhook_count": webhook_count})
|
||||
|
||||
# Send the attachment as a reply to the post in the channel
|
||||
result = await turn_context.send_activity(MessageFactory.attachment(card_attachment))
|
||||
await turn_context.send_activity(MessageFactory.attachment(card_attachment))
|
||||
return
|
||||
except Exception as e:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
Reference in New Issue
Block a user