diff --git a/README.md b/README.md index 0e1f931..32102e0 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ This client implements all NewReleases API features. - Get project release note - Get tracked providers - Get added Slack Channels +- Get added Telegram Chats - Get added Hangouts Chat webhooks - Get added Microsoft Teams webhooks - Get added custom Webhooks diff --git a/newreleases.go b/newreleases.go index 2ca763c..1721e94 100644 --- a/newreleases.go +++ b/newreleases.go @@ -43,6 +43,7 @@ type Client struct { Projects *ProjectsService Releases *ReleasesService SlackChannels *SlackChannelsService + TelegramChats *TelegramChatsService HangoutsChatWebhooks *HangoutsChatWebhooksService MicrosoftTeamsWebhooks *MicrosoftTeamsWebhooksService Webhooks *WebhooksService @@ -85,6 +86,7 @@ func newClient(httpClient *http.Client) (c *Client) { c.Projects = (*ProjectsService)(&c.service) c.Releases = (*ReleasesService)(&c.service) c.SlackChannels = (*SlackChannelsService)(&c.service) + c.TelegramChats = (*TelegramChatsService)(&c.service) c.HangoutsChatWebhooks = (*HangoutsChatWebhooksService)(&c.service) c.MicrosoftTeamsWebhooks = (*MicrosoftTeamsWebhooksService)(&c.service) c.Webhooks = (*WebhooksService)(&c.service) diff --git a/projects.go b/projects.go index 7a8d946..d383c4b 100644 --- a/projects.go +++ b/projects.go @@ -24,6 +24,7 @@ type Project struct { URL string `json:"url"` EmailNotification EmailNotification `json:"email_notification,omitempty"` SlackIDs []string `json:"slack_channels,omitempty"` + TelegramChatIDs []string `json:"telegram_chats,omitempty"` HangoutsChatWebhookIDs []string `json:"hangouts_chat_webhooks,omitempty"` MSTeamsWebhookIDs []string `json:"microsoft_teams_webhooks,omitempty"` WebhookIDs []string `json:"webhooks,omitempty"` @@ -146,6 +147,7 @@ func (s *ProjectsService) get(ctx context.Context, projectRef string) (project * type ProjectOptions struct { EmailNotification *EmailNotification `json:"email_notification"` SlackIDs []string `json:"slack_channels"` + TelegramChatIDs []string `json:"telegram_chats"` HangoutsChatWebhookIDs []string `json:"hangouts_chat_webhooks"` MSTeamsWebhookIDs []string `json:"microsoft_teams_webhooks"` WebhookIDs []string `json:"webhooks"` diff --git a/projects_test.go b/projects_test.go index 5ddbc62..f099f5e 100644 --- a/projects_test.go +++ b/projects_test.go @@ -404,6 +404,7 @@ var ( Provider: "github", EmailNotification: newreleases.EmailNotificationHourly, SlackIDs: []string{"slack123"}, + TelegramChatIDs: []string{"telegram123"}, HangoutsChatWebhookIDs: []string{"hangouts123"}, MSTeamsWebhookIDs: []string{"teams123"}, WebhookIDs: []string{"webhook123", "webhook124"}, @@ -414,6 +415,7 @@ var ( projectOptions = &newreleases.ProjectOptions{ EmailNotification: &newreleases.EmailNotificationHourly, SlackIDs: []string{"slack123"}, + TelegramChatIDs: []string{"telegram123"}, HangoutsChatWebhookIDs: []string{"hangouts123"}, MSTeamsWebhookIDs: []string{"teams123"}, WebhookIDs: []string{"webhook123", "webhook124"}, diff --git a/telegram_chats.go b/telegram_chats.go new file mode 100644 index 0000000..ec8c7cb --- /dev/null +++ b/telegram_chats.go @@ -0,0 +1,34 @@ +// Copyright (c) 2019, NewReleases Go client AUTHORS. +// All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package newreleases + +import ( + "context" + "net/http" +) + +// TelegramChatsService provides information about Telegram notifications. +type TelegramChatsService service + +// TelegramChat holds information about a Telegram Chat which receives +// notifications. +type TelegramChat struct { + ID string `json:"id"` + Type string `json:"type"` + Name string `json:"name"` +} + +// List returns all connected Slack Channels. +func (s *TelegramChatsService) List(ctx context.Context) (channels []TelegramChat, err error) { + + type TelegramChatsResponse struct { + Chats []TelegramChat `json:"chats"` + } + + var r TelegramChatsResponse + err = s.client.request(ctx, http.MethodGet, "v1/telegram-chats", nil, &r) + return r.Chats, err +} diff --git a/telegram_chats_test.go b/telegram_chats_test.go new file mode 100644 index 0000000..c33d83c --- /dev/null +++ b/telegram_chats_test.go @@ -0,0 +1,53 @@ +// Copyright (c) 2019, NewReleases Go client AUTHORS. +// All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package newreleases_test + +import ( + "context" + "fmt" + "net/http" + "testing" + + "newreleases.io/newreleases" +) + +func TestTelegramChatsService_List(t *testing.T) { + client, mux, _, teardown := newClient(t, "") + defer teardown() + + mux.HandleFunc("/v1/telegram-chats", requireMethod("GET", func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", jsonContentType) + fmt.Fprintln(w, telegramChatsServiceList) + })) + + got, err := client.TelegramChats.List(context.Background()) + if err != nil { + t.Fatal(err) + } + + assertEqual(t, "", got, telegramChatsServiceListWant) +} + +var ( + telegramChatsServiceList = ` + { + "chats": [ + { + "id": "00q3pe8gf7322d8n52bgrl551", + "type": "group", + "name": "My Telegram Chat" + } + ] + } + ` + telegramChatsServiceListWant = []newreleases.TelegramChat{ + { + ID: "00q3pe8gf7322d8n52bgrl551", + Type: "group", + Name: "My Telegram Chat", + }, + } +)