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


Golang slack.New函數代碼示例

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


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

示例1: main

func main() {
	api := slack.New(token)
	err := api.CreateGroup(groupName)
	if err != nil {
		panic(err)
	}
}
開發者ID:mcntsh,項目名稱:asana-task-bot,代碼行數:7,代碼來源:groups_create.go

示例2: main

func main() {

	ts := oauth2.StaticTokenSource(
		&oauth2.Token{AccessToken: GITHUB_TOKEN},
	)
	tc := oauth2.NewClient(oauth2.NoContext, ts)

	githubClient := github.NewClient(tc)
	release, err := githubClient.Repositories.GetLatestRelease("FRC1360", "Stronghold2016")

	if err != nil {
		panic(err)
	}

	if downloadFromUrl(release.ZipballURL) {

		message := "Code Release Downloaded: " + release.AssetsURL + "\nSaved to Backup Server - Running copy cron job now."
		api := slack.New(SLACK_TOKEN)
		channel, err := api.FindChannelByName(SLACK_CHANNEL)
		if err != nil {
			panic(err)
		}
		err = api.ChatPostMessage(channel.Id, message, nil)
		if err != nil {
			panic(err)
		}
	}

}
開發者ID:FRC1360,項目名稱:ReleaseBot,代碼行數:29,代碼來源:main.go

示例3: newSlackNotify

func newSlackNotify(conf *SlackNotifyConfig) *SlackNotify {
	sn := &SlackNotify{
		slackApi: slack.New(conf.Token),
		Config:   conf,
	}
	return sn
}
開發者ID:RobinUS2,項目名稱:indispenso,代碼行數:7,代碼來源:notification_slack.go

示例4: main

func main() {
	api := slack.New(token)
	err := api.JoinChannel(channelName)
	if err != nil {
		panic(err)
	}
}
開發者ID:mcntsh,項目名稱:asana-task-bot,代碼行數:7,代碼來源:channels_join.go

示例5: main

func main() {
	api := slack.New(token)
	user, err := api.UsersInfo(userID)
	if err != nil {
		panic(err)
	}
	fmt.Println(user.Name, user.Profile.Email)
}
開發者ID:mcntsh,項目名稱:asana-task-bot,代碼行數:8,代碼來源:users_info.go

示例6: main

func main() {
	api := slack.New(token)
	groups, err := api.GroupsList()
	if err != nil {
		panic(err)
	}
	for _, group := range groups {
		fmt.Println(group.Id, group.Name)
	}
}
開發者ID:mcntsh,項目名稱:asana-task-bot,代碼行數:10,代碼來源:groups_list.go

示例7: main

func main() {
	api := slack.New(token)
	users, err := api.UsersList()
	if err != nil {
		panic(err)
	}
	for _, user := range users {
		fmt.Println(user.Id, user.Name)
	}
}
開發者ID:mcntsh,項目名稱:asana-task-bot,代碼行數:10,代碼來源:users_list.go

示例8: main

func main() {
	api := slack.New(token)
	auth, err := api.AuthTest()
	if err != nil {
		panic(err)
	}
	fmt.Println(auth.Url)
	fmt.Println(auth.Team)
	fmt.Println(auth.User)
}
開發者ID:sentinel-tools,項目名稱:eventilator,代碼行數:10,代碼來源:auth_test.go

示例9: main

func main() {
	api := slack.New(token)
	channels, err := api.ChannelsList()
	if err != nil {
		panic(err)
	}
	for _, channel := range channels {
		fmt.Println(channel.Id, channel.Name)
	}
}
開發者ID:mcntsh,項目名稱:asana-task-bot,代碼行數:10,代碼來源:channels_list.go

示例10: main

func main() {
	token, channelName, groupName, mention, items := helper.Getenvs()
	r := helper.GetReport(os.Stdin)

	api := slack.New(token)

	id := helper.GetID(api, r, channelName, groupName)
	msg := helper.GetMessage(r, mention)

	reporter.SendReportToSlack(api, r, id, msg, items)
}
開發者ID:ariarijp,項目名稱:horenso-reporter-slack,代碼行數:11,代碼來源:horenso-reporter-slack.go

示例11: main

func main() {
	api := slack.New(token)
	channel, err := api.FindChannelByName(channelName)
	if err != nil {
		panic(err)
	}
	err = api.ChatPostMessage(channel.Id, "Hello, world!", nil)
	if err != nil {
		panic(err)
	}
}
開發者ID:mcntsh,項目名稱:asana-task-bot,代碼行數:11,代碼來源:chat_post_message.go

示例12: Notify

func Notify(message string) {
	s := slack.New(SLACK_TOKEN)
	c, err := s.FindChannelByName(SLACK_CHANNEL)
	if err != nil {
		panic(err)
	}
	err = s.ChatPostMessage(c.Id, message, nil)
	if err != nil {
		panic(err)
	}
}
開發者ID:dmnlk,項目名稱:app-reviewer,代碼行數:11,代碼來源:main.go

示例13: main

func main() {
	api := slack.New(token)
	group, err := api.FindGroupByName(groupName)
	if err != nil {
		panic(err)
	}

	err = api.ChatPostMessage(group.Id, "Hello, world!", &slack.ChatPostMessageOpt{AsUser: true})
	if err != nil {
		panic(err)
	}
}
開發者ID:mcntsh,項目名稱:asana-task-bot,代碼行數:12,代碼來源:post_group_message.go

示例14: setupSlack

func setupSlack() {
	if len(os.Getenv("SLACK_API_TOKEN")) == 0 ||
		len(os.Getenv("SLACK_ROOM")) == 0 {
		color.Yellow("[>] Skipping Slack setup, missing SLACK_API_TOKEN and SLACK_ROOM")
		return
	}
	slack_api = slack.New(os.Getenv("SLACK_API_TOKEN"))

	slack_channel, err = slack_api.FindChannelByName(os.Getenv("SLACK_ROOM"))
	if err != nil {
		panic(err)
	}
}
開發者ID:joshrendek,項目名稱:influx-alert,代碼行數:13,代碼來源:notifiers.go

示例15: PostNotificationEventToSlackChannel

func PostNotificationEventToSlackChannel(config config.SlackConfig, event parser.NotificationEvent) (err error) {
	f, err := os.OpenFile("/var/log/redis/sentinel.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
	if err != nil {
		log.Printf("error opening log file: %v", err)
	}
	defer f.Close()

	log.SetOutput(f)
	doTrigger := contains(config.TriggerOn, event.Eventname)
	hostname, err := GetMyFQDN()
	if !doTrigger {
		return nil
	}
	api := slack.New(config.Token)
	channel, err := api.FindChannelByName(config.Channel)
	levelColor := "warning"
	// switch through event to determine attachment color
	switch event.Role {
	case "sentinel":
		levelColor = "danger"
	}
	switch event.Eventname {
	case "+odown", "-failover-abort-no-good-slave":
		levelColor = "danger"
	case "-odown", "-sdown":
		levelColor = "good"
	}
	att := slack.Attachment{Color: levelColor, AuthorName: config.AuthorName}
	att.Title = fmt.Sprintf("Sentinel event")
	eventField := slack.AttachmentField{Title: "Event Name", Value: event.Eventname, Short: true}
	podField := slack.AttachmentField{Title: "Pod Name", Value: event.Podname, Short: true}
	roleField := slack.AttachmentField{Title: "Role", Value: event.Role, Short: true}
	reporterField := slack.AttachmentField{Title: "Reporter", Value: hostname, Short: true}
	att.Fields = []*slack.AttachmentField{&eventField, &podField, &roleField, &reporterField}
	if err != nil {
		return (err)
	}
	var msg string
	switch levelColor {
	case "good":
		msg = "Phew, it has recovered."
	case "danger":
		msg = "UHOH! Something is broken."
	case "warning":
		msg = "Heads up, something isn't looking right."
	}
	atts := []*slack.Attachment{&att}
	msgopt := slack.ChatPostMessageOpt{AsUser: false, Attachments: atts, Username: config.Username}
	err = api.ChatPostMessage(channel.Id, msg, &msgopt)
	return err
}
開發者ID:sentinel-tools,項目名稱:eventilator,代碼行數:51,代碼來源:slack.go


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