func (s *Slack) handleChat(action string, params map[string]string) (interface{}, error) { var v interface{} var err error switch action { case "delete": ch, ts, err := s.s.DeleteMessage(params["channel"], params["ts"]) if err != nil { return nil, err } v = map[string]string{ "channel": ch, "ts": ts, } case "postmessage": postParam := slack.PostMessageParameters{} postParam.Username = getStringParam(params, "username", slack.DEFAULT_MESSAGE_USERNAME) postParam.Parse = getStringParam(params, "parse", slack.DEFAULT_MESSAGE_PARSE) postParam.LinkNames = getIntParam(params, "link_names", slack.DEFAULT_MESSAGE_LINK_NAMES) postParam.UnfurlLinks = getBoolParam(params, "unfurl_links", slack.DEFAULT_MESSAGE_UNFURL_LINKS) postParam.UnfurlMedia = getBoolParam(params, "unfurl_media", slack.DEFAULT_MESSAGE_UNFURL_MEDIA) postParam.IconURL = getStringParam(params, "icon_url", slack.DEFAULT_MESSAGE_ICON_URL) postParam.IconEmoji = getStringParam(params, "icon_emoji", slack.DEFAULT_MESSAGE_ICON_EMOJI) if err = json.Unmarshal([]byte(getStringParam(params, "attachments", "[]")), &postParam.Attachments); err != nil { return nil, err } ch, ts, err := s.s.PostMessage(params["channel"], params["text"], postParam) if err != nil { return nil, err } v = map[string]string{ "channel": ch, "ts": ts, } case "update": ch, ts, text, err := s.s.UpdateMessage(params["channel"], params["ts"], params["text"]) if err != nil { return nil, err } v = map[string]string{ "channel": ch, "ts": ts, "text": text, } default: return nil, fmt.Errorf("invalid chat action %s", action) } return v, err }
func sendMessage(api slack.Client, channel string, message string) error { params := slack.PostMessageParameters{} params.LinkNames = 1 _, _, err := api.PostMessage(channel, message, params) return err }