當前位置: 首頁>>代碼示例>>Golang>>正文


Golang slack.NewPostMessageParameters函數代碼示例

本文整理匯總了Golang中github.com/nlopes/slack.NewPostMessageParameters函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewPostMessageParameters函數的具體用法?Golang NewPostMessageParameters怎麽用?Golang NewPostMessageParameters使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewPostMessageParameters函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: main

func main() {
	iniflags.Parse()

	api := slack.New(*token)

	//var channel_id string
	channel_id := getChannelId(*channel, api)

	var include, exclude *regexp.Regexp
	var err error
	if *includes != "" {
		include, err = regexp.Compile(*includes)
		if err != nil {
			fmt.Println("ERROR: Failed to compile `line_includes` regex.")
			fmt.Println(err)
			api.PostMessage(channel_id, "==> slackd failed to compile `line_includes` regex.", slack.NewPostMessageParameters())
			api.PostMessage(channel_id, err.Error(), slack.NewPostMessageParameters())
			os.Exit(2)
		}
	}
	if *excludes != "" {
		exclude, err = regexp.Compile(*excludes)
		if err != nil {
			fmt.Println("ERROR: Failed to compile `line_excludes` regex.")
			fmt.Println(err)
			api.PostMessage(channel_id, "==> slackd failed to compile `line_excludes` regex.", slack.NewPostMessageParameters())
			api.PostMessage(channel_id, err.Error(), slack.NewPostMessageParameters())
			os.Exit(2)
		}
	}

	log, err := tail.TailFile(*file, tail.Config{Follow: true, ReOpen: *reopen, Poll: true})
	if err != nil {
		fmt.Println("ERROR: Could not tail the specified log.")
		fmt.Println(err)
		api.PostMessage(channel_id, "==> slackd could not tail the specified log.", slack.NewPostMessageParameters())
		api.PostMessage(channel_id, err.Error(), slack.NewPostMessageParameters())
		os.Exit(2)
	}
	for line := range log.Lines {
		if (include != nil && include.MatchString(line.Text)) || (exclude != nil && !exclude.MatchString(line.Text)) {
			api.PostMessage(
				channel_id,
				fmt.Sprintf("```%s```", line.Text),
				slack.NewPostMessageParameters())
		}
	}
}
開發者ID:swill,項目名稱:slackd,代碼行數:48,代碼來源:slackd.go

示例2: postToSlack

func postToSlack(username string, channel string, message string, attachments string) {
	param := slack.NewPostMessageParameters()
	param.Username = username

	dec := json.NewDecoder(strings.NewReader(attachments))
	_ = dec.Decode(&param.Attachments)
	fmt.Printf("%v\n", param.Attachments)

	_, _, err := ctx.slack.PostMessage(channel, message, param)
	if err != nil {
		log.WithFields(log.Fields{
			"username":    username,
			"channel":     channel,
			"message":     message,
			"attachments": attachments,
		}).Error(err.Error())
		return
	}
	log.WithFields(log.Fields{
		"username":    username,
		"channel":     channel,
		"message":     message,
		"attachments": attachments,
	}).Info("posted")
}
開發者ID:tattsun,項目名稱:slack-gateway,代碼行數:25,代碼來源:slack-gateway.go

示例3: performTask

func (rt ReconTask) performTask(task ActionItemConfig, stringContext map[string]interface{}) {
	rt.log.Debug("Task Config - %v", task.Config)
	switch task.Type {
	case "sendToSlack":
		message := EvaluateTemplate(task.Config["message"].(string), stringContext)
		slackClient := slack.New(task.Config["slackKey"].(string))
		slackClient.PostMessage(task.Config["slackTo"].(string), message, slack.NewPostMessageParameters())
	case "executeMysql":
		query := EvaluateTemplate(task.Config["query"].(string), stringContext)
		params := task.Config["params"].([]interface{})
		paramValues := make([]interface{}, 0)
		for _, param := range params {
			paramValue := EvaluateTemplate(param.(string), stringContext)
			paramValues = append(paramValues, paramValue)
		}
		endPoint, err := NewMysqlDataProvider(task.Config["mysqlConfig"].(map[string]interface{}))
		if err != nil {
			rt.log.Error("Failed to connect to mysql - %v", err)
		}
		stmt, err := endPoint.db.Prepare(query)
		if err != nil {
			rt.log.Error("Failed to prepare statement- %v", err)
		}
		defer stmt.Close()
		rt.log.Info("Executing [%s] with params [%v]", query, paramValues)
		result, err := stmt.Exec(paramValues...)
		if err != nil {
			rt.log.Error("Failed to Execute query - %v", err)
		}
		count, _ := result.RowsAffected()
		if count < 1 {
			rt.log.Info("0 rows affected, might want to check - %v", stringContext)
		}
	}
}
開發者ID:artpar,項目名稱:greconcile,代碼行數:35,代碼來源:task.go

示例4: Publish

// Publish Publishes messages to slack
func (x Slack) Publish(publishMsgs <-chan models.Message, connector models.Connector) {
	api := slack.New(connector.Key)
	for {
		message := <-publishMsgs
		msg := ""
		params := slack.NewPostMessageParameters()
		params.Username = connector.BotName
		params.IconEmoji = connector.Image
		if message.Out.Detail != "" {
			color := slackColorMe(message.Out.Status)
			attachment := slack.Attachment{
				Title:      message.Out.Text,
				TitleLink:  message.Out.Link,
				Text:       message.Out.Detail,
				Color:      color,
				MarkdownIn: []string{"text"},
			}
			params.Attachments = []slack.Attachment{attachment}
		} else {
			msg = message.Out.Text
		}
		for _, target := range strings.Split(message.Out.Target, ",") {
			if target == "*" {
				target = message.In.Target
			}
			if target != "" && target != "*" {
				api.PostMessage(target, msg, params)
			}
		}
	}
}
開發者ID:projectjane,項目名稱:jane,代碼行數:32,代碼來源:slack.go

示例5: Write

// expect some byte and write to slack
func (s *Slack) Write(o []byte) (n int, err error) {
	outBuf := bytes.Buffer{}
	outBuf.Write(o)

	//s.rtm.SendMessage(
	//s.rtm.NewOutgoingMessage(
	//outBuf.String(),
	//s.channel,
	//),
	//)
	params := slack.NewPostMessageParameters()
	params.Username = "supslack"
	params.AsUser = true

	params.Attachments = []slack.Attachment{
		{
			//AuthorName: authorName,
			//AuthorIcon: authorIcon,
			Text: fmt.Sprintf("%s\n\u2014\n", outBuf.String()), // \u200B for space
			//ThumbURL: thumbURL,
			//Fields: []AttachmentField{
			//AttachmentField{
			//Title: "",
			//Value: fmt.Sprintf("*<%s|%s>*\n%s", post.ShortUrl, post.Title, description),
			//Short: false,
			//},
			//},
			MarkdownIn: []string{"text"},
		}}

	s.api.PostMessage(s.channel, "", params)
	return len(o), nil
}
開發者ID:travellingprog,項目名稱:supbot,代碼行數:34,代碼來源:client.go

示例6: sendMessage

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()
}
開發者ID:dimfeld,項目名稱:promulgator,代碼行數:25,代碼來源:outgoing.go

示例7: DefaultMessageParameters

// DefaultMessageParameters returns a default PostMessageParameters for vropsbot
func DefaultMessageParameters() (params slack.PostMessageParameters) {
	params = slack.NewPostMessageParameters()
	params.AsUser = true
	params.EscapeText = false

	return
}
開發者ID:bruceadowns,項目名稱:vropsbot,代碼行數:8,代碼來源:respchan.go

示例8: Run

func (c *HelpCommand) Run(m *slack.MessageEvent, args ...string) {
	params := slack.NewPostMessageParameters()
	params.Attachments = []slack.Attachment{slack.Attachment{
		Color:  "good",
		Fields: []slack.AttachmentField{},
	}}

	service := c.Service.(*SlackService)
	if len(args) == 0 {
		for name := range service.Commands {
			params.Attachments[0].Fields = append(params.Attachments[0].Fields, slack.AttachmentField{
				Title: service.Commands[name].GetName(),
				Value: service.Commands[name].GetDescription(),
			})
		}
	} else if command, ok := service.Commands[args[0]]; ok {
		params.Attachments[0].Fields = append(params.Attachments[0].Fields, slack.AttachmentField{
			Title: command.GetName(),
			Value: command.GetDescription(),
		})
	} else {
		c.SendMessagef(m.Channel, "Команда %s не найдена", args[0])
		return
	}

	c.SendPostMessage(m.Channel, "Мои команды", params)
}
開發者ID:kihamo,項目名稱:shadow-slack,代碼行數:27,代碼來源:command_help.go

