Skip to content

Commit

Permalink
ci: Bump version. v4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Rishats committed Mar 11, 2021
1 parent 4a991a8 commit 695778b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
5 changes: 3 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ services:
container_name: notifyer-ci
build: ./
environment:
NOTIFYER_TELEGRAM_BOT_TOKEN: "your_token"
NOTIFYER_TELEGRAM_BOT_TOKEN: ""
CI_PROJECT_URL: ""
CI_PIPELINE_ID: ""
CI_COMMIT_REF_SLUG: ""
NOTIFYER_TELEGRAM_CHAT_ID:
NOTIFYER_TEXT: "Release ready!"
command: notifyer -t "TEXT" release ready
NOTIFYER_TELEGRAM_PARSE_MODE: "HTML"
command: notifyer --text "<pre>Release done</pre><pre>pre-formatted</pre>" --telegram_parse_mode "HTML" deploy done
14 changes: 11 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func main() {
var telegramBotToken, ciProjectUrl, ciPipelineId, ciCommitSlug, text string
var telegramBotToken, telegramParseMode, ciProjectUrl, ciPipelineId, ciCommitSlug, text string
var telegramChatId int

app := &cli.App{
Expand Down Expand Up @@ -52,6 +52,14 @@ func main() {
EnvVars: []string{"NOTIFYER_TELEGRAM_CHAT_ID"},
Destination: &telegramChatId,
},
&cli.StringFlag{
Name: "telegram_parse_mode",
Aliases: []string{"tpm"},
Usage: "TELEGRAM_PARSE_MODE - Telegram",
EnvVars: []string{"NOTIFYER_TELEGRAM_PARSE_MODE"},
DefaultText: "HTML",
Destination: &telegramParseMode,
},
&cli.StringFlag{
Name: "text",
Aliases: []string{"t"},
Expand All @@ -71,7 +79,7 @@ func main() {
Usage: "release ready",
Action: func(c *cli.Context) error {
fmt.Println("[Notifyer] Release ready")
sendTextToTelegramChat(telegramChatId, text, telegramBotToken)
sendTextToTelegramChat(telegramChatId, text, telegramBotToken, telegramParseMode)
return nil
},
},
Expand All @@ -87,7 +95,7 @@ func main() {
Usage: "deploy done",
Action: func(c *cli.Context) error {
fmt.Println("[Notifyer] Deploy done")
sendTextToTelegramChat(telegramChatId, text, telegramBotToken)
sendTextToTelegramChat(telegramChatId, text, telegramBotToken, telegramParseMode)
return nil
},
},
Expand Down
9 changes: 5 additions & 4 deletions sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ import (
)

// sendTextToTelegramChat sends a text message to the Telegram chat identified by its chat Id
func sendTextToTelegramChat(chatId int, text string, telegramBotToken string, ) (string, error) {
func sendTextToTelegramChat(chatId int, text string, telegramBotToken string, telegramParseMode string) (string, error) {

log.Printf("Sending %s to chat_id: %d", text, chatId)
var telegramApi string = "https://api.telegram.org/bot" + telegramBotToken + "/sendMessage"
response, err := http.PostForm(
telegramApi,
url.Values{
"chat_id": {strconv.Itoa(chatId)},
"text": {text},
"chat_id": {strconv.Itoa(chatId)},
"text": {text},
"parse_mode": {telegramParseMode},
})

if err != nil {
Expand All @@ -35,4 +36,4 @@ func sendTextToTelegramChat(chatId int, text string, telegramBotToken string, )
log.Printf("Body of Telegram Response: %s", bodyString)

return bodyString, nil
}
}

0 comments on commit 695778b

Please sign in to comment.