Skip to content

Commit 2a72312

Browse files
Merge pull request #16 from x1um1n/patch-1
Add support for actions, to enable use of buttons
2 parents eb0e8e8 + ba89a17 commit 2a72312

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ func main() {
1616

1717
attachment1 := slack.Attachment {}
1818
attachment1.AddField(slack.Field { Title: "Author", Value: "Ashwanth Kumar" }).AddField(slack.Field { Title: "Status", Value: "Completed" })
19+
attachment1.AddAction(slack.Action { Type: "button", Text: "Book flights 🛫", Url: "https://flights.example.com/book/r123456", Style: "primary" })
20+
attachment1.AddAction(slack.Action { Type: "button", Text: "Cancel", Url: "https://flights.example.com/abandon/r123456", Style: "danger" })
1921
payload := slack.Payload {
2022
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>",
2123
Username: "robot",

main.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ type Field struct {
1212
Short bool `json:"short"`
1313
}
1414

15+
type Action struct {
16+
Type string `json:"type"`
17+
Text string `json:"text"`
18+
Url string `json:"url"`
19+
Style string `json:"style"`
20+
}
21+
1522
type Attachment struct {
1623
Fallback *string `json:"fallback"`
1724
Color *string `json:"color"`
@@ -28,6 +35,8 @@ type Attachment struct {
2835
FooterIcon *string `json:"footer_icon"`
2936
Timestamp *int64 `json:"ts"`
3037
MarkdownIn *[]string `json:"mrkdwn_in"`
38+
Actions []*Action `json:"actions"`
39+
CallbackID *string `json:"callback_id"`
3140
}
3241

3342
type Payload struct {
@@ -49,6 +58,11 @@ func (attachment *Attachment) AddField(field Field) *Attachment {
4958
return attachment
5059
}
5160

61+
func (attachment *Attachment) AddAction(action Action) *Attachment {
62+
attachment.Actions = append(attachment.Actions, &action)
63+
return attachment
64+
}
65+
5266
func redirectPolicyFunc(req gorequest.Request, via []gorequest.Request) error {
5367
return fmt.Errorf("Incorrect token (redirection)")
5468
}

0 commit comments

Comments
 (0)