Skip to content

Update Teams service to support new webhook URL format with required extraId #460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 180 commits into
base: main
Choose a base branch
from

Conversation

serverleader
Copy link

Description:
This PR updates the Teams service to support the new webhook URL format and removes support for legacy formats.

Key changes:

  • Added support for the extraId component which is now required in the latest Teams webhook URL format
  • Updated the URL parsing to extract all parts of the webhook, including the new extraId component
  • Modified the Config struct to include the extraId field as a required parameter
  • Removed legacy host fallback (outlook.office.com) and now require an organization-specific domain
  • Updated tests to use the new webhook URL format with the required extraId component
  • Improved error handling to provide clear error messages when required components are missing
  • Updated documentation to reflect the new URL format and requirements

The new webhook URL format has the form:
https://<organization>.webhook.office.com/webhookb2/<group>@<tenant>/IncomingWebhook/<altId>/<groupOwner>/<extraId>

Which gets converted to:
teams://<group>@<tenant>/<altId>/<groupOwner>/<extraId>?host=<organization>.webhook.office.com

All components including the extraId and organization-specific domain are now required.

renovate bot and others added 30 commits February 24, 2025 15:21
…om-mattn-go-colorable-0.x

fix(deps): update module github.com/mattn/go-colorable to v0.1.14
…-httpmock-1.x

fix(deps): update module github.com/jarcoal/httpmock to v1.3.1
…org-x-oauth2-0.x

fix(deps): update module golang.org/x/oauth2 to v0.26.0
…ser-goreleaser-action-6.x

chore(deps): update goreleaser/goreleaser-action action to v6
…-codecov-action-5.x

chore(deps): update codecov/codecov-action action to v5
…ocker-login-2.x

chore(deps): update azure/docker-login action to v2
chore(deps): update alpine docker tag to v3.21.3
…om-onsi-gomega-1.x

fix(deps): update module github.com/onsi/gomega to v1.36.2
…com-spf13-viper-1.x

fix(deps): update module github.com/spf13/viper to v1.19.0
…om-fatih-color-1.x

fix(deps): update module github.com/fatih/color to v1.18.0
…om-onsi-ginkgo-v2-2.x

fix(deps): update module github.com/onsi/ginkgo/v2 to v2.22.2
…org-x-net-0.x

fix(deps): update module golang.org/x/net to v0.35.0
…om-spf13-cobra-1.x

fix(deps): update module github.com/spf13/cobra to v1.9.1
- Changed repository references to nicholas-fedor/shoutrrr
- Linted all files
- Added additional test cases to increase test coverage
- Updated deprecated code
- Updated GitHub workflows
- Added GolangCI lint configuration
- Added Codacy and CircleCI configurations
- Removed dot imports in favor of explicit imports
nicholas-fedor and others added 7 commits March 18, 2025 20:15
… tests (containrrr#53)

* feat(mattermost): add DisableTLS param and preserve port in host

Introduce `DisableTLS` query/param prop to toggle between HTTPS and HTTP in the Mattermost service, addressing self-hosted HTTP use cases (e.g., Containrrr/Watchtower issue #2089). Preserve port in `Host` by adopting Gotify-style handling, fixing port stripping. Enhance security with `MinVersion: tls.VersionTLS12`, refactor `setURL` for complexity (from 11 to 4, parsePath to 8, limit 8), and add comprehensive tests.

- Add `DisableTLS` to `Config` (default "No") and update `buildURL` to switch schemes.
- Change `setURL` to use `url.Host` instead of `Hostname()` for port retention.
- Introduce `httpClient` with `GetHTTPClient()` in `Service` for mocking.
- Set `MinVersion` in `TLSClientConfig` when `DisableTLS` is false.
- Extract path parsing into `parsePath`, reducing complexity and fixing empty token validation.
- Add tests for `DisableTLS` transport (`TLSClientConfig: nil`) and `Send` error handling (non-200 status).
- Update dependencies with minor Go version increment.

Resolves port and scheme issues (e.g., `mattermost://user@host:port/token?disabletls=yes`), ensuring compliance with security and complexity standards at 95.9% coverage.
…ontainrrr#52)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
…ontainrrr#54)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
…nrrr#56)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
- Updated documentation to reflect the new Teams webhook URL format, which now requires the organization domain.
- Removed support for legacy webhook formats.
- Enhanced the configuration structure to include an additional `ExtraID` component.
- Updated related functions and tests to accommodate the new URL structure and ensure proper validation of the webhook parts.
- Updated the documentation to emphasize the new Teams webhook URL format, including the organization domain.
- Enhanced the explanation of the URL structure and its components for better clarity.
- Changed the formatting of notes and examples for improved readability.
renovate bot and others added 5 commits March 20, 2025 15:13
…nrrr#57)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
…nrrr#58)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
…r#59)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
nicholas-fedor and others added 5 commits March 25, 2025 00:20
…r#60)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
…rrr#63)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
…ontainrrr#61)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
@JPRauwolf JPRauwolf mentioned this pull request Mar 25, 2025
Carlos Savcic and others added 9 commits March 25, 2025 18:25
# Conflicts:
#	pkg/services/teams/teams.go
#	pkg/services/teams/teams_config.go
#	pkg/services/teams/teams_test.go
#	pkg/services/teams/teams_token.go
This commit updates the Teams service in this Shoutrrr fork to support the new Microsoft Teams webhook URL format, removing legacy support, and refactors the package to align with Go best practices. It builds on serverleader's initial PR (March 25, 2025) to standardize the implementation, adding robust validation, improved error handling, and  updated documentation in `teams.md`. Tests in `router_suite_test.go` and `services_test.go` are updated to match the new format.

Key changes:
- Added support for the required `extraId` in webhook URLs.
- Updated URL parsing to extract all components, including `extraId`.
- Modified `Config` to include `extraId` as a required field.
- Removed legacy host fallback (`outlook.office.com`), enforcing an organization-specific domain (e.g., `<org>.webhook.office.com`).
- Enhanced parameter validation with specific error messages.
- Improved error handling for missing components.
- Updated tests to use the new format with `extraId` and `host` param.
- Reorganized package into `teams_config.go`, `teams_service.go`, `teams_validation.go`,  and `teams_message.go` for better modularity and clarity.
- Renamed functions (`BuildWebhookURL`, `WebhookParts`) to follow Go naming conventions.
- Updated `teams.md` to document the new format, optional `color` and `title` parameters, and modernized the Microsoft link.

The new webhook format is:
`https://<org>.webhook.office.com/webhookb2/<group>@<tenant>/IncomingWebhook/<altId>/<groupOwner>/<extraId>`
Converted to:
`teams://<group>@<tenant>/<altId>/<groupOwner>/<extraId>?host=<org>.webhook.office.com`
feat(teams): update Teams service for new webhook format and refactor
…r#67)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Address Codacy-reported complexity issues in the teams package by refactoring two methods exceeding the limit of 8:

- `setURL` (complexity 9): Split into `setURL`, `parseURLParts`, and  `setQueryParams`, reducing complexity to 3, 5, and 4, respectively.
  Extracted URL parsing and query handling into separate functions for better modularity and maintainability.

- `verifyWebhookParts` (complexity 10): Refactored to use a loop over a spec slice, reducing complexity to 3. Consolidated repeated length  checks into a single control structure.

Added comments to new functions.
All existing tests pass with no functional changes.
refactor: reduce cyclomatic complexity in teams package
Lint jobs failing due to updated config.
Temporarily disabling to get latest Teams update pushed through, then will re-enable and update project to meet updated linting criteria.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants