### Install pymsteams Source: https://github.com/rveachkc/pymsteams/blob/master/README.md Installs the pymsteams library using pip. For asynchronous capabilities, install with the '[async]' extra, requiring Python 3.6 or later. ```bash pip install pymsteams pip install pymsteams[async] ``` -------------------------------- ### Testing pymsteams with pytest (Bash) Source: https://github.com/rveachkc/pymsteams/blob/master/README.md Provides instructions for setting up and running tests for the pymsteams library using pytest. It outlines the necessary steps: installing requirements, setting the MS_TEAMS_WEBHOOK environment variable, and executing the pytest command with coverage reporting. ```bash pip install -r dev-requirements.txt MS_TEAMS_WEBHOOK=MicrosoftWebhookURL export MS_TEAMS_WEBHOOK pytest --cov=./pymsteams --cov-report=term-missing --cov-branch ``` -------------------------------- ### Configure Proxy Settings for PyMSTeams Source: https://context7.com/rveachkc/pymsteams/llms.txt This example shows how to configure proxy settings for sending messages via PyMSTeams. It demonstrates initializing the connector card with a webhook URL, implying that proxy settings would be applied at a lower level, possibly through environment variables or a session configuration if the library supported it directly on initialization. The provided snippet is incomplete for full proxy configuration. ```python import pymsteams webhook_url = "https://outlook.webhook.office.com/webhookb2/..." # Proxy configuration would typically be set here or via environment variables # Example: os.environ['HTTP_PROXY'] = 'http://user:pass@host:port' # Example: os.environ['HTTPS_PROXY'] = 'https://user:pass@host:port' # The pymsteams.connectorcard initialization itself does not directly take proxy arguments. # It relies on the underlying HTTP client's configuration. # For more advanced proxy handling, consider using a library like 'requests' # with a custom Session object passed to pymsteams if the library supports it, # or managing proxy settings globally via environment variables. ``` -------------------------------- ### Async Message Sending with asyncio in PyMSTeams Source: https://context7.com/rveachkc/pymsteams/llms.txt Illustrates how to send Microsoft Teams messages asynchronously using Python's asyncio library. It covers sending a single async message and multiple messages concurrently. This approach ensures non-blocking operations. Requires `pymsteams[async]` installation. ```python import asyncio import pymsteams async def send_notification(): webhook_url = "https://outlook.webhook.office.com/webhookb2/..." # Use async_connectorcard instead of connectorcard teams_message = pymsteams.async_connectorcard(webhook_url) teams_message.title("Async Notification") teams_message.text("This message was sent asynchronously") teams_message.color("0078D4") try: await teams_message.send() print("Async message sent successfully") return teams_message.last_http_response.status_code except pymsteams.TeamsWebhookException as e: print(f"Failed to send async message: {e}") return None async def send_multiple_notifications(): # Send multiple messages concurrently webhook_url = "https://outlook.webhook.office.com/webhookb2/..." messages = [] for i in range(5): msg = pymsteams.async_connectorcard(webhook_url) msg.title(f"Task {i+1} Completed") msg.text(f"Processing task {i+1} finished successfully") messages.append(msg.send()) # Wait for all messages to complete results = await asyncio.gather(*messages, return_exceptions=True) for i, result in enumerate(results): if isinstance(result, Exception): print(f"Message {i+1} failed: {result}") else: print(f"Message {i+1} sent successfully") # Run async function asyncio.run(send_notification()) # Or run multiple messages concurrently asyncio.run(send_multiple_notifications()) # Note: Requires installation with async extras: pip install pymsteams[async] ``` -------------------------------- ### Dynamically Switch Webhook URLs with pymsteams Source: https://context7.com/rveachkc/pymsteams/llms.txt This example shows how to send the same message to multiple Microsoft Teams channels by dynamically switching the webhook URL. It defines a dictionary of webhook URLs, creates a message, and then iterates through the defined webhooks to send the message to each channel using the `newhookurl` method. Error handling is included for each send attempt. ```python import pymsteams # Define multiple webhook URLs for different channels webhooks = { "dev_team": "https://outlook.webhook.office.com/webhookb2/.../dev", "ops_team": "https://outlook.webhook.office.com/webhookb2/.../ops", "management": "https://outlook.webhook.office.com/webhookb2/.../mgmt" } # Create message once teams_message = pymsteams.connectorcard(webhooks["dev_team"]) teams_message.title("Critical System Alert") teams_message.text("Database server is experiencing high load") teams_message.color("red") section = pymsteams.cardsection() section.title("Server Status") section.addFact("Server", "db-prod-01") section.addFact("CPU", "98%") section.addFact("Memory", "95%") section.addFact("Connections", "500/500") teams_message.addSection(section) # Send to multiple channels for channel_name, webhook_url in webhooks.items(): teams_message.newhookurl(webhook_url) try: teams_message.send() print(f"Alert sent to {channel_name}") except pymsteams.TeamsWebhookException as e: print(f"Failed to send to {channel_name}: {e}") ``` -------------------------------- ### Create Interactive Teams Messages with Actions (Python) Source: https://context7.com/rveachkc/pymsteams/llms.txt This Python example shows how to build an interactive Microsoft Teams message with input fields and action buttons. It uses the potentialaction class to define an action that allows users to submit text input via an HTTP POST request. Requires a webhook URL. ```python import pymsteams webhook_url = "https://outlook.webhook.office.com/webhookb2/" teams_message = pymsteams.connectorcard(webhook_url) teams_message.title("New Support Ticket #7821") teams_message.text("Customer reported login issues on mobile application") teams_message.summary("New support ticket requires assignment") # Create action for adding comments action_comment = pymsteams.potentialaction(_name="Add Comment") action_comment.addInput("TextInput", "comment", "Enter your comment", False) action_comment.addAction("HttpPost", "Submit Comment", "https://api.example.com/tickets/7821/comments") ``` -------------------------------- ### Send Messages with HTTP POST Body Templates in PyMSTeams Source: https://context7.com/rveachkc/pymsteams/llms.txt Shows how to create interactive actions that submit custom JSON payloads using input values as template variables. The example demonstrates adding text and multi-choice inputs, defining choices, and configuring an HttpPost action with a JSON template. It also notes how Teams encodes the POST data. ```python import pymsteams webhook_url = "https://outlook.webhook.office.com/webhookb2/..." teams_message = pymsteams.connectorcard(webhook_url) teams_message.title("Code Review Request") teams_message.text("Pull Request #456 ready for review") teams_message.summary("PR review required") # Create action with custom POST body using input values action_review = pymsteams.potentialaction(_name="Submit Review") action_review.addInput("TextInput", "feedback", "Enter your review feedback", True) action_review.addInput("MultichoiceInput", "approval", "Decision", False) action_review.choices.addChoices("Approve", "approved") action_review.choices.addChoices("Request Changes", "changes_requested") action_review.choices.addChoices("Comment Only", "commented") # Use template variables from input IDs - Teams will replace with actual values # When user submits, {{feedback.value}} and {{approval.value}} will be replaced action_review.addAction( "HttpPost", "Submit Review", "https://api.example.com/reviews", '{"pr_id": 456, "feedback": "{{feedback.value}}", "status": "{{approval.value}}"}' ) teams_message.addPotentialAction(action_review) try: teams_message.send() except pymsteams.TeamsWebhookException as e: print(f"Error: {e}") # Note: Teams will encode the POST data with Unicode escapes # For example: {"feedback": "looks good"} becomes # b'{\\u0022feedback\\u0022:\\u0022looks good\\u0022}' # Your API should decode unicode escapes when receiving webhook data ``` -------------------------------- ### Send Async Message to Teams Source: https://github.com/rveachkc/pymsteams/blob/master/README.md Sends a message to Microsoft Teams asynchronously using the 'async_connectorcard' object. This requires the 'pymsteams[async]' installation and Python 3.6+. The message is sent via an asyncio event loop. ```python import asyncio import pymsteams loop = asyncio.get_event_loop() myTeamsMessage = pymsteams.async_connectorcard("") myTeamsMessage.text("This is my message") loop.run_until_complete(myTeamsMessage.send()) ``` -------------------------------- ### Configure Certificate Validation for MS Teams Webhook (Python) Source: https://github.com/rveachkc/pymsteams/blob/master/README.md Details how to configure SSL certificate validation when initializing a pymsteams connector card. It provides examples for setting a custom CA bundle path or disabling verification entirely by setting `verify` to `False`. This is useful in environments with custom certificate requirements. ```python import pymsteams # set custom ca bundle msg = pymsteams.connectorcard("", verify="/path/to/file") # disable CA validation msg = pymsteams.connectorcard("", verify=False) ``` -------------------------------- ### Method Chaining for Fluent Interface in Pymsteams Source: https://context7.com/rveachkc/pymsteams/llms.txt Utilize method chaining for a fluent interface to build and send messages concisely. Demonstrates chaining for basic message elements and adding sections with facts. ```python import pymsteams webhook_url = "https://outlook.webhook.office.com/webhookb2/..." # Create and send message with method chaining try: result = (pymsteams.connectorcard(webhook_url) .title("Deployment Pipeline") .text("Build #1234 completed and deployed to staging") .color("00FF00") .addLinkButton("View Build", "https://ci.example.com/builds/1234") .addLinkButton("View Staging", "https://staging.example.com") .send()) print("Message sent successfully" if result else "Message failed") except pymsteams.TeamsWebhookException as e: print(f"Error: {e}") # Method chaining with sections section = ( pymsteams.cardsection() .title("Performance Metrics") .activityTitle("Daily Report") .activitySubtitle("Generated at 08:00 UTC") .activityImage("https://example.com/chart-icon.png") .addFact("Total Requests", "1,234,567") .addFact("Avg Response Time", "145ms") .addFact("Error Rate", "0.02%") .text("All metrics within normal ranges") ) (pymsteams.connectorcard(webhook_url) .title("Daily Performance Report") .addSection(section) .send()) ``` -------------------------------- ### Debug Message Payload Before Sending with Python Source: https://context7.com/rveachkc/pymsteams/llms.txt This Python snippet demonstrates how to preview the complete message structure and webhook URL before sending it to Microsoft Teams. It uses the pymsteams library to construct a card message, add sections and facts, print the debug output, and then display the formatted JSON payload. It also includes basic validation and a try-except block for sending the message. ```python import pymsteams import json webhook_url = "https://outlook.webhook.office.com/webhookb2/..." teams_message = pymsteams.connectorcard(webhook_url) teams_message.title("Test Message") teams_message.text("Debugging message payload") teams_message.color("0078D4") section = pymsteams.cardsection() section.title("Debug Info") section.addFact("Environment", "staging") section.addFact("Version", "2.3.0") teams_message.addSection(section) # Print debug information print("=== DEBUG OUTPUT ===") teams_message.printme() print("\n=== FORMATTED PAYLOAD ===") print(json.dumps(teams_message.payload, indent=2)) # Verify payload structure before sending if "title" in teams_message.payload and "text" in teams_message.payload: print("\nāœ“ Payload validation passed") try: teams_message.send() print("āœ“ Message sent successfully") except pymsteams.TeamsWebhookException as e: print(f"āœ— Send failed: {e}") else: print("\nāœ— Payload validation failed - missing required fields") ``` -------------------------------- ### Create Interactive Messages with PyMSTeams Source: https://context7.com/rveachkc/pymsteams/llms.txt Demonstrates how to create interactive messages in Microsoft Teams using the PyMSTeams library. This includes setting due dates, changing status via multiple choice, and opening external links. It shows how to add various action types to a message object and send it. ```python import pymsteams # Assuming teams_message is already initialized # teams_message = pymsteams.connectorcard(webhook_url) # Create action for setting due date action_duedate = pymsteams.potentialaction(_name="Set Due Date") action_duedate.addInput("DateInput", "dueDate", "Select due date") action_duedate.addAction("HttpPost", "Save Due Date", "https://api.example.com/tickets/7821/duedate") # Create action with multiple choice dropdown action_status = pymsteams.potentialaction(_name="Change Status") action_status.choices.addChoices("Open", "0") action_status.choices.addChoices("In Progress", "1") action_status.choices.addChoices("Resolved", "2") action_status.choices.addChoices("Closed", "3") action_status.addInput("MultichoiceInput", "status", "Select ticket status", False) action_status.addAction("HttpPost", "Update Status", "https://api.example.com/tickets/7821/status") # Create OpenURI action for external links action_link = pymsteams.potentialaction(_name="View Ticket") action_link.addOpenURI("Open Ticket", [{"os": "default", "uri": "https://support.example.com/tickets/7821"}]) # Add all actions to message # teams_message.addPotentialAction(action_comment) # Assuming action_comment exists teams_message.addPotentialAction(action_duedate) teams_message.addPotentialAction(action_status) teams_message.addPotentialAction(action_link) try: teams_message.send() except pymsteams.TeamsWebhookException as e: print(f"Error sending interactive message: {e}") ``` -------------------------------- ### Create Teams Messages with Sections and Images (Python) Source: https://context7.com/rveachkc/pymsteams/llms.txt This Python snippet demonstrates creating a structured Microsoft Teams message with multiple sections, including activities, facts, and images. It uses the cardsection class to build distinct content blocks, allowing for organized display of information like alerts and performance data. Requires a webhook URL. ```python import pymsteams webhook_url = "https://outlook.webhook.office.com/webhookb2/" teams_message = pymsteams.connectorcard(webhook_url) teams_message.title("Server Monitoring Alert") teams_message.text("Multiple metrics exceeded thresholds") # Create first section with activity and facts section_1 = pymsteams.cardsection() section_1.title("Server web-01") section_1.activityTitle("Alert Triggered") section_1.activitySubtitle("Critical threshold exceeded") section_1.activityImage("https://example.com/alert-icon.png") section_1.activityText("CPU and memory usage have exceeded configured thresholds.") section_1.addFact("CPU Usage", "95%") section_1.addFact("Memory Usage", "89%") section_1.addFact("Alert Time", "2025-11-14 10:30:00 UTC") section_1.text("Immediate attention required for server web-01.") # Create second section with image section_2 = pymsteams.cardsection() section_2.title("Performance Graph") section_2.text("24-hour performance trend showing spike at 10:30 UTC") section_2.addImage("https://example.com/performance-graph.png", ititle="CPU Usage Last 24h") # Add sections and send teams_message.addSection(section_1) teams_message.addSection(section_2) try: teams_message.send() except pymsteams.TeamsWebhookException as e: print(f"Failed to send alert: {e}") ``` -------------------------------- ### Configure HTTP and HTTPS Proxies with Timeout Source: https://context7.com/rveachkc/pymsteams/llms.txt Configure both HTTP and HTTPS proxies for sending messages to Microsoft Teams. Sets a custom HTTP timeout. Includes error handling for webhook exceptions. ```python import pymsteams webhook_url = "your_webhook_url_here" teams_message = pymsteams.connectorcard( webhook_url, http_proxy="http://proxy.corporate.com:8080", https_proxy="https://proxy.corporate.com:8443", http_timeout=120 # Set timeout to 120 seconds ) teams_message.title("Message via Proxy") teams_message.text("This message is routed through corporate proxy servers") try: teams_message.send() print(f"Message sent via proxy. Status: {teams_message.last_http_response.status_code}") except pymsteams.TeamsWebhookException as e: print(f"Proxy connection failed: {e}") ``` -------------------------------- ### Format Markdown Links in Pymsteams Message Text Source: https://context7.com/rveachkc/pymsteams/llms.txt Use the `formaturl` helper function to create markdown-formatted links within message text for a more interactive and informative Teams message. Shows how to embed these links in the message body. ```python import pymsteams webhook_url = "https://outlook.webhook.office.com/webhookb2/..." teams_message = pymsteams.connectorcard(webhook_url) # Create markdown links using formaturl helper repo_link = pymsteams.formaturl("GitHub Repository", "https://github.com/example/project") docs_link = pymsteams.formaturl("Documentation", "https://docs.example.com") api_link = pymsteams.formaturl("API Reference", "https://api.example.com/docs") # Compose message text with embedded links message_text = f""" New release v2.3.0 is now available! Please review the {docs_link} for upgrade instructions. Source code is available in the {repo_link}. For integration details, see the {api_link}. """ teams_message.title("Release Announcement v2.3.0") teams_message.text(message_text) teams_message.color("0078D4") try: teams_message.send() except pymsteams.TeamsWebhookException as e: print(f"Error: {e}") ``` -------------------------------- ### Add HTTP Post to Potential Actions in MS Teams Connector Card (Python) Source: https://github.com/rveachkc/pymsteams/blob/master/README.md Illustrates how to add an HTTP Post action to a potential action within a Microsoft Teams connector card message. It specifically shows how to use input values in the POST request body and addresses potential JavaScript encoding issues when sending data, suggesting a method for decoding Unicode escapes. ```python myTeamsMessage = pymsteams.connectorcard("") myTeamsPotentialAction1 = pymsteams.potentialaction(_name = "Add a comment") # You can add a TextInput to your potential action like below - Please note the 2nd argment below as the id name myTeamsPotentialAction1.addInput("TextInput","comment","Add a comment here",False) # we use the 2nd argument above as the id name to parse the values into the body post like below. myTeamsPotentialAction1.addAction("HttpPost","Add Comment","https://...", "{{comment.value}}") myTeamsMessage.addPotentialAction(myTeamsPotentialAction1) myTeamsMessage.summary("Test Message") myTeamsMessage.send() # Notes: # If you post anything via teams, you will get some Javascript encoding happening via the post - For example: # Posting this: {"name":"john", "comment" : "nice"} # Output will be: b'{\\u0022name\u0022:\u0022john\u0022, \u0022comment\u0022 : \u0022nice\u0022}' # i solved this issue by decoding unicode escape for a custom rest backend. ``` -------------------------------- ### Add Potential Actions to MS Teams Connector Card Message (Python) Source: https://github.com/rveachkc/pymsteams/blob/master/README.md Demonstrates how to add interactive potential actions to a Microsoft Teams connector card message using the pymsteams library. This includes adding text input, date input, and multi-choice input functionalities. It shows how to create different types of actions like adding a comment, setting a due date, and changing a status. ```python myTeamsMessage = pymsteams.connectorcard("") myTeamsPotentialAction1 = pymsteams.potentialaction(_name = "Add a comment") myTeamsPotentialAction1.addInput("TextInput","comment","Add a comment here",False) myTeamsPotentialAction1.addAction("HttpPost","Add Comment","https://...") myTeamsPotentialAction2 = pymsteams.potentialaction(_name = "Set due date") myTeamsPotentialAction2.addInput("DateInput","dueDate","Enter due date") myTeamsPotentialAction2.addAction("HttpPost","save","https://...") myTeamsPotentialAction3 = pymsteams.potentialaction(_name = "Change Status") myTeamsPotentialAction3.choices.addChoices("In progress","0") myTeamsPotentialAction3.choices.addChoices("Active","1") myTeamsPotentialAction3.addInput("MultichoiceInput","list","Select a status",False) myTeamsPotentialAction3.addAction("HttpPost","Save","https://...") myTeamsMessage.addPotentialAction(myTeamsPotentialAction1) myTeamsMessage.addPotentialAction(myTeamsPotentialAction2) myTeamsMessage.addPotentialAction(myTeamsPotentialAction3) myTeamsMessage.summary("Test Message") myTeamsMessage.send() ``` -------------------------------- ### Handling Large Messages and Size Limits with Pymsteams Source: https://context7.com/rveachkc/pymsteams/llms.txt Demonstrates a strategy for managing Microsoft Teams message size limits (approximately 21,000 characters per section) by splitting content into manageable chunks. ```python import pymsteams webhook_url = "https://outlook.webhook.office.com/webhookb2/..." # Generate large log content log_data = "ERROR: Connection timeout\n" * 500 # Simulated large log file section_size_limit = 20000 # Stay under 21,000 character limit # Placeholder for actual message splitting logic # This example only sets up the scenario and does not implement the splitting mechanism. ``` -------------------------------- ### Send Simple Text Message to Teams Channel (Python) Source: https://context7.com/rveachkc/pymsteams/llms.txt This snippet demonstrates how to send a basic text message with a title to a Microsoft Teams channel using the pymsteams library. It requires a webhook URL and uses basic text and title methods for message composition. Error handling for sending is included. ```python import pymsteams # Initialize connector card with webhook URL from Teams channel settings webhook_url = "https://outlook.webhook.office.com/webhookb2/" teams_message = pymsteams.connectorcard(webhook_url) # Set message content and title teams_message.text("Deployment to production completed successfully!") teams_message.title("Deployment Notification") # Send the message try: teams_message.send() print(f"Message sent successfully. Status code: {teams_message.last_http_response.status_code}") except pymsteams.TeamsWebhookException as e: print(f"Failed to send message: {e}") ``` -------------------------------- ### Send Basic Text Message to Teams Source: https://github.com/rveachkc/pymsteams/blob/master/README.md Sends a simple plain text message to a Microsoft Teams channel using a webhook URL. Requires the 'pymsteams' library. ```python import pymsteams myTeamsMessage = pymsteams.connectorcard("") myTeamsMessage.text("this is my text") myTeamsMessage.send() ``` -------------------------------- ### Add Link Buttons to Teams Messages (Python) Source: https://context7.com/rveachkc/pymsteams/llms.txt This Python code shows how to add clickable link buttons to a Microsoft Teams message card. It composes a message with a title, text, sets a theme color, and attaches multiple buttons with associated URLs using the addLinkButton method. It requires a webhook URL. ```python import pymsteams webhook_url = "https://outlook.webhook.office.com/webhookb2/" teams_message = pymsteams.connectorcard(webhook_url) # Build message with multiple link buttons teams_message.title("Build #1234 Completed") teams_message.text("The production build has completed successfully.") teams_message.addLinkButton("View Build Logs", "https://ci.example.com/builds/1234") teams_message.addLinkButton("View Deployment", "https://app.example.com") # Set theme color (hex without # or "red") teams_message.color("00FF00") try: teams_message.send() except pymsteams.TeamsWebhookException as e: print(f"Error: {e}") ``` -------------------------------- ### Troubleshoot MS Teams HTTP Response using pymsteams (Python) Source: https://github.com/rveachkc/pymsteams/blob/master/README.md Explains how to access the last HTTP response from a Microsoft Teams webhook call using the pymsteams library. It shows how to retrieve the status code from the `last_http_response` attribute for troubleshooting purposes. Further details can be found in the requests library documentation. ```python import pymsteams myTeamsMessage = pymsteams.connectorcard("") myTeamsMessage.text("this is my text") myTeamsMessage.send() last_status_code = myTeamsMessage.last_http_response.status_code ``` -------------------------------- ### Format Teams Message Card Source: https://github.com/rveachkc/pymsteams/blob/master/README.md Adds various formatting elements to a Microsoft Teams connector card message object before sending. These methods include setting a title, adding link buttons, changing the webhook URL, setting a color theme, and previewing the message object. ```python myTeamsMessage.title("This is my message title") myTeamsMessage.addLinkButton("This is the button Text", "https://github.com/rveachkc/pymsteams/") myTeamsMessage.newhookurl("") myTeamsMessage.color("") myTeamsMessage.printme() ``` -------------------------------- ### Add Section to Teams Message Card Source: https://github.com/rveachkc/pymsteams/blob/master/README.md Constructs and adds a section to a Microsoft Teams connector card message. This includes setting a section title, activity elements (title, subtitle, image, text), facts (key-value pairs), text content, and images with optional titles. ```python myMessageSection = pymsteams.cardsection() myMessageSection.title("Section title") myMessageSection.activityTitle("my activity title") myMessageSection.activitySubtitle("my activity subtitle") myMessageSection.activityImage("http://i.imgur.com/c4jt321l.png") myMessageSection.activityText("This is my activity Text") myMessageSection.addFact("this", "is fine") myMessageSection.addFact("this is", "also fine") myMessageSection.text("This is my section text") myMessageSection.addImage("http://i.imgur.com/c4jt321l.png", ititle="This Is Fine") myTeamsMessage.addSection(myMessageSection) ``` -------------------------------- ### Custom SSL Certificate Validation with Pymsteams Source: https://context7.com/rveachkc/pymsteams/llms.txt Configure custom CA bundles or disable certificate verification for corporate SSL environments when sending messages. Demonstrates two options: using a custom CA bundle and disabling verification (not recommended for production). ```python import pymsteams webhook_url = "https://outlook.webhook.office.com/webhookb2/..." # Option 1: Use custom CA bundle teams_message_custom = pymsteams.connectorcard( webhook_url, verify="/path/to/corporate-ca-bundle.crt" ) teams_message_custom.title("Custom CA Bundle") teams_message_custom.text("Using corporate certificate authority") try: teams_message_custom.send() except pymsteams.TeamsWebhookException as e: print(f"Certificate validation error: {e}") # Option 2: Disable certificate validation (not recommended for production) teams_message_no_verify = pymsteams.connectorcard( webhook_url, verify=False ) teams_message_no_verify.title("No Certificate Validation") teams_message_no_verify.text("Certificate verification disabled") try: teams_message_no_verify.send() except pymsteams.TeamsWebhookException as e: print(f"Send failed: {e}") ``` -------------------------------- ### Inspect HTTP Response Details with pymsteams Source: https://context7.com/rveachkc/pymsteams/llms.txt This snippet demonstrates how to inspect detailed HTTP response information after sending a message using pymsteams. It captures the last HTTP response object to access status code, text, headers, URL, and elapsed time for debugging message delivery. It also includes logic to check specific status codes for success or failure. ```python import pymsteams webhook_url = "https://outlook.webhook.office.com/webhookb2/..." teams_message = pymsteams.connectorcard(webhook_url, http_timeout=30) teams_message.title("Test Message") teams_message.text("Testing response inspection") try: success = teams_message.send() # Access response details response = teams_message.last_http_response print(f"HTTP Status Code: {response.status_code}") print(f"Response Text: {response.text}") print(f"Response Headers: {response.headers}") print(f"Request URL: {response.url}") print(f"Response Time: {response.elapsed.total_seconds()}s") # Check specific status codes if response.status_code == 200: print("Message delivered successfully") elif 200 <= response.status_code < 300: print(f"Message accepted with status {response.status_code}") except pymsteams.TeamsWebhookException as e: response = teams_message.last_http_response print(f"Message failed with status {response.status_code}") print(f"Error message: {e}") print(f"Response body: {response.text}") ``` -------------------------------- ### Add Multiple Sections to Teams Message Source: https://github.com/rveachkc/pymsteams/blob/master/README.md Adds multiple distinct sections to a single Microsoft Teams connector card message. Each section is created independently and then added to the main message object before the entire card is sent. ```python Section1 = pymsteams.cardsection() Section1.text("My First Section") Section2 = pymsteams.cardsection() Section2.text("My Second Section") myTeamsMessage.addSection(Section1) myTeamsMessage.addSection(Section2) myTeamsMessage.send() ``` -------------------------------- ### Send Large Messages in Sections using pymsteams Source: https://context7.com/rveachkc/pymsteams/llms.txt This function splits a large message content into smaller chunks and sends them as separate sections in a single Microsoft Teams message. It handles content splitting and iterates through chunks to add them as sections. Error handling for sending the message is included. ```python import pymsteams def send_large_message(title, content, webhook): message = pymsteams.connectorcard(webhook) message.title(title) message.summary(f"{title} - Multiple sections") # Split content into chunks (assuming section_size_limit is defined elsewhere) # chunks = [content[i:i+section_size_limit] for i in range(0, len(content), section_size_limit)] chunks = [content[i:i+1000] for i in range(0, len(content), 1000)] # Example limit for idx, chunk in enumerate(chunks): section = pymsteams.cardsection() section.title(f"Section {idx+1} of {len(chunks)}") section.text(chunk) message.addSection(section) try: message.send() print(f"Sent {len(chunks)} sections successfully") except pymsteams.TeamsWebhookException as e: print(f"Error sending large message: {e}") # Example usage: # send_large_message("Application Logs", log_data, webhook_url) ``` -------------------------------- ### Disable Markdown Rendering in pymsteams Sections Source: https://context7.com/rveachkc/pymsteams/llms.txt This code demonstrates how to control markdown rendering on a per-section basis within a Microsoft Teams message using pymsteams. It shows how to explicitly enable markdown for one section to render rich text and links, and disable it for another section to display plain text, including special characters like asterisks and stars literally. ```python import pymsteams webhook_url = "https://outlook.webhook.office.com/webhookb2/" teams_message = pymsteams.connectorcard(webhook_url) teams_message.title("Code Deployment Summary") # Section 1: With markdown enabled (default) section_markdown = pymsteams.cardsection() section_markdown.title("Release Notes") section_markdown.enableMarkdown() # Explicitly enable (default state) section_markdown.text("\n**New Features:**\n- User authentication with OAuth2\n- *Real-time* notifications\n- `API rate limiting`\n\n[View Full Changelog](https://github.com/example/project/releases)\n") # Section 2: With markdown disabled for literal text section_plain = pymsteams.cardsection() section_plain.title("Raw Configuration") section_plain.disableMarkdown() # Disable markdown rendering section_plain.text("\n**config.json**\n{\n \"timeout\": 30,\n \"retry\": 3,\n \"endpoint\": \"https://api.example.com/*\"\n}\n*Note: Stars and asterisks display literally*\n") teams_message.addSection(section_markdown) teams_message.addSection(section_plain) try: teams_message.send() except pymsteams.TeamsWebhookException as e: print(f"Error: {e}") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.