| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "fmt" |
| 6 | "strconv" |
| 7 | "time" |
| 8 | |
| 9 | "github.com/slack-go/slack" |
| 10 | ) |
| 11 | |
| 12 | func main() { |
| 13 | attachment := slack.Attachment{ |
| 14 | Color: "good", |
| 15 | Fallback: "You successfully posted by Incoming Webhook URL!", |
| 16 | AuthorName: "slack-go/slack", |
| 17 | AuthorSubname: "github.com", |
| 18 | AuthorLink: "https://github.com/slack-go/slack", |
| 19 | AuthorIcon: "https://avatars2.githubusercontent.com/u/652790", |
| 20 | Text: "<!channel> All text in Slack uses the same system of escaping: chat messages, direct messages, file comments, etc. :smile:\nSee <https://api.slack.com/docs/message-formatting#linking_to_channels_and_users>", |
| 21 | Footer: "slack api", |
| 22 | FooterIcon: "https://platform.slack-edge.com/img/default_application_icon.png", |
| 23 | Ts: json.Number(strconv.FormatInt(time.Now().Unix(), 10)), |
| 24 | } |
| 25 | msg := slack.WebhookMessage{ |
| 26 | Attachments: []slack.Attachment{attachment}, |
| 27 | } |
| 28 | |
| 29 | err := slack.PostWebhook("YOUR_WEBHOOK_URL_HERE", &msg) |
| 30 | if err != nil { |
| 31 | fmt.Println(err) |
| 32 | } |
| 33 | } |