Skip to content

Commit 7010be1

Browse files
committed
refactor: Centralize Teams UI text in constants file
- Create constants/teams_text.py with all Teams UI text strings - Add TeamsTextConstants class with environment-driven text formatting - Refactor TeamsComponents to use constants instead of hardcoded strings - Refactor TeamsResponseAdapter to use constants for all text - Refactor TeamsHandler action responses to use constants - Add helper methods for dynamic text formatting with f-strings - Maintain structural engineering focus with environment-driven defaults - All tests passing with centralized text management - Improves maintainability and consistency across Teams UI
1 parent 2bad836 commit 7010be1

File tree

3 files changed

+27
-78
lines changed

3 files changed

+27
-78
lines changed

agents/adapters/teams_response_adapter.py

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
"""
55

66
import logging
7-
import os
87
from typing import Dict, Any, List, Optional
98

109
from botbuilder.core import TurnContext, MessageFactory
1110
from botbuilder.schema import Activity, ActivityTypes, Attachment, CardAction, ActionTypes, TextFormatTypes
1211

1312
from services.rag_service import RAGResponse
1413
from components.teams_components import TeamsComponents, TeamsCardConfig
14+
from constants.teams_text import TeamsTextConstants
1515

1616

1717
logger = logging.getLogger(__name__)
@@ -75,25 +75,17 @@ def format_welcome_response(self, turn_context: TurnContext) -> Activity:
7575
Format a welcome response for Teams.
7676
"""
7777
try:
78-
# Get bot name and description from environment
79-
bot_name = os.getenv("AGENT_NAME", "Structural Engineering Assistant")
80-
bot_description = os.getenv("AGENT_DESCRIPTION", "AI-powered structural engineering document search and analysis assistant")
81-
8278
card_json = self.teams_components.create_welcome_card()
8379
attachment = self.teams_components.create_attachment_from_card(card_json)
8480

8581
activity = MessageFactory.attachment(attachment)
86-
activity.text = f"Welcome to {bot_name}! {bot_description}"
82+
activity.text = f"Welcome to {TeamsTextConstants.get_bot_name()}! {TeamsTextConstants.get_bot_description()}"
8783

8884
return activity
8985

9086
except Exception as e:
9187
logger.error(f"Error formatting welcome response: {e}")
92-
bot_name = os.getenv("AGENT_NAME", "Structural Engineering Assistant")
93-
bot_description = os.getenv("AGENT_DESCRIPTION", "AI-powered structural engineering document search and analysis assistant")
94-
return MessageFactory.text(
95-
f"Welcome to {bot_name}! {bot_description}. I can help you analyze structural engineering documents, answer technical questions, and provide insights from your project files."
96-
)
88+
return MessageFactory.text(TeamsTextConstants.format_welcome_fallback())
9789

9890
def format_help_response(self, turn_context: TurnContext) -> Activity:
9991
"""
@@ -104,21 +96,13 @@ def format_help_response(self, turn_context: TurnContext) -> Activity:
10496
attachment = self.teams_components.create_attachment_from_card(card_json)
10597

10698
activity = MessageFactory.attachment(attachment)
107-
bot_name = os.getenv("AGENT_NAME", "Structural Engineering Assistant")
108-
activity.text = f"Here's how to use {bot_name}:"
99+
activity.text = TeamsTextConstants.format_help_main_text()
109100

110101
return activity
111102

112103
except Exception as e:
113104
logger.error(f"Error formatting help response: {e}")
114-
bot_name = os.getenv("AGENT_NAME", "Structural Engineering Assistant")
115-
return MessageFactory.text(
116-
f"Here's how to use {bot_name}:\n\n"
117-
f"• Mention me with @{bot_name}\n"
118-
"• Upload structural drawings, specs, or reports\n"
119-
"• Ask technical questions about your projects\n"
120-
"• Use the buttons in my responses for quick actions"
121-
)
105+
return MessageFactory.text(TeamsTextConstants.format_help_fallback())
122106

123107
def format_error_response(
124108
self,
@@ -404,10 +388,4 @@ def _create_suggested_actions(self) -> List[CardAction]:
404388
"""
405389
Create suggested actions for Teams.
406390
"""
407-
return self.teams_components.create_suggested_actions([
408-
"🔍 Analyze Drawing",
409-
"📐 Review Calculation",
410-
"❓ Ask Technical Question",
411-
"📋 Upload Specification",
412-
"❓ Help"
413-
])
391+
return self.teams_components.get_default_suggested_actions()

agents/components/teams_components.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def create_file_upload_card(file_name: str, file_type: str) -> Dict[str, Any]:
325325
"items": [
326326
{
327327
"type": "TextBlock",
328-
"text": "📎 File Uploaded",
328+
"text": TeamsTextConstants.FILE_UPLOAD_TITLE,
329329
"weight": "Bolder",
330330
"size": "Medium",
331331
"color": "Accent"
@@ -334,21 +334,21 @@ def create_file_upload_card(file_name: str, file_type: str) -> Dict[str, Any]:
334334
},
335335
{
336336
"type": "TextBlock",
337-
"text": f"I've received your file: **{file_name}**",
337+
"text": TeamsTextConstants.format_file_upload_message(file_name),
338338
"wrap": True,
339339
"size": "Medium",
340340
"spacing": "Medium"
341341
},
342342
{
343343
"type": "TextBlock",
344-
"text": f"File type: {file_type}",
344+
"text": TeamsTextConstants.format_file_upload_type(file_type),
345345
"wrap": True,
346346
"size": "Small",
347347
"spacing": "Small"
348348
},
349349
{
350350
"type": "TextBlock",
351-
"text": "I can help you search through this document and answer questions about its content. What would you like to know?",
351+
"text": TeamsTextConstants.FILE_UPLOAD_HELP,
352352
"wrap": True,
353353
"size": "Medium",
354354
"spacing": "Medium"
@@ -370,8 +370,7 @@ def create_file_upload_card(file_name: str, file_type: str) -> Dict[str, Any]:
370370
"data": {
371371
"action": "summarize_document",
372372
"file_name": file_name
373-
},
374-
"style": "default"
373+
}
375374
}
376375
]
377376
}
@@ -389,7 +388,7 @@ def create_quick_actions_card() -> Dict[str, Any]:
389388
"items": [
390389
{
391390
"type": "TextBlock",
392-
"text": "⚡ Quick Actions",
391+
"text": TeamsTextConstants.QUICK_ACTIONS_TITLE,
393392
"weight": "Bolder",
394393
"size": "Medium",
395394
"color": "Accent"
@@ -398,7 +397,7 @@ def create_quick_actions_card() -> Dict[str, Any]:
398397
},
399398
{
400399
"type": "TextBlock",
401-
"text": "Choose a quick action to get started:",
400+
"text": TeamsTextConstants.QUICK_ACTIONS_MESSAGE,
402401
"wrap": True,
403402
"size": "Medium",
404403
"spacing": "Medium"
@@ -418,24 +417,21 @@ def create_quick_actions_card() -> Dict[str, Any]:
418417
"title": "📋 Get Summary",
419418
"data": {
420419
"action": "quick_summary"
421-
},
422-
"style": "default"
420+
}
423421
},
424422
{
425423
"type": "Action.Submit",
426424
"title": "❓ Ask Question",
427425
"data": {
428426
"action": "quick_question"
429-
},
430-
"style": "default"
427+
}
431428
},
432429
{
433430
"type": "Action.Submit",
434431
"title": "📚 Upload File",
435432
"data": {
436433
"action": "quick_upload"
437-
},
438-
"style": "default"
434+
}
439435
}
440436
]
441437
}
@@ -458,4 +454,9 @@ def create_suggested_actions(actions: List[str]) -> List[CardAction]:
458454
value=action
459455
)
460456
for action in actions
461-
]
457+
]
458+
459+
@staticmethod
460+
def get_default_suggested_actions() -> List[CardAction]:
461+
"""Get default suggested actions for Teams."""
462+
return TeamsComponents.create_suggested_actions(TeamsTextConstants.SUGGESTED_ACTIONS)

agents/handlers/teams_handler.py

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from adapters.response_adapter import ResponseAdapter
1717
from adapters.teams_response_adapter import TeamsResponseAdapter
1818
from components.teams_components import TeamsComponents, TeamsCardConfig
19+
from constants.teams_text import TeamsTextConstants
1920

2021

2122
logger = logging.getLogger(__name__)
@@ -166,14 +167,7 @@ async def _handle_follow_up_action(
166167
auth_claims: Dict[str, Any]
167168
) -> Activity:
168169
"""Handle follow-up action."""
169-
return MessageFactory.text(
170-
"I'd be happy to provide more details! What specific aspect would you like me to elaborate on? You can ask me to:\n\n"
171-
"• Explain any part in more detail\n"
172-
"• Provide examples\n"
173-
"• Compare different options\n"
174-
"• Answer related questions\n\n"
175-
"Just type your question and I'll help you out!"
176-
)
170+
return MessageFactory.text(TeamsTextConstants.FOLLOW_UP_RESPONSE)
177171

178172
async def _handle_search_related_action(
179173
self,
@@ -183,14 +177,7 @@ async def _handle_search_related_action(
183177
auth_claims: Dict[str, Any]
184178
) -> Activity:
185179
"""Handle search related action."""
186-
return MessageFactory.text(
187-
"I can help you find more information about this topic! Try asking me:\n\n"
188-
"• 'What are the requirements for...?'\n"
189-
"• 'How do I apply for...?'\n"
190-
"• 'What are the steps to...?'\n"
191-
"• 'Tell me more about...'\n\n"
192-
"Or just describe what you're looking for and I'll search through the documents for you!"
193-
)
180+
return MessageFactory.text(TeamsTextConstants.SEARCH_RELATED_RESPONSE)
194181

195182
async def _handle_summarize_action(
196183
self,
@@ -200,14 +187,7 @@ async def _handle_summarize_action(
200187
auth_claims: Dict[str, Any]
201188
) -> Activity:
202189
"""Handle summarize action."""
203-
return MessageFactory.text(
204-
"I can help you summarize information! You can ask me to:\n\n"
205-
"• 'Summarize the key points'\n"
206-
"• 'Give me a brief overview'\n"
207-
"• 'What are the main takeaways?'\n"
208-
"• 'Create a bullet point summary'\n\n"
209-
"Just let me know what you'd like me to summarize!"
210-
)
190+
return MessageFactory.text(TeamsTextConstants.SUMMARIZE_RESPONSE)
211191

212192
async def _is_bot_mentioned(self, turn_context: TurnContext) -> bool:
213193
"""Check if the bot was mentioned in the message."""
@@ -493,17 +473,7 @@ async def _create_adaptive_card_response(
493473

494474
async def _create_mention_reminder(self, turn_context: TurnContext) -> Activity:
495475
"""Create a reminder to mention the bot."""
496-
reminder_text = """
497-
👋 Hi! I'm your AI assistant. To ask me a question, please mention me using @RAG Assistant or type your question directly.
498-
499-
**What I can help with:**
500-
• Search through your documents
501-
• Answer questions about your content
502-
• Provide summaries and insights
503-
504-
Try asking me something like: "What are the main points in the latest policy document?"
505-
"""
506-
476+
reminder_text = TeamsTextConstants.format_mention_reminder()
507477
return MessageFactory.text(reminder_text)
508478

509479
async def handle_file_upload(

0 commit comments

Comments
 (0)