예제 #1
0
func main() {
	api := slack.New(token)
	err := api.CreateGroup(groupName)
	if err != nil {
		panic(err)
	}
}
예제 #2
0
파일: main.go 프로젝트: FRC1360/ReleaseBot
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)
		}
	}

}
예제 #3
0
func newSlackNotify(conf *SlackNotifyConfig) *SlackNotify {
	sn := &SlackNotify{
		slackApi: slack.New(conf.Token),
		Config:   conf,
	}
	return sn
}
예제 #4
0
func main() {
	api := slack.New(token)
	err := api.JoinChannel(channelName)
	if err != nil {
		panic(err)
	}
}
예제 #5
0
func main() {
	api := slack.New(token)
	user, err := api.UsersInfo(userID)
	if err != nil {
		panic(err)
	}
	fmt.Println(user.Name, user.Profile.Email)
}
예제 #6
0
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)
	}
}
예제 #7
0
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)
	}
}
예제 #8
0
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)
}
예제 #9
0
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)
	}
}
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)
}
예제 #11
0
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)
	}
}
예제 #12
0
파일: main.go 프로젝트: dmnlk/app-reviewer
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)
	}
}
예제 #13
0
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)
	}
}
예제 #14
0
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)
	}
}
예제 #15
0
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
}
예제 #16
0
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)
	}
}
예제 #17
0
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
}
예제 #18
0
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)
	}
}
예제 #19
0
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
}
예제 #20
0
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)
	}
}
예제 #21
0
파일: main.go 프로젝트: sorenmat/botbrother
func main() {
	kingpin.Version("1.3")
	kingpin.Parse()

	api := slack.New(*token)

	for {

		users, _ := api.UsersList()

		svc := ec2.New(session.New(), &aws.Config{Region: aws.String(*region)})

		// Call the DescribeInstances Operation
		resp, err := svc.DescribeInstances(nil)
		if err != nil {
			panic(err)
		}

		usersInstances := findLongRunningInstances(resp, users)
		alreadyNotified := getAlreadyNotified()

		for user, instances := range usersInstances {
			msg := ""
			for _, inst := range instances {
				if !contains(alreadyNotified, *inst.InstanceId) {
					msg += fmt.Sprintf("`%v - %v` with id _%v_\n", getTagValue(inst.Tags, "Purpose"), getTagValue(inst.Tags, "Name"), *inst.InstanceId)
					alreadyNotified = append(alreadyNotified, *inst.InstanceId)
				}
			}
			if msg != "" {
				msg := "\nYou have the following instances running in amazon:\n\n" + msg
				msg += "They were all started more then two days ago, are they still needed ?"
				if user == "U02HSGZ3F" || *prod { // ME
					err = api.ChatPostMessage(user, msg, &slack.ChatPostMessageOpt{Username: "******"})
				}

			}

		}
		saveAlreadyNotified(alreadyNotified)
		time.Sleep(time.Duration(*timeout) * time.Minute)
	}
}
예제 #22
0
func main() {
	api := slack.New(token)
	channel, err := api.FindChannelByName(channelName)
	if err != nil {
		panic(err)
	}

	err = api.FilesUpload(&slack.FilesUploadOpt{
		Filepath: uploadFilePath,
		Filetype: "text",
		Filename: filepath.Base(uploadFilePath),
		Title:    "upload test",
		Channels: []string{channel.Id},
	})
	if err != nil {
		panic(err)
	}

	fmt.Println("Completed file upload.")
}
예제 #23
0
func main() {
	config = GetConfig()

	tok := &oauth2.Token{
		AccessToken: config.AsanaAPIKey,
	}

	tokSrc := oauth2.StaticTokenSource(tok)
	tokenAuth := oauth2.NewClient(context.TODO(), tokSrc)

	asanaAPI = asana.NewClient(tokenAuth)
	slackAPI = slack.New(config.SlackAPIKey)

	server := &http.Server{
		Addr:    config.Address,
		Handler: Router(),
	}

	fmt.Printf("API Server started at: %s\n", config.Address)
	log.Fatalln(server.ListenAndServe())
}
예제 #24
0
파일: main.go 프로젝트: a-r-g-v/almost-ddns
func work() {

	targetDomain := config.Server.TargetDomain
	nameServer := config.Server.NameServer

	// counter
	status.SameCount = 0
	status.CheckCount = 0

	// connection slack-api
	api := slack.New(config.Slack.Token)
	channel, err := api.FindChannelByName(config.Slack.Channel)
	if err != nil {
		panic(err)
	}

	for {
		status.CheckCount = status.CheckCount + 1

		// notify running?
		if status.CheckCount%60 == 0 {
			err = api.ChatPostMessage(channel.Id, "@takoyaki I'm running. ", nil)
			if err != nil {
				fmt.Println("slack api error", err)
			}
		}

		time.Sleep(60 * time.Second)

		// nonreq-resovle using dig(/hack/resolve.sh), get registry ipv4 address
		ripaddr, err := resolve(targetDomain, nameServer)
		if err != nil {
			fmt.Println("resolve error:", err)
			continue
		}

		if ripaddr == nil {
			fmt.Println("resolve error:", "resolve ip == nil")
			continue
		}

		fmt.Println("resovle ipaddr:", ripaddr.String())

		// get global-ipv4-address using STUN
		_, host, err := stun.NewClient().Discover()
		if err != nil {
			fmt.Println("stun client error", err)
			continue
		}

		if host == nil {
			fmt.Println("stun client error", "host == nil")
			continue
		}

		gipaddr := net.ParseIP(host.IP())
		fmt.Println("stun client ipaddr:", gipaddr.String())

		// compare
		if gipaddr.String() == ripaddr.String() {
			fmt.Println("same")
			status.SameCount = status.SameCount + 1
			continue
		}

		// notify update
		err = api.ChatPostMessage(channel.Id, "@takoyaki global-ipv4-address != resolve-ipv4-address. Now, I try to update. ", nil)
		if err != nil {
			fmt.Println("slack api error", err)
		}
		fmt.Println("not equal ipaddr")

		// update
		_, err = exec.Command("/bin/bash", "hack/update.sh", gipaddr.String()).Output()
		if err != nil {
			fmt.Println("update error", err)
			continue
		}

		// wait
		time.Sleep(5 * 10 * time.Second)

	}
}
예제 #25
0
func main() {
	app := cli.NewApp()
	app.Name = "slackcat"
	app.Usage = "redirect a file to slack"
	app.Version = version
	app.Flags = []cli.Flag{
		cli.BoolFlag{
			Name:  "tee, t",
			Usage: "Print stdin to screen before posting",
		},
		cli.BoolFlag{
			Name:  "noop",
			Usage: "Skip posting file to Slack. Useful for testing",
		},
		cli.BoolFlag{
			Name:  "configure",
			Usage: "Configure Slackcat via oauth",
		},
		cli.StringFlag{
			Name:  "channel, c",
			Usage: "Slack channel or group to post to",
		},
		cli.StringFlag{
			Name:  "filename, n",
			Usage: "Filename for upload. Defaults to current timestamp",
		},
	}

	app.Action = func(c *cli.Context) {
		var filePath string
		var fileName string

		if c.Bool("configure") {
			configureOA()
		}

		token := readConfig()
		api := slack.New(token)

		if c.String("channel") == "" {
			exit(fmt.Errorf("no channel provided!"))
		}

		channelId, err := lookupSlackId(api, c.String("channel"))
		failOnError(err, "", true)

		if len(c.Args()) > 0 {
			filePath = c.Args()[0]
			fileName = filepath.Base(filePath)
		} else {
			lines := make(chan string)
			go readIn(lines, c.Bool("tee"))
			filePath = writeTemp(lines)
			fileName = strconv.FormatInt(time.Now().Unix(), 10)
			defer os.Remove(filePath)
		}

		//override default filename with provided option value
		if c.String("filename") != "" {
			fileName = c.String("filename")
		}

		if c.Bool("noop") {
			output(fmt.Sprintf("skipping upload of file %s to %s", fileName, c.String("channel")))
		} else {
			start := time.Now()
			err = api.FilesUpload(&slack.FilesUploadOpt{
				Filepath: filePath,
				Filename: fileName,
				Title:    fileName,
				Channels: []string{channelId},
			})
			failOnError(err, "error uploading file to Slack", true)
			duration := strconv.FormatFloat(time.Since(start).Seconds(), 'f', 3, 64)
			output(fmt.Sprintf("file %s uploaded to %s (%ss)", fileName, c.String("channel"), duration))
		}
	}

	app.Run(os.Args)

}