• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang slack.New函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/bluele/slack.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: main

func main() {
	api := slack.New(token)
	channel, err := api.FindChannelByName(channelName)
	if err != nil {
		panic(err)
	}
	err = api.ChatPostMessage(channel.Id, "Hello, world!", &slack.ChatPostMessageOpt{
		Attachments: []*slack.Attachment{
			{Text: "danger", Color: "danger"},
		},
	})
	if err != nil {
		panic(err)
	}
}
开发者ID:mcntsh,项目名称:asana-task-bot,代码行数:15,代码来源:chat_post_attachments.go


示例17: newSlackEcho

func newSlackEcho(token, channelName string) (*SlackEcho, error) {
	se := &SlackEcho{
		api:         slack.New(token),
		opts:        &slack.ChatPostMessageOpt{AsUser: true},
		queue:       newStreamQ(),
		shutdown:    make(chan os.Signal, 1),
		channelName: channelName,
	}
	err := se.lookupSlackId()
	if err != nil {
		return nil, err
	}
	signal.Notify(se.shutdown, os.Interrupt)
	return se, nil
}
开发者ID:tsroten,项目名称:slackecho,代码行数:15,代码来源:slackecho.go


示例18: main

func main() {
	api := slack.New(token)
	channel, err := api.FindChannelByName(channelName)
	if err != nil {
		panic(err)
	}
	msgs, err := api.ChannelsHistory(&slack.ChannelsHistoryOpt{
		Channel: channel.Id,
	})
	if err != nil {
		panic(err)
	}
	for _, msg := range msgs {
		fmt.Println(msg.UserId, msg.Text)
	}
}
开发者ID:mcntsh,项目名称:asana-task-bot,代码行数:16,代码来源:channels_history.go


示例19: newSlackCat

func newSlackCat(token, channelName string) *SlackCat {
	sc := &SlackCat{
		api:         slack.New(token),
		opts:        &slack.ChatPostMessageOpt{AsUser: true},
		queue:       newStreamQ(),
		shutdown:    make(chan os.Signal, 1),
		channelName: channelName,
	}

	res, err := sc.api.AuthTest()
	failOnError(err, "Slack API Error", true)
	output(fmt.Sprintf("connected to %s as %s", res.Team, res.User))
	sc.channelID = sc.lookupSlackID()

	signal.Notify(sc.shutdown, os.Interrupt)
	return sc
}
开发者ID:brewingcode,项目名称:slackcat,代码行数:17,代码来源:slackcat.go


示例20: main

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

	user, err := api.FindUser(func(user *slack.User) bool {
		return user.Name == inviteUserName
	})
	if err != nil {
		panic(err)
	}

	err = api.InviteGroup(group.Id, user.Id)
	if err != nil {
		panic(err)
	}
}
开发者ID:mcntsh,项目名称:asana-task-bot,代码行数:19,代码来源:groups_invite.go



注:本文中的github.com/bluele/slack.New函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang aws.Bool函数代码示例发布时间:2022-05-24
下一篇:
Golang request.Request类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap