pymsteams-workflow


Namepymsteams-workflow JSON
Version 1.0.3 PyPI version JSON
download
home_pagehttps://github.com/th3happybit/pymsteams/
SummaryFormat messages and post to Microsoft Teams through Microsoft Power Automate WorkFlow.
upload_time2024-10-23 12:10:24
maintainerNone
docs_urlNone
authorOussama Messabih
requires_python>=3.6
licenseApache
keywords microsoft teams power automate workflow
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pymsteams

Python Wrapper Library to send requests to Microsoft Teams via Microsoft Power Automate workflows.

I have created this library because the Microsoft Teams Webhook is being retired. [Retirement of Office 365 connectors within Microsoft Teams](https://devblogs.microsoft.com/microsoft365dev/retirement-of-office-365-connectors-within-microsoft-teams/)

## Overview

This library allows sending messages with rich formatting to Microsoft Teams by utilizing Power Automate workflows. Messages can include simple text, titles, link buttons, and more. You can also use asynchronous operations to send messages in parallel.

## Installation

Install with pip:

```bash
pip install pymsteams-workflow
```

## Usage

### Creating ConnectorCard Messages

Below is a basic example demonstrating how to send a message using a Power Automate workflow URL:

```python
from pymsteams import connectorcard

# You must create the connectorcard object with the Power Automate URL
myTeamsMessage = connectorcard("<Power Automate URL>")

# Add text to the message
myTeamsMessage.text("This is my text")

# Send the message
myTeamsMessage.send()
```

### Asynchronous ConnectorCard Messages

You can send messages asynchronously using `async_connectorcard`. This is useful when sending multiple messages or performing other asynchronous tasks.

```python
import asyncio
from pymsteams import async_connectorcard

loop = asyncio.get_event_loop()

# The async_connectorcard object is used for asynchronous operations
myTeamsMessage = async_connectorcard("<Power Automate URL>")

# Add text to the message
myTeamsMessage.text("This is my async message")

# Send the message asynchronously
loop.run_until_complete(myTeamsMessage.send())
```

### Optional Formatting Methods

#### Add a Title

You can add a title to the message, which will be displayed prominently:

```python
myTeamsMessage.title("This is my message title")
```

#### Add a Link Button

Add a link button to your message to redirect users to a specific URL:

```python
myTeamsMessage.addLinkButton("This is the button Text", "https://example.com")
```

### Example: Sending a Message with a Title and Link Button

Here's a complete example of sending a message with both a title and a link button:

```python
from your_module import connectorcard  # Replace 'your_module' with your module name

webhook_url = "<Power Automate URL>"

# Create the connector card
card = connectorcard(webhook_url)
card.title("Important Notification")
card.text("Please review the latest updates.")
card.addLinkButton("Review Updates", "https://example.com/updates")

# Send the message
card.send()
```

### Exception Handling

If the call to the Power Automate service fails, a `TeamsWebhookException` will be thrown. Ensure you handle this exception in your code:

```python
try:
    card.send()
except TeamsWebhookException as e:
    print(f"Failed to send message: {e}")
```

## Testing

In order to test in your environment with `pytest`, set the environment variable `MS_TEAMS_WORKFLOW` to the Power Automate workflow URL you would like to use.

Then, from the root of the repo, install the requirements and run pytest.

```bash
pip install -r dev-requirements.txt
MS_TEAMS_WORKFLOW=<PowerAutomateURL>
export MS_TEAMS_WORKFLOW
pytest --cov=./your_module --cov-report=term-missing --cov-branch  # Replace 'your_module' with your module name
```

## Docs

- [Send a message in Teams using Power Automate](https://learn.microsoft.com/en-us/power-automate/teams/send-a-message-in-teams)
- [apprise Notify_workflows](https://github.com/caronc/apprise/wiki/Notify_workflows)
- [Retirement of Office 365 connectors within Microsoft Teams](https://devblogs.microsoft.com/microsoft365dev/retirement-of-office-365-connectors-within-microsoft-teams/)


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/th3happybit/pymsteams/",
    "name": "pymsteams-workflow",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "Microsoft, Teams, Power, Automate, Workflow",
    "author": "Oussama Messabih",
    "author_email": "oussamamessabih02@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/f6/e6/8a642d65ad3153fabd502d981b252df635c4d1c1a60668be377b9f70478a/pymsteams_workflow-1.0.3.tar.gz",
    "platform": null,
    "description": "# pymsteams\n\nPython Wrapper Library to send requests to Microsoft Teams via Microsoft Power Automate workflows.\n\nI have created this library because the Microsoft Teams Webhook is being retired. [Retirement of Office 365 connectors within Microsoft Teams](https://devblogs.microsoft.com/microsoft365dev/retirement-of-office-365-connectors-within-microsoft-teams/)\n\n## Overview\n\nThis library allows sending messages with rich formatting to Microsoft Teams by utilizing Power Automate workflows. Messages can include simple text, titles, link buttons, and more. You can also use asynchronous operations to send messages in parallel.\n\n## Installation\n\nInstall with pip:\n\n```bash\npip install pymsteams-workflow\n```\n\n## Usage\n\n### Creating ConnectorCard Messages\n\nBelow is a basic example demonstrating how to send a message using a Power Automate workflow URL:\n\n```python\nfrom pymsteams import connectorcard\n\n# You must create the connectorcard object with the Power Automate URL\nmyTeamsMessage = connectorcard(\"<Power Automate URL>\")\n\n# Add text to the message\nmyTeamsMessage.text(\"This is my text\")\n\n# Send the message\nmyTeamsMessage.send()\n```\n\n### Asynchronous ConnectorCard Messages\n\nYou can send messages asynchronously using `async_connectorcard`. This is useful when sending multiple messages or performing other asynchronous tasks.\n\n```python\nimport asyncio\nfrom pymsteams import async_connectorcard\n\nloop = asyncio.get_event_loop()\n\n# The async_connectorcard object is used for asynchronous operations\nmyTeamsMessage = async_connectorcard(\"<Power Automate URL>\")\n\n# Add text to the message\nmyTeamsMessage.text(\"This is my async message\")\n\n# Send the message asynchronously\nloop.run_until_complete(myTeamsMessage.send())\n```\n\n### Optional Formatting Methods\n\n#### Add a Title\n\nYou can add a title to the message, which will be displayed prominently:\n\n```python\nmyTeamsMessage.title(\"This is my message title\")\n```\n\n#### Add a Link Button\n\nAdd a link button to your message to redirect users to a specific URL:\n\n```python\nmyTeamsMessage.addLinkButton(\"This is the button Text\", \"https://example.com\")\n```\n\n### Example: Sending a Message with a Title and Link Button\n\nHere's a complete example of sending a message with both a title and a link button:\n\n```python\nfrom your_module import connectorcard  # Replace 'your_module' with your module name\n\nwebhook_url = \"<Power Automate URL>\"\n\n# Create the connector card\ncard = connectorcard(webhook_url)\ncard.title(\"Important Notification\")\ncard.text(\"Please review the latest updates.\")\ncard.addLinkButton(\"Review Updates\", \"https://example.com/updates\")\n\n# Send the message\ncard.send()\n```\n\n### Exception Handling\n\nIf the call to the Power Automate service fails, a `TeamsWebhookException` will be thrown. Ensure you handle this exception in your code:\n\n```python\ntry:\n    card.send()\nexcept TeamsWebhookException as e:\n    print(f\"Failed to send message: {e}\")\n```\n\n## Testing\n\nIn order to test in your environment with `pytest`, set the environment variable `MS_TEAMS_WORKFLOW` to the Power Automate workflow URL you would like to use.\n\nThen, from the root of the repo, install the requirements and run pytest.\n\n```bash\npip install -r dev-requirements.txt\nMS_TEAMS_WORKFLOW=<PowerAutomateURL>\nexport MS_TEAMS_WORKFLOW\npytest --cov=./your_module --cov-report=term-missing --cov-branch  # Replace 'your_module' with your module name\n```\n\n## Docs\n\n- [Send a message in Teams using Power Automate](https://learn.microsoft.com/en-us/power-automate/teams/send-a-message-in-teams)\n- [apprise Notify_workflows](https://github.com/caronc/apprise/wiki/Notify_workflows)\n- [Retirement of Office 365 connectors within Microsoft Teams](https://devblogs.microsoft.com/microsoft365dev/retirement-of-office-365-connectors-within-microsoft-teams/)\n\n",
    "bugtrack_url": null,
    "license": "Apache",
    "summary": "Format messages and post to Microsoft Teams through Microsoft Power Automate WorkFlow.",
    "version": "1.0.3",
    "project_urls": {
        "Homepage": "https://github.com/th3happybit/pymsteams/"
    },
    "split_keywords": [
        "microsoft",
        " teams",
        " power",
        " automate",
        " workflow"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f6e68a642d65ad3153fabd502d981b252df635c4d1c1a60668be377b9f70478a",
                "md5": "f03d3ff03a194434bc174a8679bb8191",
                "sha256": "bdd2df88528b240e2f852f540114bd745f087221642ada9577dfbcac173ca9b0"
            },
            "downloads": -1,
            "filename": "pymsteams_workflow-1.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "f03d3ff03a194434bc174a8679bb8191",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 9442,
            "upload_time": "2024-10-23T12:10:24",
            "upload_time_iso_8601": "2024-10-23T12:10:24.938974Z",
            "url": "https://files.pythonhosted.org/packages/f6/e6/8a642d65ad3153fabd502d981b252df635c4d1c1a60668be377b9f70478a/pymsteams_workflow-1.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-23 12:10:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "th3happybit",
    "github_project": "pymsteams",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "circle": true,
    "lcname": "pymsteams-workflow"
}
        
Elapsed time: 0.32466s