Skip to content

Commit

Permalink
feat(outgoing-webhook): add href property to generic webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
ncarlier committed Nov 14, 2022
1 parent 802a120 commit b772f33
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ By default, the article is sent as a JSON with the following format:

```json
{
"href": "article URL on readflow",
"title": "The title",
"text": "Text content (the summary)",
"html": "HTML content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Par défaut, l'article est envoyé en JSON selon le format suivant:

```json
{
"href": "L'URL de l'article sur readflow",
"title": "Le titre",
"text": "Le text de l'article (le résumé)",
"html": "Le contenu HTML de l'article",
Expand Down
13 changes: 9 additions & 4 deletions pkg/integration/webhook/generic/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"net/http"
"net/url"
"strings"
"text/template"
"time"

Expand All @@ -31,6 +32,7 @@ func isValidContentType(contentType string) bool {

// webhookArticle is the structure definition of a generic Webhook article
type webhookArticle struct {
Href string `json:"href,omitempty"`
Title string `json:"title,omitempty"`
Text *string `json:"text,omitempty"`
HTML *string `json:"html,omitempty"`
Expand All @@ -49,8 +51,9 @@ type ProviderConfig struct {

// Provider is the structure definition of a Webhook outbound service
type Provider struct {
config ProviderConfig
tpl *template.Template
config ProviderConfig
tpl *template.Template
hrefBase string
}

func newWebhookProvider(srv model.OutgoingWebhook, conf config.Config) (webhook.Provider, error) {
Expand Down Expand Up @@ -81,8 +84,9 @@ func newWebhookProvider(srv model.OutgoingWebhook, conf config.Config) (webhook.
}

provider := &Provider{
config: config,
tpl: tpl,
config: config,
tpl: tpl,
hrefBase: strings.Replace(conf.Global.PublicURL, "api.", "", 1),
}

return provider, nil
Expand All @@ -91,6 +95,7 @@ func newWebhookProvider(srv model.OutgoingWebhook, conf config.Config) (webhook.
// Send article to Webhook endpoint.
func (whp *Provider) Send(ctx context.Context, article model.Article) error {
art := webhookArticle{
Href: fmt.Sprintf("%s/inbox/%d", whp.hrefBase, article.ID),
Title: article.Title,
Text: article.Text,
HTML: article.HTML,
Expand Down

0 comments on commit b772f33

Please sign in to comment.