mirror of
https://github.com/miniflux/v2.git
synced 2025-07-17 17:08:36 +00:00
Add Notion integration
This commit is contained in:
parent
06c37a132f
commit
bfb4fc1c36
28 changed files with 229 additions and 6 deletions
|
@ -9,6 +9,7 @@ import (
|
|||
"miniflux.app/integration/instapaper"
|
||||
"miniflux.app/integration/linkding"
|
||||
"miniflux.app/integration/matrixbot"
|
||||
"miniflux.app/integration/notion"
|
||||
"miniflux.app/integration/nunuxkeeper"
|
||||
"miniflux.app/integration/pinboard"
|
||||
"miniflux.app/integration/pocket"
|
||||
|
@ -62,6 +63,18 @@ func SendEntry(entry *model.Entry, integration *model.Integration) {
|
|||
}
|
||||
}
|
||||
|
||||
if integration.NotionEnabled {
|
||||
logger.Debug("[Integration] Sending Entry #%d %q for User #%d to Notion", entry.ID, entry.URL, integration.UserID)
|
||||
|
||||
client := notion.NewClient(
|
||||
integration.NotionToken,
|
||||
integration.NotionPageID,
|
||||
)
|
||||
if err := client.AddEntry(entry.URL, entry.Title); err != nil {
|
||||
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
|
||||
}
|
||||
}
|
||||
|
||||
if integration.NunuxKeeperEnabled {
|
||||
logger.Debug("[Integration] Sending Entry #%d %q for User #%d to NunuxKeeper", entry.ID, entry.URL, integration.UserID)
|
||||
|
||||
|
|
54
integration/notion/notion.go
Normal file
54
integration/notion/notion.go
Normal file
|
@ -0,0 +1,54 @@
|
|||
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package notion
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"miniflux.app/http/client"
|
||||
)
|
||||
|
||||
// Client represents a Notion client.
|
||||
type Client struct {
|
||||
token string
|
||||
pageID string
|
||||
}
|
||||
|
||||
// NewClient returns a new Notion client.
|
||||
func NewClient(token, pageID string) *Client {
|
||||
return &Client{token, pageID}
|
||||
}
|
||||
|
||||
func (c *Client) AddEntry(entryURL string, entryTitle string) error {
|
||||
if c.token == "" || c.pageID == "" {
|
||||
return fmt.Errorf("notion: missing credentials")
|
||||
}
|
||||
clt := client.New("https://api.notion.com/v1/blocks/" + c.pageID + "/children")
|
||||
block := &Data{
|
||||
Children: []Block{
|
||||
{
|
||||
Object: "block",
|
||||
Type: "bookmark",
|
||||
Bookmark: Bookmark{
|
||||
Caption: []interface{}{},
|
||||
URL: entryURL,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
clt.WithAuthorization("Bearer " + c.token)
|
||||
customHeaders := map[string]string{
|
||||
"Notion-Version": "2022-06-28",
|
||||
}
|
||||
clt.WithCustomHeaders(customHeaders)
|
||||
response, error := clt.PatchJSON(block)
|
||||
if error != nil {
|
||||
return fmt.Errorf("notion: unable to patch entry: %v", error)
|
||||
}
|
||||
|
||||
if response.HasServerFailure() {
|
||||
return fmt.Errorf("notion: request failed, status=%d", response.StatusCode)
|
||||
}
|
||||
return nil
|
||||
}
|
19
integration/notion/wrapper.go
Normal file
19
integration/notion/wrapper.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package notion
|
||||
|
||||
type Data struct {
|
||||
Children []Block `json:"children"`
|
||||
}
|
||||
|
||||
type Block struct {
|
||||
Object string `json:"object"`
|
||||
Type string `json:"type"`
|
||||
Bookmark Bookmark `json:"bookmark"`
|
||||
}
|
||||
|
||||
type Bookmark struct {
|
||||
Caption []interface{} `json:"caption"` // Assuming the "caption" field can have different types
|
||||
URL string `json:"url"`
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue