示例#1
0
func setupTelegram() {
	var err error
	log.Error("Instance bot initialized! Using token:", configuration.C.Actions.Telegram.Bot)
	bot, err = golegram.NewBot(configuration.C.Actions.Telegram.Bot)
	if err != nil {
		log.Error("[Telegram] Init error")
		log.Error(err)
	}
}
示例#2
0
func processWebhook(wh Webhook) {

	bot, _ := golegram.NewBot(config.Bottoken)
	//our beautiful git push sticker
	// nope
	//bot.SendSticker(userID, "BQADBAADjgEAAlIvPQAB7_h8b5RYj3sC")
	gitSystem := "gogs"

	if len(wh.Repository.Full_name) > 0 {
		gitSystem = "github"
	}

	var fullRepo string

	if gitSystem == "github" {
		fullRepo = wh.Repository.Full_name
	} else {
		fullRepo = wh.Repository.Owner.Username + "/" + wh.Repository.Name
	}

	for _, repo := range config.Repositories {

		if repo.Clone_url != wh.Repository.Clone_url {
			continue
		}
		branch := strings.Replace(wh.Ref, "refs/heads/", "", -1) //doe iets wegstrippen later

		announceMsg := "⬆️ " + wh.Pusher.Name + " pushed to _" + branch + "_ of _" + fullRepo + "_"

		_, _ = bot.SendMessage(repo.Telegramtarget, announceMsg)

		for _, commit := range wh.Commits { //for each commit in our received json, show a seperate message
			msg := "➕ [" + commit.Message + "](" + commit.Url + ")\n"
			msg += "👤 " + commit.Author.Name
			msg += ""
			_, _ = bot.SendMessage(repo.Telegramtarget, msg)
		}
	}
}