func sendMessage(sendWg *sync.WaitGroup, config *model.Config, api *slack.Client, msg *model.ChatMessage) { params := slack.NewPostMessageParameters() params.Attachments = msg.Attachments params.Username = config.SlackUser params.IconURL = config.SlackIcon params.LinkNames = 1 params.AsUser = false channel := msg.Channel if channel == "" { // For now just print everything to the main channel. When we have RTM // support up and running we might also want the ability to write back // to a user DM channel. channel = config.SlackDefaultChannel } logOut.Debugf("Posting to channel %s %s %+v", channel, msg.Text, params) _, _, err := api.PostMessage(channel, msg.Text, params) if err != nil { logOut.Errorf("Error writing chat message: %s\n", err.Error()) } sendWg.Done() }
func notifyRoom(api *slack.Client, note Note) { var attachments []slack.Attachment avatar := slack.Attachment{Text: note.Text, Color: "good"} heading := fmt.Sprintf("%s Announcement from %s", strings.Title(note.Category), note.Author) params := slack.PostMessageParameters{Username: heading, IconURL: note.AvatarURL, Attachments: append(attachments, avatar)} _, _, err := api.PostMessage(fmt.Sprintf("#%s", targetRoom()), "", params) check(err) }
func slackMessage(client *slack.Client, ctx *PullRequestEventContext, msg string) error { messageParams := slack.PostMessageParameters{ IconEmoji: ":game_die:", Username: "******", LinkNames: 1, Attachments: []slack.Attachment{*pullRequestEventAttachment(ctx)}, } _, _, err := client.PostMessage(*ctx.Options.SlackChannel, msg, messageParams) return err }
func slackMessage(api *slack.Client, message string) { if len(message) > 0 { parms := slack.PostMessageParameters{ Username: *fUsername, } _, _, err := api.PostMessage(*fChannel, message, parms) if err != nil { panic(err) } } }
func statusToSlack(api *slack.Client, my_name string, channel string, msg string) { params := slack.NewPostMessageParameters() params.Username = my_name params.IconEmoji = ":exclamation:" attachment := slack.Attachment{} attachment.Color = "#ffaa00" attachment.Title = "Alarm Status Update" attachment.Text = msg params.Attachments = []slack.Attachment{attachment} api.PostMessage(channel, "", params) }
func logToSlack(api *slack.Client, my_name string, channel string, msg string, fields []slack.AttachmentField) { params := slack.NewPostMessageParameters() params.Username = my_name params.IconEmoji = ":page_with_curl:" attachment := slack.Attachment{} attachment.Color = "#ffaa00" attachment.Title = "Log Entry" attachment.Text = msg attachment.Fields = fields params.Attachments = []slack.Attachment{attachment} api.PostMessage(channel, "", params) }
func motionToSlack(api *slack.Client, my_name string, channel string, image string, count int) { _, err := http.Get(image) chk(err) params := slack.NewPostMessageParameters() params.Username = my_name params.IconEmoji = ":rotating_light:" attachment := slack.Attachment{} attachment.Color = "#ff0000" attachment.Title = "Motion detected" attachment.Text = fmt.Sprintf("Motion events detected: %d", count) attachment.ImageURL = image params.Attachments = []slack.Attachment{attachment} api.PostMessage(channel, "", params) }
func lightsToSlack(api *slack.Client, my_name string, channel string, image string, level int) { _, err := http.Get(image) chk(err) params := slack.NewPostMessageParameters() params.Username = my_name params.IconEmoji = ":bulb:" attachment := slack.Attachment{} attachment.Color = "#00ff00" attachment.Title = "Lights detected" attachment.Text = fmt.Sprintf("Light level detected: %d", level) attachment.ImageURL = image params.Attachments = []slack.Attachment{attachment} api.PostMessage(channel, "", params) }
func welcomeUser(user string, api *slack.Client) { fmt.Printf("New user joined: %s", user) _, _, channelID, err := api.OpenIMChannel(user) if err != nil { fmt.Printf("Error: %s\n", err) return } defer api.CloseIMChannel(channelID) text := ` Welcome to the Slack group! When you have a moment, head over to the #intros channel to introduce yourself to everyone here. We're making introducing yourself a requirement of being a part of the group. We want people to know they can reach out to a community of diverse experts on here to ask any questions or to engage in fruitful conversations. You should mention your name, what you do, and any expertise you have that might be helpful to the group. Thanks, and looking forward to having you here! ` params := slack.PostMessageParameters{ Username: SEND_AS_USER, AsUser: true, LinkNames: 1, } _, timestamp, err := api.PostMessage(channelID, text, params) if err != nil { fmt.Printf("Error: %s\n", err) return } fmt.Printf("Message successfully sent to channel %s at %s", channelID, timestamp) }
// RespChan creates and returns a buffered channel used to write messages to slack func RespChan(client *slack.Client, size int) (ch chan *Response) { ch = make(chan *Response, size) go func() { for { select { case m := <-ch: if m.Channel == "" { log.Print("Channel is empty") continue } if m.Text == "" { log.Print("Text is empty") continue } if _, _, err := client.PostMessage(m.Channel, m.Text, m.Parameters); err != nil { log.Printf("Error posting message to %s [%v].", m.Channel, err) } } } }() return }
func sendMessage(api slack.Client, channel string, message string) error { params := slack.PostMessageParameters{} params.LinkNames = 1 _, _, err := api.PostMessage(channel, message, params) return err }