本文整理匯總了Golang中github.com/nlopes/slack.PostMessageParameters.Parse方法的典型用法代碼示例。如果您正苦於以下問題:Golang PostMessageParameters.Parse方法的具體用法?Golang PostMessageParameters.Parse怎麽用?Golang PostMessageParameters.Parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/nlopes/slack.PostMessageParameters
的用法示例。
在下文中一共展示了PostMessageParameters.Parse方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: handleChat
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
}
示例2: main
func main() {
flag.Parse()
// Read config block
config := &configStruct{}
userJSON, err := ioutil.ReadFile(*configFile)
if err != nil {
panic("ReadFile json failed")
}
if err = json.Unmarshal(userJSON, &config); err != nil {
panic("Unmarshal json failed")
}
api := slack.New(config.Token)
api.SetDebug(config.Debug)
rtm := api.NewRTM()
go rtm.ManageConnection()
postParams := slack.PostMessageParameters{}
postParams.Username = "dutybot"
postParams.Parse = "full"
postParams.IconEmoji = ":runner:"
// Get Duty users
Loop:
for {
select {
case msg := <-rtm.IncomingEvents:
switch ev := msg.Data.(type) {
case *slack.HelloEvent:
case *slack.ConnectedEvent:
fmt.Println("Infos:", ev.Info)
fmt.Println("Connection counter:", ev.ConnectionCount)
botID = ev.Info.User.ID
updateDutyGroup(api, config.DutyGroup)
case *slack.MessageEvent:
if ev.SubType == "channel_leave" || ev.SubType == "channel_join" {
updateDutyGroup(api, config.DutyGroup)
fmt.Printf("%s %s\n", ev.SubType, ev.User)
}
if strings.Contains(ev.Text, botID) {
if onDuty.Name != "" {
_, _, err := rtm.PostMessage(ev.Channel, fmt.Sprintf(config.MessageDuty, onDuty.Name), postParams)
if err != nil {
fmt.Printf("%s\n", err)
}
} else {
_, _, err := rtm.PostMessage(ev.Channel, config.MessageNoDuty, postParams)
if err != nil {
fmt.Printf("%s\n", err)
}
}
} else if strings.Contains(ev.Text, "@onduty") {
slackUser, err := rtm.GetUserInfo(ev.User)
if err != nil {
fmt.Printf("%s\n", err)
}
if stringInSlice(slackUser.ID, dutyMembers) {
onDuty = *slackUser
_, _, err = rtm.PostMessage(ev.Channel, fmt.Sprintf(config.MessageOnDuty, onDuty.Name), postParams)
if err != nil {
fmt.Printf("%s\n", err)
}
} else {
_, _, err = rtm.PostMessage(ev.Channel, fmt.Sprintf(config.MessageNotInDutyGroup, slackUser.Name), postParams)
if err != nil {
fmt.Printf("%s\n", err)
}
}
} else if strings.Contains(ev.Text, "@offduty") {
slackUser, err := rtm.GetUserInfo(ev.User)
if err != nil {
fmt.Printf("%s\n", err)
}
if onDuty.ID == ev.User {
_, _, err := rtm.PostMessage(ev.Channel, fmt.Sprintf(config.MessageOffDuty, onDuty.Name), postParams)
if err != nil {
fmt.Printf("%s\n", err)
}
onDuty = slack.User{}
} else {
_, _, err := rtm.PostMessage(ev.Channel, fmt.Sprintf(config.MessageNotDuty, slackUser.Name), postParams)
if err != nil {
//.........這裏部分代碼省略.........