Skip to content

Commit

Permalink
Allows to set custom properties on a teams client (#927)
Browse files Browse the repository at this point in the history
Co-authored-by: Niko Köser <[email protected]>
  • Loading branch information
firefart and nikoksr authored Jan 15, 2025
1 parent be564db commit 7af33de
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 1 deletion.
100 changes: 99 additions & 1 deletion service/msteams/mock_teams_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions service/msteams/ms_teams.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@ package msteams
import (
"context"
"fmt"
"net/http"

teams "github.com/atc0005/go-teams-notify/v2"
"github.com/atc0005/go-teams-notify/v2/adaptivecard"
)

type teamsClient interface {
// https://pkg.go.dev/github.com/atc0005/go-teams-notify/v2#TeamsClient.SendWithContext
SendWithContext(ctx context.Context, webhookURL string, message teams.TeamsMessage) error
// https://pkg.go.dev/github.com/atc0005/go-teams-notify/v2#TeamsClient.SkipWebhookURLValidationOnSend
SkipWebhookURLValidationOnSend(skip bool) *teams.TeamsClient
// https://pkg.go.dev/github.com/atc0005/go-teams-notify/v2#TeamsClient.SetHTTPClient
SetHTTPClient(httpClient *http.Client) *teams.TeamsClient
// https://pkg.go.dev/github.com/atc0005/go-teams-notify/v2#TeamsClient.SetUserAgent
SetUserAgent(userAgent string) *teams.TeamsClient
}

// Compile-time check to ensure that teams.Client implements the teamsClient interface.
Expand Down Expand Up @@ -59,6 +66,16 @@ func (m *MSTeams) AddReceivers(webHooks ...string) {
m.webHooks = append(m.webHooks, webHooks...)
}

// SetUseragent allows the user to set a custom user agent.
func (m *MSTeams) SetUseragent(userAgent string) {
m.client = m.client.SetUserAgent(userAgent)
}

// SetHTTPClient allows the user to set a custom http client.
func (m *MSTeams) SetHTTPClient(httpClient *http.Client) {
m.client = m.client.SetHTTPClient(httpClient)
}

// Send accepts a subject and a message body and sends them to all previously specified channels. Message body supports
// html as markup language.
// For more information about telegram api token:
Expand Down

0 comments on commit 7af33de

Please sign in to comment.