Skip to main content

Pluggable notification channels (Teams, …) for MPT Extension SDK projects.

Project description

mpt-extension-contrib-custom-notifications

Shared notification channels for SoftwareONE MPT extensions built on the Extension SDK. Extensions report to a channel (Microsoft Teams or AWS SES email) through one registry — ctx.notifications — instead of re-implementing a sender per extension.

Channels are pluggable: each is gated by an optional-dependency extra and self-registers through an entry point, so a base install pulls no channel dependencies and only the channels you install and configure are exposed.

It consolidates the per-extension notification code previously re-implemented in the AWS (swo/notifications/teams.py) and Adobe (adobe_vipm/notifications.py) extensions.

See AGENTS.md for the module documentation map.

Install

pip install "mpt-extension-contrib-custom-notifications[teams,ses]"

The base distribution has no channel dependencies. Each channel is an extra:

Extra Pulls in Channel key
teams microsoft-teams-cards, httpx teams
ses boto3, jinja2 aws_ses

Public API

mpt_extension_contrib.custom_notifications exposes the core; channel implementations live under mpt_extension_contrib.custom_notifications.channels.<name>.

Object Purpose
NotificationsContextMixin Adds self.notifications to an SDK context, built from settings.
NotificationRegistry Named lookup of configured channels (register, get).
build_registry(settings) Discover installed channels and register the configured ones.
Notification Marker Protocol every channel satisfies.
NotificationChannel Entry-point descriptor (name, build) advertised by a channel.
NotificationSettings Marker Protocol for the settings a channel factory reads.

Teams channel — mpt_extension_contrib.custom_notifications.channels.teams (extra teams):

Object Purpose
TeamsNotifications Send Adaptive Cards to a Teams channel via a Workflows webhook.
TeamsNotifier Protocol a custom Teams implementation must preserve.
TeamsSettings Protocol describing the settings the channel reads (teams_webhook_url, teams_notifications_enabled).
Button, FactsSection Value types for a card link button and a facts section.

SES channel — mpt_extension_contrib.custom_notifications.channels.ses (extra ses):

Object Purpose
SesNotifications Send HTML emails through AWS SES (send_email(...) / send_template(...) -> bool).
SesNotifier Protocol a custom SES implementation must preserve.
SesSettings Protocol for the settings the channel reads (region, sender, credentials, enable flag).
EmailNotificationTemplate Subject + Jinja2 HTML body (render(context); from_file(subject, body_path) to load the body from an .html file).

Usage

Make the extension settings satisfy each installed channel's settings protocol (inherit it so the contract is type-checked), then mix NotificationsContextMixin into the context — it reads the standard ext_settings, so no extra wiring:

from dataclasses import dataclass

from mpt_extension_sdk.settings.extension import BaseExtensionSettings

from mpt_extension_contrib.custom_notifications import NotificationsContextMixin
from mpt_extension_contrib.custom_notifications.channels.teams import TeamsSettings


@dataclass(frozen=True)
class ExtensionSettings(BaseExtensionSettings, TeamsSettings):
    # MSTEAMS_WEBHOOK_URL is read from the extension configuration.
    teams_webhook_url: str | None = None


class OrderContext(NotificationsContextMixin, SdkOrderContext): ...

Then resolve a channel and send. get(NotifierProtocol) returns the registered channel that satisfies the protocol, typed as that protocol:

from mpt_extension_contrib.custom_notifications.channels.teams import (
    Button,
    FactsSection,
    TeamsNotifier,
)

teams = ctx.notifications.get(TeamsNotifier)
teams.send_error(
    "Agreement sync failed",
    str(exc),
    button=Button(label="Open agreement", url=agreement_url),
    facts=FactsSection(title="Context", entries={"Agreement": agreement_id}),
)

A channel appears in the registry only when both its extra is installed and it is configured in settings. Asking for a channel that is not registered raises KeyError, so an extension that does not use Teams neither installs the extra nor configures the webhook.

Custom channels

A custom implementation only has to satisfy the channel Protocol; register it under any key (use override=True to replace a built-in):

ctx.notifications.register("teams", MyTeamsNotifications(...), override=True)

To make a custom channel discoverable across extensions, ship it as its own distribution that advertises a mpt_extension_contrib.custom_notifications.channels entry point exposing a NotificationChannel.

Documentation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file mpt_extension_contrib_custom_notifications-1.1.0.tar.gz.

File metadata

  • Download URL: mpt_extension_contrib_custom_notifications-1.1.0.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mpt_extension_contrib_custom_notifications-1.1.0.tar.gz
Algorithm Hash digest
SHA256 b3a0808d7f8c8a8f4b2224698b7467e9b7d99eea1e8dc09966c420a6e5cbf18b
MD5 08fe0765586d674f217d42031ae8a7e2
BLAKE2b-256 a9b9d2eafe71b021c254f8f0c505a1b40994215f94eb08153618bed1af83bf91

See more details on using hashes here.

File details

Details for the file mpt_extension_contrib_custom_notifications-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: mpt_extension_contrib_custom_notifications-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mpt_extension_contrib_custom_notifications-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3f4e1a1596c6189031a1c80cad13a662fb274a80674d32492a3be11d5deddb7e
MD5 904da90f639f8356d743cd529c2c7e0e
BLAKE2b-256 866db0d10b37d0f83d671353e39df41ca83ebf1e1600627b9247d1f7f19576df

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page