Example #1
0
func (a *SendAttachments) Do(ctx coa.Context) error {
	log.Action("==> send attachments")
	client := ctx.ActionGroup().(HasClient).Client()
	params := slack.PostMessageParameters{}
	params.Attachments = []slack.Attachment{a.Attachment}
	params.Username = "******"
	params.IconURL = "https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcT4Nm9GTh-1aTRmNMdkkAYoCMFHALSj560lxbHA7nYSYjBcptH0JA"
	chanID := store.ChanByName("general").ID
	_, _, err := client.PostMessage(chanID, "", params)
	if err != nil {
		return err
	}
	return nil
}
Example #2
0
func main() {
	api := slack.New("YOUR_TOKEN_HERE")
	params := slack.PostMessageParameters{}
	attachment := slack.Attachment{
		Pretext: "some pretext",
		Text:    "some text",
		// Uncomment the following part to send a field too
		/*
			Fields: []slack.AttachmentField{
				slack.AttachmentField{
					Title: "a",
					Value: "no",
				},
			},
		*/
	}
	params.Attachments = []slack.Attachment{attachment}
	channelID, timestamp, err := api.PostMessage("CHANNEL_ID", "Some text", params)
	if err != nil {
		fmt.Printf("%s\n", err)
		return
	}
	fmt.Printf("Message successfully sent to channel %s at %s", channelID, timestamp)
}