Use upstream slack-go/slack again (#1018)
parent
e9edbfc051
commit
250b3bb579
@ -1,14 +0,0 @@
|
||||
package slack
|
||||
|
||||
// UnknownBlock represents a block type that is not yet known. This block type exists to prevent Slack from introducing
|
||||
// new and unknown block types that break this library.
|
||||
type UnknownBlock struct {
|
||||
Type MessageBlockType `json:"type"`
|
||||
BlockID string `json:"block_id,omitempty"`
|
||||
Elements BlockElements `json:"elements"`
|
||||
}
|
||||
|
||||
// BlockType returns the type of the block
|
||||
func (b UnknownBlock) BlockType() MessageBlockType {
|
||||
return b.Type
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/gorilla/websocket v1.2.0 h1:VJtLvh6VQym50czpZzx07z/kw9EgAxI3x1ZB8taTMQQ=
|
||||
github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
||||
github.com/nlopes/slack v0.1.0/go.mod h1:jVI4BBK3lSktibKahxBF74txcK2vyvkza1z/+rRnVAM=
|
||||
github.com/nlopes/slack v0.5.0 h1:NbIae8Kd0NpqaEI3iUrsuS0KbcEDhzhc939jLW5fNm0=
|
||||
github.com/nlopes/slack v0.5.0/go.mod h1:jVI4BBK3lSktibKahxBF74txcK2vyvkza1z/+rRnVAM=
|
||||
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/testify v1.2.0/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/victorcoder/slack-test v0.0.0-20190131110821-6f9a569c10af h1:JFxr+No3ZWgCtxnnTWCybnB/z0Iy3qLmdj3u2NV5o48=
|
||||
github.com/victorcoder/slack-test v0.0.0-20190131110821-6f9a569c10af/go.mod h1:dStM4ShMus8J3hiq66ExbbzGLkwyZ+RQJePwFhWCCvQ=
|
||||
github.com/victorcoder/slack-test v0.0.0-20190131113129-a43b3bb77f43 h1:wtFekkaAAQibpy3iE4Hhx2Gi9pZAbITOSfVP7GXk5eM=
|
||||
github.com/victorcoder/slack-test v0.0.0-20190131113129-a43b3bb77f43/go.mod h1:dStM4ShMus8J3hiq66ExbbzGLkwyZ+RQJePwFhWCCvQ=
|
||||
golang.org/x/net v0.0.0-20180108090419-434ec0c7fe37 h1:BkNcmLtAVeWe9h5k0jt24CQgaG5vb4x/doFbAiEC/Ho=
|
||||
golang.org/x/net v0.0.0-20180108090419-434ec0c7fe37/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
0
vendor/github.com/nlopes/slack/LICENSE → vendor/github.com/slack-go/slack/LICENSE
generated
vendored
0
vendor/github.com/nlopes/slack/LICENSE → vendor/github.com/slack-go/slack/LICENSE
generated
vendored
@ -0,0 +1,36 @@
|
||||
.PHONY: help deps fmt lint test test-race test-integration
|
||||
|
||||
help:
|
||||
@echo ""
|
||||
@echo "Welcome to slack-go/slack make."
|
||||
@echo "The following commands are available:"
|
||||
@echo ""
|
||||
@echo " make deps : Fetch all dependencies"
|
||||
@echo " make fmt : Run go fmt to fix any formatting issues"
|
||||
@echo " make lint : Use go vet to check for linting issues"
|
||||
@echo " make test : Run all short tests"
|
||||
@echo " make test-race : Run all tests with race condition checking"
|
||||
@echo " make test-integration : Run all tests without limiting to short"
|
||||
@echo ""
|
||||
@echo " make pr-prep : Run this before making a PR to run fmt, lint and tests"
|
||||
@echo ""
|
||||
|
||||
deps:
|
||||
@go mod tidy
|
||||
|
||||
fmt:
|
||||
@go fmt .
|
||||
|
||||
lint:
|
||||
@go vet .
|
||||
|
||||
test:
|
||||
@go test -count=1 -timeout 300s -short .
|
||||
|
||||
test-race:
|
||||
@go test -count=1 -timeout 300s -short -race .
|
||||
|
||||
test-integration:
|
||||
@go test -count=1 -timeout 600s .
|
||||
|
||||
pr-prep: fmt lint test-race test-integration
|
23
vendor/github.com/nlopes/slack/README.md → vendor/github.com/slack-go/slack/README.md
generated
vendored
23
vendor/github.com/nlopes/slack/README.md → vendor/github.com/slack-go/slack/README.md
generated
vendored
0
vendor/github.com/nlopes/slack/TODO.txt → vendor/github.com/slack-go/slack/TODO.txt
generated
vendored
0
vendor/github.com/nlopes/slack/TODO.txt → vendor/github.com/slack-go/slack/TODO.txt
generated
vendored
0
vendor/github.com/nlopes/slack/admin.go → vendor/github.com/slack-go/slack/admin.go
generated
vendored
0
vendor/github.com/nlopes/slack/admin.go → vendor/github.com/slack-go/slack/admin.go
generated
vendored
0
vendor/github.com/nlopes/slack/auth.go → vendor/github.com/slack-go/slack/auth.go
generated
vendored
0
vendor/github.com/nlopes/slack/auth.go → vendor/github.com/slack-go/slack/auth.go
generated
vendored
1
vendor/github.com/nlopes/slack/block.go → vendor/github.com/slack-go/slack/block.go
generated
vendored
1
vendor/github.com/nlopes/slack/block.go → vendor/github.com/slack-go/slack/block.go
generated
vendored
@ -0,0 +1,30 @@
|
||||
package slack
|
||||
|
||||
// InputBlock defines data that is used to collect information from users -
|
||||
// it can hold a plain-text input element, a select menu element,
|
||||
// a multi-select menu element, or a datepicker.
|
||||
//
|
||||
// More Information: https://api.slack.com/reference/messaging/blocks#input
|
||||
type InputBlock struct {
|
||||
Type MessageBlockType `json:"type"`
|
||||
BlockID string `json:"block_id,omitempty"`
|
||||
Label *TextBlockObject `json:"label"`
|
||||
Element BlockElement `json:"element"`
|
||||
Hint *TextBlockObject `json:"hint,omitempty"`
|
||||
Optional bool `json:"optional,omitempty"`
|
||||
}
|
||||
|
||||
// BlockType returns the type of the block
|
||||
func (s InputBlock) BlockType() MessageBlockType {
|
||||
return s.Type
|
||||
}
|
||||
|
||||
// NewInputBlock returns a new instance of an Input Block
|
||||
func NewInputBlock(blockID string, label *TextBlockObject, element BlockElement) *InputBlock {
|
||||
return &InputBlock{
|
||||
Type: MBTInput,
|
||||
BlockID: blockID,
|
||||
Label: label,
|
||||
Element: element,
|
||||
}
|
||||
}
|
0
vendor/github.com/nlopes/slack/bots.go → vendor/github.com/slack-go/slack/bots.go
generated
vendored
0
vendor/github.com/nlopes/slack/bots.go → vendor/github.com/slack-go/slack/bots.go
generated
vendored
6
vendor/github.com/nlopes/slack/chat.go → vendor/github.com/slack-go/slack/chat.go
generated
vendored
6
vendor/github.com/nlopes/slack/chat.go → vendor/github.com/slack-go/slack/chat.go
generated
vendored
0
vendor/github.com/nlopes/slack/dnd.go → vendor/github.com/slack-go/slack/dnd.go
generated
vendored
0
vendor/github.com/nlopes/slack/dnd.go → vendor/github.com/slack-go/slack/dnd.go
generated
vendored
0
vendor/github.com/nlopes/slack/emoji.go → vendor/github.com/slack-go/slack/emoji.go
generated
vendored
0
vendor/github.com/nlopes/slack/emoji.go → vendor/github.com/slack-go/slack/emoji.go
generated
vendored
@ -1,6 +1,6 @@
|
||||
package slack
|
||||
|
||||
import "github.com/nlopes/slack/internal/errorsx"
|
||||
import "github.com/slack-go/slack/internal/errorsx"
|
||||
|
||||
// Errors returned by various methods.
|
||||
const (
|
0
vendor/github.com/nlopes/slack/files.go → vendor/github.com/slack-go/slack/files.go
generated
vendored
0
vendor/github.com/nlopes/slack/files.go → vendor/github.com/slack-go/slack/files.go
generated
vendored
5
vendor/github.com/nlopes/slack/go.mod → vendor/github.com/slack-go/slack/go.mod
generated
vendored
5
vendor/github.com/nlopes/slack/go.mod → vendor/github.com/slack-go/slack/go.mod
generated
vendored
@ -1,7 +1,10 @@
|
||||
module github.com/matterbridge/slack
|
||||
module github.com/slack-go/slack
|
||||
|
||||
go 1.13
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/go-test/deep v1.0.4
|
||||
github.com/gorilla/websocket v1.2.0
|
||||
github.com/pkg/errors v0.8.0
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
@ -0,0 +1,12 @@
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/go-test/deep v1.0.4 h1:u2CU3YKy9I2pmu9pX0eq50wCgjfGIt539SqR7FbHiho=
|
||||
github.com/go-test/deep v1.0.4/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
|
||||
github.com/gorilla/websocket v1.2.0 h1:VJtLvh6VQym50czpZzx07z/kw9EgAxI3x1ZB8taTMQQ=
|
||||
github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
||||
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
0
vendor/github.com/nlopes/slack/info.go → vendor/github.com/slack-go/slack/info.go
generated
vendored
0
vendor/github.com/nlopes/slack/info.go → vendor/github.com/slack-go/slack/info.go
generated
vendored
0
vendor/github.com/nlopes/slack/item.go → vendor/github.com/slack-go/slack/item.go
generated
vendored
0
vendor/github.com/nlopes/slack/item.go → vendor/github.com/slack-go/slack/item.go
generated
vendored
0
vendor/github.com/nlopes/slack/misc.go → vendor/github.com/slack-go/slack/misc.go
generated
vendored
0
vendor/github.com/nlopes/slack/misc.go → vendor/github.com/slack-go/slack/misc.go
generated
vendored
0
vendor/github.com/nlopes/slack/oauth.go → vendor/github.com/slack-go/slack/oauth.go
generated
vendored
0
vendor/github.com/nlopes/slack/oauth.go → vendor/github.com/slack-go/slack/oauth.go
generated
vendored
0
vendor/github.com/nlopes/slack/pins.go → vendor/github.com/slack-go/slack/pins.go
generated
vendored
0
vendor/github.com/nlopes/slack/pins.go → vendor/github.com/slack-go/slack/pins.go
generated
vendored
0
vendor/github.com/nlopes/slack/rtm.go → vendor/github.com/slack-go/slack/rtm.go
generated
vendored
0
vendor/github.com/nlopes/slack/rtm.go → vendor/github.com/slack-go/slack/rtm.go
generated
vendored
2
vendor/github.com/nlopes/slack/slack.go → vendor/github.com/slack-go/slack/slack.go
generated
vendored
2
vendor/github.com/nlopes/slack/slack.go → vendor/github.com/slack-go/slack/slack.go
generated
vendored
0
vendor/github.com/nlopes/slack/slash.go → vendor/github.com/slack-go/slack/slash.go
generated
vendored
0
vendor/github.com/nlopes/slack/slash.go → vendor/github.com/slack-go/slack/slash.go
generated
vendored
0
vendor/github.com/nlopes/slack/stars.go → vendor/github.com/slack-go/slack/stars.go
generated
vendored
0
vendor/github.com/nlopes/slack/stars.go → vendor/github.com/slack-go/slack/stars.go
generated
vendored
0
vendor/github.com/nlopes/slack/team.go → vendor/github.com/slack-go/slack/team.go
generated
vendored
0
vendor/github.com/nlopes/slack/team.go → vendor/github.com/slack-go/slack/team.go
generated
vendored
4
vendor/github.com/nlopes/slack/users.go → vendor/github.com/slack-go/slack/users.go
generated
vendored
4
vendor/github.com/nlopes/slack/users.go → vendor/github.com/slack-go/slack/users.go
generated
vendored
@ -0,0 +1,221 @@
|
||||
package slack
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
const (
|
||||
VTModal ViewType = "modal"
|
||||
VTHomeTab ViewType = "home"
|
||||
)
|
||||
|
||||
type ViewType string
|
||||
|
||||
type View struct {
|
||||
SlackResponse
|
||||
ID string `json:"id"`
|
||||
TeamID string `json:"team_id"`
|
||||
Type ViewType `json:"type"`
|
||||
Title *TextBlockObject `json:"title"`
|
||||
Close *TextBlockObject `json:"close"`
|
||||
Submit *TextBlockObject `json:"submit"`
|
||||
Blocks Blocks `json:"blocks"`
|
||||
PrivateMetadata string `json:"private_metadata"`
|
||||
CallbackID string `json:"callback_id"`
|
||||
State interface{} `json:"state"`
|
||||
Hash string `json:"hash"`
|
||||
ClearOnClose bool `json:"clear_on_close"`
|
||||
NotifyOnClose bool `json:"notify_on_close"`
|
||||
RootViewID string `json:"root_view_id"`
|
||||
PreviousViewID string `json:"previous_view_id"`
|
||||
AppID string `json:"app_id"`
|
||||
ExternalID string `json:"external_id"`
|
||||
BotID string `json:"bot_id"`
|
||||
}
|
||||
|
||||
type ModalViewRequest struct {
|
||||
Type ViewType `json:"type"`
|
||||
Title *TextBlockObject `json:"title"`
|
||||
Blocks Blocks `json:"blocks"`
|
||||
Close *TextBlockObject `json:"close"`
|
||||
Submit *TextBlockObject `json:"submit"`
|
||||
PrivateMetadata string `json:"private_metadata"`
|
||||
CallbackID string `json:"callback_id"`
|
||||
ClearOnClose bool `json:"clear_on_close"`
|
||||
NotifyOnClose bool `json:"notify_on_close"`
|
||||
ExternalID string `json:"external_id"`
|
||||
}
|
||||
|
||||
func (v *ModalViewRequest) ViewType() ViewType {
|
||||
return v.Type
|
||||
}
|
||||
|
||||
type HomeTabViewRequest struct {
|
||||
Type ViewType `json:"type"`
|
||||
Blocks Blocks `json:"blocks"`
|
||||
PrivateMetadata string `json:"private_metadata"`
|
||||
CallbackID string `json:"callback_id"`
|
||||
ExternalID string `json:"external_id"`
|
||||
}
|
||||
|
||||
func (v *HomeTabViewRequest) ViewType() ViewType {
|
||||
return v.Type
|
||||
}
|
||||
|
||||
type openViewRequest struct {
|
||||
TriggerID string `json:"trigger_id"`
|
||||
View ModalViewRequest `json:"view"`
|
||||
}
|
||||
|
||||
type publishViewRequest struct {
|
||||
UserID string `json:"user_id"`
|
||||
View HomeTabViewRequest `json:"view"`
|
||||
Hash string `json:"hash"`
|
||||
}
|
||||
|
||||
type pushViewRequest struct {
|
||||
TriggerID string `json:"trigger_id"`
|
||||
View ModalViewRequest `json:"view"`
|
||||
}
|
||||
|
||||
type updateViewRequest struct {
|
||||
View ModalViewRequest `json:"view"`
|
||||
ExternalID string `json:"external_id"`
|
||||
Hash string `json:"hash"`
|
||||
ViewID string `json:"view_id"`
|
||||
}
|
||||
|
||||
type ViewResponse struct {
|
||||
SlackResponse
|
||||
View `json:"view"`
|
||||
}
|
||||
|
||||
// OpenView opens a view for a user.
|
||||
func (api *Client) OpenView(triggerID string, view ModalViewRequest) (*ViewResponse, error) {
|
||||
return api.OpenViewContext(context.Background(), triggerID, view)
|
||||
}
|
||||
|
||||
// OpenViewContext opens a view for a user with a custom context.
|
||||
func (api *Client) OpenViewContext(
|
||||
ctx context.Context,
|
||||
triggerID string,
|
||||
view ModalViewRequest,
|
||||
) (*ViewResponse, error) {
|
||||
if triggerID == "" {
|
||||
return nil, ErrParametersMissing
|
||||
}
|
||||
req := openViewRequest{
|
||||
TriggerID: triggerID,
|
||||
View: view,
|
||||
}
|
||||
encoded, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
endpoint := api.endpoint + "views.open"
|
||||
resp := &ViewResponse{}
|
||||
err = postJSON(ctx, api.httpclient, endpoint, api.token, encoded, resp, api)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, resp.Err()
|
||||
}
|
||||
|
||||
// PublishView publishes a static view for a user.
|
||||
func (api *Client) PublishView(userID string, view HomeTabViewRequest, hash string) (*ViewResponse, error) {
|
||||
return api.PublishViewContext(context.Background(), userID, view, hash)
|
||||
}
|
||||
|
||||
// PublishViewContext publishes a static view for a user with a custom context.
|
||||
func (api *Client) PublishViewContext(
|
||||
ctx context.Context,
|
||||
userID string,
|
||||
view HomeTabViewRequest,
|
||||
hash string,
|
||||
) (*ViewResponse, error) {
|
||||
if userID == "" {
|
||||
return nil, ErrParametersMissing
|
||||
}
|
||||
req := publishViewRequest{
|
||||
UserID: userID,
|
||||
View: view,
|
||||
Hash: hash,
|
||||
}
|
||||
encoded, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
endpoint := api.endpoint + "views.publish"
|
||||
resp := &ViewResponse{}
|
||||
err = postJSON(ctx, api.httpclient, endpoint, api.token, encoded, resp, api)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, resp.Err()
|
||||
}
|
||||
|
||||
// PushView pushes a view onto the stack of a root view.
|
||||
func (api *Client) PushView(triggerID string, view ModalViewRequest) (*ViewResponse, error) {
|
||||
return api.PushViewContext(context.Background(), triggerID, view)
|
||||
}
|
||||
|
||||
// PublishViewContext pushes a view onto the stack of a root view with a custom context.
|
||||
func (api *Client) PushViewContext(
|
||||
ctx context.Context,
|
||||
triggerID string,
|
||||
view ModalViewRequest,
|
||||
) (*ViewResponse, error) {
|
||||
if triggerID == "" {
|
||||
return nil, ErrParametersMissing
|
||||
}
|
||||
req := pushViewRequest{
|
||||
TriggerID: triggerID,
|
||||
View: view,
|
||||
}
|
||||
encoded, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
endpoint := api.endpoint + "views.push"
|
||||
resp := &ViewResponse{}
|
||||
err = postJSON(ctx, api.httpclient, endpoint, api.token, encoded, resp, api)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, resp.Err()
|
||||
}
|
||||
|
||||
// UpdateView updates an existing view.
|
||||
func (api *Client) UpdateView(view ModalViewRequest, externalID, hash, viewID string) (*ViewResponse, error) {
|
||||
return api.UpdateViewContext(context.Background(), view, externalID, hash, viewID)
|
||||
}
|
||||
|
||||
// UpdateViewContext updates an existing view with a custom context.
|
||||
func (api *Client) UpdateViewContext(
|
||||
ctx context.Context,
|
||||
view ModalViewRequest,
|
||||
externalID, hash,
|
||||
viewID string,
|
||||
) (*ViewResponse, error) {
|
||||
if externalID == "" && viewID == "" {
|
||||
return nil, ErrParametersMissing
|
||||
}
|
||||
req := updateViewRequest{
|
||||
View: view,
|
||||
ExternalID: externalID,
|
||||
Hash: hash,
|
||||
ViewID: viewID,
|
||||
}
|
||||
encoded, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
endpoint := api.endpoint + "views.update"
|
||||
resp := &ViewResponse{}
|
||||
err = postJSON(ctx, api.httpclient, endpoint, api.token, encoded, resp, api)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, resp.Err()
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
// +build !go1.13
|
||||
|
||||
package slack
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func PostWebhookCustomHTTPContext(ctx context.Context, url string, httpClient *http.Client, msg *WebhookMessage) error {
|
||||
raw, err := json.Marshal(msg)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "marshal failed")
|
||||
}
|
||||
|
||||
req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(raw))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed new request")
|
||||
}
|
||||
req = req.WithContext(ctx)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
resp, err := httpClient.Do(req)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to post webhook")
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
return checkStatusCode(resp, discard{})
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
// +build go1.13
|
||||
|
||||
package slack
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func PostWebhookCustomHTTPContext(ctx context.Context, url string, httpClient *http.Client, msg *WebhookMessage) error {
|
||||
raw, err := json.Marshal(msg)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "marshal failed")
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(raw))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed new request")
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
resp, err := httpClient.Do(req)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to post webhook")
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
return checkStatusCode(resp, discard{})
|
||||
}
|
Loading…
Reference in New Issue