示例9: newPostMessageParams

func (s Slack) newPostMessageParams() slack.PostMessageParameters {
	params := slack.NewPostMessageParameters()
	if s.userName != "" {
		params.Username = s.userName
	}
	if s.iconURL != "" {
		params.IconURL = s.iconURL
	}
	return params
}
開發者ID:kyokomi,項目名稱:geiborugu,代碼行數:10,代碼來源:main.go

示例10: main

func main() {
	if cli.file != "" {
		log.Printf("Loading config from %s\n", cli.file)
		f, err := os.Open(cli.file)
		if err != nil {
			log.Fatal(err)
		}
		defer f.Close()
		err = json.NewDecoder(f).Decode(&settings)
		if err != nil {
			log.Fatal(err)
		}
	} else {
		log.Fatal("You need to pass a json file to -config")
	}

	// override whats in the settings with whats on the cli
	if cli.token != "" {
		log.Printf("Slack token passed via CLI: %s\n", cli.token)
		settings.Token = cli.token
	}
	if settings.Botname == "" || cli.botname != "" {
		settings.Botname = cli.botname
	}

	if settings.Token == "" {
		log.Fatal("You need to give me an API token!")
	}

	collins := c.New(settings.Collins.Username, settings.Collins.Password, settings.Collins.Host)

	// set up posting params
	postParams = slack.NewPostMessageParameters()
	//postParams.Username = settings.Botname
	//postParams.LinkNames = 1
	// we will perform proper formatting per https://api.slack.com/docs/formatting, do make the server do no processing
	postParams.Parse = "none"

	api := slack.New(settings.Token)
	api.SetDebug(cli.debug)
	authresp, err := api.AuthTest()
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("Authed with Slack successfully as %s (%s)\n", authresp.User, authresp.UserId)

	log.Printf("Creating new handler context with message handlers:\n")
	for _, v := range messagehandlers {
		log.Printf("  %s\n", v)
	}
	handlerContext = handlers.New(collins, authresp, api, messagehandlers)
	log.Printf("Starting up message handler")
	handlerContext.Run()

}
開發者ID:byxorna,項目名稱:collinsbot,代碼行數:55,代碼來源:main.go

示例11: statusToSlack

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)
}
開發者ID:ballarat-hackerspace,項目名稱:alarmbot-go,代碼行數:11,代碼來源:alarmbot.go

示例12: logToSlack

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)
}
開發者ID:ballarat-hackerspace,項目名稱:alarmbot-go,代碼行數:12,代碼來源:alarmbot.go

示例13: motionToSlack

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)
}
開發者ID:ballarat-hackerspace,項目名稱:alarmbot-go,代碼行數:15,代碼來源:alarmbot.go

示例14: lightsToSlack

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)
}
開發者ID:ballarat-hackerspace,項目名稱:alarmbot-go,代碼行數:15,代碼來源:alarmbot.go

示例15: Send

func (b *Bslack) Send(msg config.Message) error {
	flog.Debugf("Receiving %#v", msg)
	if msg.Account == b.Account {
		return nil
	}
	nick := msg.Username
	message := msg.Text
	channel := msg.Channel
	if b.Config.PrefixMessagesWithNick {
		message = nick + " " + message
	}
	if !b.Config.UseAPI {
		matterMessage := matterhook.OMessage{IconURL: b.Config.IconURL}
		matterMessage.Channel = channel
		matterMessage.UserName = nick
		matterMessage.Type = ""
		matterMessage.Text = message
		err := b.mh.Send(matterMessage)
		if err != nil {
			flog.Info(err)
			return err
		}
		return nil
	}
	schannel, err := b.getChannelByName(channel)
	if err != nil {
		return err
	}
	np := slack.NewPostMessageParameters()
	if b.Config.PrefixMessagesWithNick == true {
		np.AsUser = true
	}
	np.Username = nick
	np.IconURL = config.GetIconURL(&msg, b.Config)
	if msg.Avatar != "" {
		np.IconURL = msg.Avatar
	}
	b.sc.PostMessage(schannel.ID, message, np)

	/*
	   newmsg := b.rtm.NewOutgoingMessage(message, schannel.ID)
	   b.rtm.SendMessage(newmsg)
	*/

	return nil
}
開發者ID:42wim,項目名稱:matterbridge,代碼行數:46,代碼來源:slack.go


注:本文中的github.com/nlopes/slack.NewPostMessageParameters函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。