Skip to content

Commit

Permalink
fix(integration-discord): single message structure
Browse files Browse the repository at this point in the history
  • Loading branch information
captainark committed Jan 4, 2025
1 parent 4ebd7de commit 00dd0cb
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions internal/integration/discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
)

const defaultClientTimeout = 10 * time.Second
const discordMsgColor = 5793266

type Client struct {
webhookURL string
Expand All @@ -30,18 +31,15 @@ func NewClient(webhookURL string) *Client {
func (c *Client) SendDiscordMsg(feed *model.Feed, entries model.Entries) error {

for _, entry := range entries {

footerText := entry.Author + " " + "•" + " " + "Miniflux/" +version.Version

requestBody, err := json.Marshal(&discordMessage{
Embeds: []discordEmbed{
Embeds: []{
{
Title: entry.Title,
Url: entry.URL,
Description: feed.Title,
Color: 5793266,
Footer: &discordFooter{
Text: footerText,
Color: discordMsgColor,
Footer: {
Text: entry.Author + " " + "•" + " " + "Miniflux/" +version.Version,
IconUrl: feed.IconURL,
},
},
Expand Down Expand Up @@ -80,22 +78,15 @@ func (c *Client) SendDiscordMsg(feed *model.Feed, entries model.Entries) error {
return nil
}

type discordFooter struct {
Text string `json:"text,omitempty"`
IconUrl string `json:"icon_url,omitempty"`
}

type discordEmbed struct {
Title string `json:"title,omitempty"`
Url string `json:"url,omitempty"`
Description string `json:"description,omitempty"`
Color int `json:"color,omitempty"`
Footer *discordFooter `json:"footer,omitempty"`
}

type discordMessage struct {
Username string `json:"username,omitempty"`
AvatarUrl string `json:"avatar_url,omitempty"`
Content string `json:"content,omitempty"`
Embeds []discordEmbed `json:"embeds,omitempty"`
[]Embeds struct {
Title string `json:"title,omitempty"`
Url string `json:"url,omitempty"`
Description string `json:"description,omitempty"`
Color int `json:"color,omitempty"`
Footer struct {
Text string `json:"text,omitempty"`
IconUrl string `json:"icon_url,omitempty"`
} `json:"footer,omitempty"`
} `json:"embeds,omitempty"`
}

0 comments on commit 00dd0cb

Please sign in to comment.