Skip to content

Commit

Permalink
Merge pull request #16 from x1um1n/patch-1
Browse files Browse the repository at this point in the history
Add support for actions, to enable use of buttons
  • Loading branch information
ashwanthkumar authored Nov 19, 2018
2 parents eb0e8e8 + ba89a17 commit 2a72312
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ func main() {

attachment1 := slack.Attachment {}
attachment1.AddField(slack.Field { Title: "Author", Value: "Ashwanth Kumar" }).AddField(slack.Field { Title: "Status", Value: "Completed" })
attachment1.AddAction(slack.Action { Type: "button", Text: "Book flights 🛫", Url: "https://flights.example.com/book/r123456", Style: "primary" })
attachment1.AddAction(slack.Action { Type: "button", Text: "Cancel", Url: "https://flights.example.com/abandon/r123456", Style: "danger" })
payload := slack.Payload {
Text: "Hello from <https://github.com/ashwanthkumar/slack-go-webhook|slack-go-webhook>, a Go-Lang library to send slack webhook messages.\n<https://golangschool.com/wp-content/uploads/golang-teach.jpg|golang-img>",
Username: "robot",
Expand Down
14 changes: 14 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ type Field struct {
Short bool `json:"short"`
}

type Action struct {
Type string `json:"type"`
Text string `json:"text"`
Url string `json:"url"`
Style string `json:"style"`
}

type Attachment struct {
Fallback *string `json:"fallback"`
Color *string `json:"color"`
Expand All @@ -28,6 +35,8 @@ type Attachment struct {
FooterIcon *string `json:"footer_icon"`
Timestamp *int64 `json:"ts"`
MarkdownIn *[]string `json:"mrkdwn_in"`
Actions []*Action `json:"actions"`
CallbackID *string `json:"callback_id"`
}

type Payload struct {
Expand All @@ -49,6 +58,11 @@ func (attachment *Attachment) AddField(field Field) *Attachment {
return attachment
}

func (attachment *Attachment) AddAction(action Action) *Attachment {
attachment.Actions = append(attachment.Actions, &action)
return attachment
}

func redirectPolicyFunc(req gorequest.Request, via []gorequest.Request) error {
return fmt.Errorf("Incorrect token (redirection)")
}
Expand Down

0 comments on commit 2a72312

Please sign in to comment.