func hc(values url.Values) { var color, message string switch values.Get("Status") { case "Up": color = getColor(config.UpColor) message = formatMessage(values, config.MessageUp) case "Down": color = getColor(config.DownColor) message = formatMessage(values, config.MessageDown) } c := hipchat.Client{AuthToken: config.AuthToken} req := hipchat.MessageRequest{ RoomId: config.RoomId, From: config.From, Message: message, Color: color, MessageFormat: hipchat.FormatText, Notify: config.Notify, } if err := c.PostMessage(req); err != nil { fmt.Println("Expected no error, but got %q", err) } }
func rockGiphy(q string, c *hipchat.Client) { log.Printf("Searching for %q", q) url := fmt.Sprintf("http://api.giphy.com/v1/gifs/search?q=%s&api_key=dc6zaTOxFJmzC", url.QueryEscape(q)) resp, err := http.Get(url) if err != nil { log.Println(err) return } defer resp.Body.Close() giphyResp := &struct{ Data []GiphyGif }{} dec := json.NewDecoder(resp.Body) if err := dec.Decode(giphyResp); err != nil { log.Println(err) return } msg := "NO RESULTS. I’M A MONSTER." if len(giphyResp.Data) > 0 { msg = fmt.Sprintf("%s: %s", q, giphyResp.Data[rand.Intn(len(giphyResp.Data))].Images.Original.URL) } req := hipchat.MessageRequest{ RoomId: *roomName, From: "BUSTER", Message: msg, Color: hipchat.ColorRandom, MessageFormat: hipchat.FormatText, Notify: true, } if err := c.PostMessage(req); err != nil { log.Printf("Expected no error, but got %q", err) } }
// helper function to send Hipchat requests func (h *Hipchat) send(color, format, message string) error { c := hipchat.Client{AuthToken: h.Token} req := hipchat.MessageRequest{ RoomId: h.Room, From: "Drone", Message: message, Color: color, MessageFormat: format, Notify: true, } return c.PostMessage(req) }
func (h HipChatSender) SendMessage(room_id, message string) error { c := hipchat.Client{AuthToken: h.AuthToken} c.BaseURL = "https://api.hipchat.com/v1" req := hipchat.MessageRequest{ RoomId: room_id, From: "Amazon SNS", Message: message, Color: hipchat.ColorYellow, MessageFormat: hipchat.FormatText, Notify: true, } return c.PostMessage(req) }
func sendMessageToRoom(token, roomID, from, message string, color string) error { c := hipchat.Client{AuthToken: token} req := hipchat.MessageRequest{ RoomId: roomID, From: from, Message: message, Color: color, MessageFormat: hipchat.FormatText, Notify: false, } return c.PostMessage(req) }
func main() { c := hipchat.Client{AuthToken: "<PUT YOUR AUTH TOKEN HERE>"} req := hipchat.MessageRequest{ RoomId: "Rat Man’s Den", From: "GLaDOS", Message: "Bad news: Combustible lemons failed.", Color: hipchat.ColorPurple, MessageFormat: hipchat.FormatText, Notify: true, } if err := c.PostMessage(req); err != nil { log.Printf("Expected no error, but got %q", err) } }
func notifyPullRequest(pr github.PullRequest, room string, token string) { message := fmt.Sprintf("PR is %d days old: %s", int(time.Since(*pr.CreatedAt).Hours()/24), *pr.HTMLURL) client := hipchat.Client{AuthToken: token} req := hipchat.MessageRequest{ RoomId: room, From: "PR Checker", Message: message, Color: hipchat.ColorRed, MessageFormat: hipchat.FormatText, Notify: true, } fmt.Println("Sending HipChat notification:", message) if err := client.PostMessage(req); err != nil { fmt.Println("Failed to send HipChat notification:", err) } }
// Post posts a hipchat message // TODO: make hipchat api endpoint configurable for on-premises servers func (hipChat *HipChat) Post(message string) bool { client := hipchat.Client{AuthToken: hipChat.Token} req := hipchat.MessageRequest{ RoomId: hipChat.RoomID, From: hipChat.From, Message: message, Color: hipchat.ColorPurple, MessageFormat: hipchat.FormatText, Notify: true, } if err := client.PostMessage(req); err != nil { log.Errorf("Failed post message...: %s", message) return false } return true }
func HepCat(msg string) (hep string, err error) { c := hipchat.Client{AuthToken: ""} req := hipchat.MessageRequest{ RoomId: "", From: "", Message: msg, Color: hipchat.ColorPurple, MessageFormat: hipchat.FormatText, Notify: true, } if err := c.PostMessage(req); err != nil { log.Printf("Expected no error, but got %q", err) } return "crap", err }