Files
mostlymatter/server/boards/services/webhook/webhook.go
Jesse Hallam bb02b35048 Expose public/ API as submodule (#23345)
* model -> public/model

* plugin -> public/plugin

* public/model/utils -> public/utils

* platform/shared/mlog -> public/shared/mlog

* platform/shared/i18n -> public/shared/i18n

* platform/shared/markdown -> public/shared/markdown

* platform/services/timezones -> public/shared/timezones

* channels/einterfaces -> einterfaces

* expose public/ submodule

* go mod tidy

* .github: cache-dependency-path, setup-go-work

* modules-tidy for public/ too

* remove old gomodtidy
2023-05-10 13:07:02 -03:00

50 строки
1.2 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package webhook
import (
"bytes"
"encoding/json"
"io"
"net/http"
"github.com/mattermost/mattermost-server/server/v8/boards/model"
"github.com/mattermost/mattermost-server/server/v8/boards/services/config"
"github.com/mattermost/mattermost-server/server/public/shared/mlog"
)
// NotifyUpdate calls webhooks.
func (wh *Client) NotifyUpdate(block *model.Block) {
if len(wh.config.WebhookUpdate) < 1 {
return
}
json, err := json.Marshal(block)
if err != nil {
wh.logger.Fatal("NotifyUpdate: json.Marshal", mlog.Err(err))
}
for _, url := range wh.config.WebhookUpdate {
resp, _ := http.Post(url, "application/json", bytes.NewBuffer(json)) //nolint:gosec
_, _ = io.ReadAll(resp.Body)
resp.Body.Close()
wh.logger.Debug("webhook.NotifyUpdate", mlog.String("url", url))
}
}
// Client is a webhook client.
type Client struct {
config *config.Configuration
logger mlog.LoggerIFace
}
// NewClient creates a new Client.
func NewClient(config *config.Configuration, logger mlog.LoggerIFace) *Client {
return &Client{
config: config,
logger: logger,
}
}