func processShuttleCommand(bot *BaseBot, channel string) { // retrieve shuttle bus information from official site resp, err := http.Get("http://www.yonsei.ac.kr/_custom/yonsei/_common/shuttle_bus/get_bus_info.jsp") if err != nil { shuttleErrorMessage(bot, channel) return } buf := new(bytes.Buffer) buf.ReadFrom(resp.Body) b := buf.Bytes() var info BusInfo err = json.Unmarshal(b, &info) if err != nil { shuttleErrorMessage(bot, channel) return } attachments := make([]slack.AttachmentField, len(info.MBus)+len(info.ABus)) index := 0 for _, pos := range info.MBus { makeShuttlePositionAttachmentField(&attachments[index], before_noon, pos) index++ } for _, pos := range info.ABus { makeShuttlePositionAttachmentField(&attachments[index], after_noon, pos) index++ } attachment := slack.Attachment{ Color: "#1766ff", } if len(attachments) == 0 { // no info! attachment.Text = "현재 운영중인 셔틀버스 정보 없음" } else { attachment.Text = "셔틀버스 위치" attachment.Fields = attachments } bot.PostMessage(channel, "", slack.PostMessageParameters{ AsUser: false, IconEmoji: ":bus:", Username: "******", Attachments: []slack.Attachment{ attachment, }, }) }
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) }