docs integrations notion (#1951)
- docs: add Notion Setup instructions - docs: Notion Add Content to Page instructions - docs: Notion List Database Properties instructions - docs: Notion List Pages instructions - docs: Notion Page Viewer instructions - docs: Notion Page Create instructions - docs: Notion User Lists instructions - docs: Notion Page Update instructions
138
docs/docs/integrations/notion/add-content-to-page.md
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
import Admonition from "@theme/Admonition";
|
||||
import ThemedImage from "@theme/ThemedImage";
|
||||
import useBaseUrl from "@docusaurus/useBaseUrl";
|
||||
import ZoomableImage from "/src/theme/ZoomableImage.js";
|
||||
|
||||
# Add Content To Page
|
||||
|
||||
The `AddContentToPage` component converts markdown text to Notion blocks and appends them to a Notion page.
|
||||
|
||||
[Notion Reference](https://developers.notion.com/reference/patch-block-children)
|
||||
|
||||
<Admonition type="tip" title="Component Functionality">
|
||||
|
||||
The `AddContentToPage` component enables you to:
|
||||
|
||||
- Convert markdown text to Notion blocks.
|
||||
- Append the converted blocks to a specified Notion page.
|
||||
- Seamlessly integrate Notion content creation into Langflow workflows.
|
||||
</Admonition>
|
||||
|
||||
## Component Usage
|
||||
|
||||
To use the `AddContentToPage` component in a Langflow flow:
|
||||
|
||||
1. **Add the `AddContentToPage` component** to your flow.
|
||||
2. **Configure the component** by providing:
|
||||
- `markdown_text`: The markdown text to convert.
|
||||
- `block_id`: The ID of the Notion page/block to append the content.
|
||||
- `notion_secret`: The Notion integration token for authentication.
|
||||
3. **Connect the component** to other nodes in your flow as needed.
|
||||
4. **Run the flow** to convert the markdown text and append it to the specified Notion page.
|
||||
|
||||
## Component Python Code
|
||||
|
||||
```python
|
||||
import json
|
||||
from typing import Optional
|
||||
|
||||
import requests
|
||||
from langflow.custom import CustomComponent
|
||||
|
||||
|
||||
class NotionPageCreator(CustomComponent):
|
||||
display_name = "Create Page [Notion]"
|
||||
description = "A component for creating Notion pages."
|
||||
documentation: str = "https://docs.langflow.org/integrations/notion/add-content-to-page"
|
||||
icon = "NotionDirectoryLoader"
|
||||
|
||||
def build_config(self):
|
||||
return {
|
||||
"database_id": {
|
||||
"display_name": "Database ID",
|
||||
"field_type": "str",
|
||||
"info": "The ID of the Notion database.",
|
||||
},
|
||||
"notion_secret": {
|
||||
"display_name": "Notion Secret",
|
||||
"field_type": "str",
|
||||
"info": "The Notion integration token.",
|
||||
"password": True,
|
||||
},
|
||||
"properties": {
|
||||
"display_name": "Properties",
|
||||
"field_type": "str",
|
||||
"info": "The properties of the new page. Depending on your database setup, this can change. E.G: {'Task name': {'id': 'title', 'type': 'title', 'title': [{'type': 'text', 'text': {'content': 'Send Notion Components to LF', 'link': null}}]}}",
|
||||
},
|
||||
}
|
||||
|
||||
def build(
|
||||
self,
|
||||
database_id: str,
|
||||
notion_secret: str,
|
||||
properties: str = '{"Task name": {"id": "title", "type": "title", "title": [{"type": "text", "text": {"content": "Send Notion Components to LF", "link": null}}]}}',
|
||||
) -> str:
|
||||
if not database_id or not properties:
|
||||
raise ValueError("Invalid input. Please provide 'database_id' and 'properties'.")
|
||||
|
||||
headers = {
|
||||
"Authorization": f"Bearer {notion_secret}",
|
||||
"Content-Type": "application/json",
|
||||
"Notion-Version": "2022-06-28",
|
||||
}
|
||||
|
||||
data = {
|
||||
"parent": {"database_id": database_id},
|
||||
"properties": json.loads(properties),
|
||||
}
|
||||
|
||||
response = requests.post("https://api.notion.com/v1/pages", headers=headers, json=data)
|
||||
|
||||
if response.status_code == 200:
|
||||
page_id = response.json()["id"]
|
||||
self.status = f"Successfully created Notion page with ID: {page_id}\n {str(response.json())}"
|
||||
return response.json()
|
||||
else:
|
||||
error_message = f"Failed to create Notion page. Status code: {response.status_code}, Error: {response.text}"
|
||||
self.status = error_message
|
||||
raise Exception(error_message)
|
||||
```
|
||||
|
||||
## Example Usage
|
||||
|
||||
<Admonition type="info" title="Example Usage">
|
||||
|
||||
Example of using the `AddContentToPage` component in a Langflow flow using Markdown as input:
|
||||
|
||||
<ZoomableImage
|
||||
alt="NotionDatabaseProperties Flow Example"
|
||||
sources={{
|
||||
light: "img/notion/AddContentToPage_flow_example.png",
|
||||
dark: "img/notion/AddContentToPage_flow_example.png",
|
||||
}}
|
||||
style={{ width: "100%", margin: "20px 0" }}
|
||||
/>
|
||||
|
||||
In this example, the `AddContentToPage` component connects to a `MarkdownLoader` component to provide the markdown text input. The converted Notion blocks are appended to the specified Notion page using the provided `block_id` and `notion_secret`.
|
||||
|
||||
</Admonition>
|
||||
|
||||
## Best Practices
|
||||
|
||||
When using the `AddContentToPage` component:
|
||||
|
||||
- Ensure markdown text is well-formatted.
|
||||
- Verify the `block_id` corresponds to the right Notion page/block.
|
||||
- Keep your Notion integration token secure.
|
||||
- Test with sample markdown text before production use.
|
||||
|
||||
The `AddContentToPage` component is a powerful tool for integrating Notion content creation into Langflow workflows, facilitating easy conversion of markdown text to Notion blocks and appending them to specific pages.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
If you encounter any issues while using the `AddContentToPage` component, consider the following:
|
||||
- Verify the Notion integration token’s validity and permissions.
|
||||
- Check the Notion API documentation for updates.
|
||||
- Ensure markdown text is properly formatted.
|
||||
- Double-check the `block_id` for correctness.
|
||||
|
||||
43
docs/docs/integrations/notion/intro.md
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import Admonition from "@theme/Admonition";
|
||||
import ThemedImage from "@theme/ThemedImage";
|
||||
import useBaseUrl from "@docusaurus/useBaseUrl";
|
||||
import ZoomableImage from "/src/theme/ZoomableImage.js";
|
||||
|
||||
# Introduction to Notion in Langflow
|
||||
|
||||
The Notion integration in Langflow enables seamless connectivity with Notion databases, pages, and users, facilitating automation and improving productivity.
|
||||
|
||||
<ZoomableImage
|
||||
alt="Notion Components in Langflow"
|
||||
sources={{
|
||||
light: "img/notion/notion_components_bundle.png",
|
||||
dark: "img/notion/notion_components_bundle_dark.png",
|
||||
}}
|
||||
style={{ width: "100%", margin: "20px 0" }}
|
||||
/>
|
||||
|
||||
#### <a target="\_blank" href="json_files/Notion_Components_bundle.json" download>Download Notion Components Bundle</a>
|
||||
|
||||
### Key Features of Notion Integration in Langflow
|
||||
|
||||
- **List Pages**: Retrieve a list of pages from a Notion database and access data stored in your Notion workspace.
|
||||
- **List Database Properties**: Obtain insights into the properties of a Notion database, allowing for easy understanding of its structure and metadata.
|
||||
- **Add Page Content**: Programmatically add new content to a Notion page, simplifying the creation and updating of pages.
|
||||
- **List Users**: Retrieve a list of users with access to a Notion workspace, aiding in user management and collaboration.
|
||||
- **Update Property**: Update the value of a specific property in a Notion page, enabling easy modification and maintenance of Notion data.
|
||||
|
||||
### Potential Use Cases for Notion Integration in Langflow
|
||||
|
||||
- **Task Automation**: Automate task creation in Notion using Langflow's AI capabilities. Describe the required tasks, and they will be automatically created and updated in Notion.
|
||||
- **Context Extraction from Meetings**: Leverage AI to analyze meeting contexts, extract key points, and update the relevant Notion pages automatically.
|
||||
- **Content Creation**: Utilize AI to generate ideas, suggest templates, and populate Notion pages with relevant data, enhancing content management efficiency.
|
||||
|
||||
### Getting Started with Notion Integration in Langflow
|
||||
|
||||
1. **Set Up Notion Integration**: Follow the guide [Setting up a Notion App](./setup) to set up a Notion integration in your workspace.
|
||||
2. **Configure Notion Components**: Provide the necessary authentication details and parameters to configure the Notion components in your Langflow flows.
|
||||
3. **Connect Components**: Integrate Notion components with other Langflow components to build your workflow.
|
||||
4. **Test and Refine**: Ensure your Langflow flow operates as intended by testing and refining it.
|
||||
5. **Deploy and Run**: Deploy your Langflow flow to automate Notion-related tasks and processes.
|
||||
|
||||
The Notion integration in Langflow offers a powerful toolset for automation and productivity enhancement. Whether managing tasks, extracting meeting insights, or creating content, Langflow and Notion provide robust solutions for streamlining workflows.
|
||||
115
docs/docs/integrations/notion/list-database-properties.md
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
import Admonition from "@theme/Admonition";
|
||||
import ThemedImage from "@theme/ThemedImage";
|
||||
import useBaseUrl from "@docusaurus/useBaseUrl";
|
||||
import ZoomableImage from "/src/theme/ZoomableImage.js";
|
||||
|
||||
# Database Properties
|
||||
|
||||
The `NotionDatabaseProperties` component retrieves properties of a Notion database. It provides a convenient way to integrate Notion database information into your Langflow workflows.
|
||||
|
||||
[Notion Reference](https://developers.notion.com/reference/post-database-query)
|
||||
|
||||
<Admonition type="tip" title="Component Functionality">
|
||||
The `NotionDatabaseProperties` component enables you to:
|
||||
- Retrieve properties of a Notion database
|
||||
- Access the retrieved properties in your Langflow flows
|
||||
- Integrate Notion database information seamlessly into your workflows
|
||||
</Admonition>
|
||||
|
||||
## Component Usage
|
||||
|
||||
To use the `NotionDatabaseProperties` component in a Langflow flow, follow these steps:
|
||||
|
||||
1. Add the `NotionDatabaseProperties` component to your flow.
|
||||
2. Configure the component by providing the required inputs:
|
||||
- `database_id`: The ID of the Notion database you want to retrieve properties from.
|
||||
- `notion_secret`: The Notion integration token for authentication.
|
||||
3. Connect the output of the `NotionDatabaseProperties` component to other components in your flow as needed.
|
||||
|
||||
## Component Python code
|
||||
|
||||
```python
|
||||
import requests
|
||||
from typing import Dict
|
||||
|
||||
from langflow import CustomComponent
|
||||
from langflow.schema import Record
|
||||
|
||||
|
||||
class NotionDatabaseProperties(CustomComponent):
|
||||
display_name = "List Database Properties [Notion]"
|
||||
description = "Retrieve properties of a Notion database."
|
||||
documentation: str = "https://docs.langflow.org/integrations/notion/list-database-properties"
|
||||
icon = "NotionDirectoryLoader"
|
||||
|
||||
def build_config(self):
|
||||
return {
|
||||
"database_id": {
|
||||
"display_name": "Database ID",
|
||||
"field_type": "str",
|
||||
"info": "The ID of the Notion database.",
|
||||
},
|
||||
"notion_secret": {
|
||||
"display_name": "Notion Secret",
|
||||
"field_type": "str",
|
||||
"info": "The Notion integration token.",
|
||||
"password": True,
|
||||
},
|
||||
}
|
||||
|
||||
def build(
|
||||
self,
|
||||
database_id: str,
|
||||
notion_secret: str,
|
||||
) -> Record:
|
||||
url = f"https://api.notion.com/v1/databases/{database_id}"
|
||||
headers = {
|
||||
"Authorization": f"Bearer {notion_secret}",
|
||||
"Notion-Version": "2022-06-28", # Use the latest supported version
|
||||
}
|
||||
|
||||
response = requests.get(url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
data = response.json()
|
||||
properties = data.get("properties", {})
|
||||
|
||||
record = Record(text=str(response.json()), data=properties)
|
||||
self.status = f"Retrieved {len(properties)} properties from the Notion database.\n {record.text}"
|
||||
return record
|
||||
```
|
||||
|
||||
## Example Usage
|
||||
<Admonition type="info" title="Example Usage">
|
||||
Here's an example of how you can use the `NotionDatabaseProperties` component in a Langflow flow:
|
||||
|
||||
<ZoomableImage
|
||||
alt="NotionDatabaseProperties Flow Example"
|
||||
sources={{
|
||||
light: "img/notion/NotionDatabaseProperties_flow_example.png",
|
||||
dark: "img/notion/NotionDatabaseProperties_flow_example_dark.png",
|
||||
}}
|
||||
style={{ width: "100%", margin: "20px 0" }}
|
||||
/>
|
||||
|
||||
In this example, the `NotionDatabaseProperties` component retrieves the properties of a Notion database, and the retrieved properties are then used as input for subsequent components in the flow.
|
||||
</Admonition>
|
||||
|
||||
## Best Practices
|
||||
|
||||
When using the `NotionDatabaseProperties` component, consider the following best practices:
|
||||
|
||||
- Ensure that you have a valid Notion integration token with the necessary permissions to access the desired database.
|
||||
- Double-check the database ID to avoid retrieving properties from the wrong database.
|
||||
- Handle potential errors gracefully by checking the response status and providing appropriate error messages.
|
||||
|
||||
The `NotionDatabaseProperties` component simplifies the process of retrieving properties from a Notion database and integrating them into your Langflow workflows. By leveraging this component, you can easily access and utilize Notion database information in your flows, enabling powerful integrations and automations.
|
||||
|
||||
Feel free to explore the capabilities of the `NotionDatabaseProperties` component and experiment with different use cases to enhance your Langflow workflows!
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
If you encounter any issues while using the `NotionDatabaseProperties` component, consider the following:
|
||||
- Verify that the Notion integration token is valid and has the required permissions.
|
||||
- Check the database ID to ensure it matches the intended Notion database.
|
||||
- Inspect the response from the Notion API for any error messages or status codes that may indicate the cause of the issue.
|
||||
178
docs/docs/integrations/notion/list-pages.md
Normal file
|
|
@ -0,0 +1,178 @@
|
|||
import Admonition from "@theme/Admonition";
|
||||
import ThemedImage from "@theme/ThemedImage";
|
||||
import useBaseUrl from "@docusaurus/useBaseUrl";
|
||||
import ZoomableImage from "/src/theme/ZoomableImage.js";
|
||||
|
||||
# List Pages
|
||||
|
||||
The `NotionListPages` component queries a Notion database with filtering and sorting. It provides a convenient way to integrate Notion database querying capabilities into your Langflow workflows.
|
||||
|
||||
[Notion Reference](https://developers.notion.com/reference/post-database-query)
|
||||
|
||||
<Admonition type="tip" title="Component Functionality">
|
||||
The `NotionListPages` component enables you to:
|
||||
|
||||
- Query a Notion database with custom filters and sorting options
|
||||
- Retrieve specific pages from a Notion database based on the provided criteria
|
||||
- Integrate Notion database data seamlessly into your Langflow workflows
|
||||
|
||||
</Admonition>
|
||||
|
||||
## Component Usage
|
||||
|
||||
To use the `NotionListPages
|
||||
` component in a Langflow flow, follow these steps:
|
||||
|
||||
1. **Add the `NotionListPages
|
||||
` component to your flow.**
|
||||
2. **Configure the component by providing the required parameters:**
|
||||
- `notion_secret`: The Notion integration token for authentication.
|
||||
- `database_id`: The ID of the Notion database you want to query.
|
||||
- `query_payload`: A JSON string containing the filters and sorting options for the query.
|
||||
3. **Connect the `NotionListPages
|
||||
` component to other components in your flow as needed.**
|
||||
|
||||
## Component Python code
|
||||
|
||||
```python
|
||||
import requests
|
||||
import json
|
||||
from typing import Dict, Any, List
|
||||
from langflow.custom import CustomComponent
|
||||
from langflow.schema import Record
|
||||
|
||||
class NotionListPages(CustomComponent):
|
||||
display_name = "List Pages [Notion]"
|
||||
description = (
|
||||
"Query a Notion database with filtering and sorting. "
|
||||
"The input should be a JSON string containing the 'filter' and 'sorts' objects. "
|
||||
"Example input:\n"
|
||||
'{"filter": {"property": "Status", "select": {"equals": "Done"}}, "sorts": [{"timestamp": "created_time", "direction": "descending"}]}'
|
||||
)
|
||||
documentation: str = "https://docs.langflow.org/integrations/notion/list-pages"
|
||||
icon = "NotionDirectoryLoader"
|
||||
|
||||
field_order = [
|
||||
"notion_secret",
|
||||
"database_id",
|
||||
"query_payload",
|
||||
]
|
||||
|
||||
def build_config(self):
|
||||
return {
|
||||
"notion_secret": {
|
||||
"display_name": "Notion Secret",
|
||||
"field_type": "str",
|
||||
"info": "The Notion integration token.",
|
||||
"password": True,
|
||||
},
|
||||
"database_id": {
|
||||
"display_name": "Database ID",
|
||||
"field_type": "str",
|
||||
"info": "The ID of the Notion database to query.",
|
||||
},
|
||||
"query_payload": {
|
||||
"display_name": "Database query",
|
||||
"field_type": "str",
|
||||
"info": "A JSON string containing the filters that will be used for querying the database. EG: {'filter': {'property': 'Status', 'status': {'equals': 'In progress'}}}",
|
||||
},
|
||||
}
|
||||
|
||||
def build(
|
||||
self,
|
||||
notion_secret: str,
|
||||
database_id: str,
|
||||
query_payload: str = "{}",
|
||||
) -> List[Record]:
|
||||
try:
|
||||
query_data = json.loads(query_payload)
|
||||
filter_obj = query_data.get("filter")
|
||||
sorts = query_data.get("sorts", [])
|
||||
|
||||
url = f"https://api.notion.com/v1/databases/{database_id}/query"
|
||||
headers = {
|
||||
"Authorization": f"Bearer {notion_secret}",
|
||||
"Content-Type": "application/json",
|
||||
"Notion-Version": "2022-06-28",
|
||||
}
|
||||
|
||||
data = {
|
||||
"sorts": sorts,
|
||||
}
|
||||
|
||||
if filter_obj:
|
||||
data["filter"] = filter_obj
|
||||
|
||||
response = requests.post(url, headers=headers, json=data)
|
||||
response.raise_for_status()
|
||||
|
||||
results = response.json()
|
||||
records = []
|
||||
combined_text = f"Pages found: {len(results['results'])}\n\n"
|
||||
for page in results['results']:
|
||||
page_data = {
|
||||
'id': page['id'],
|
||||
'url': page['url'],
|
||||
'created_time': page['created_time'],
|
||||
'last_edited_time': page['last_edited_time'],
|
||||
'properties': page['properties'],
|
||||
}
|
||||
|
||||
text = (
|
||||
f"id: {page['id']}\n"
|
||||
f"url: {page['url']}\n"
|
||||
f"created_time: {page['created_time']}\n"
|
||||
f"last_edited_time: {page['last_edited_time']}\n"
|
||||
f"properties: {json.dumps(page['properties'], indent=2)}\n\n"
|
||||
)
|
||||
|
||||
combined_text += text
|
||||
records.append(Record(text=text, data=page_data))
|
||||
|
||||
self.status = combined_text.strip()
|
||||
return records
|
||||
|
||||
except Exception as e:
|
||||
self.status = f"An error occurred: {str(e)}"
|
||||
return [Record(text=self.status, data=[])]
|
||||
```
|
||||
|
||||
<Admonition type="info" title="Example Usage">
|
||||
|
||||
## Example Usage
|
||||
Here's an example of how you can use the `NotionListPages` component in a Langflow flow and passing to the Prompt component:
|
||||
|
||||
<ZoomableImage
|
||||
alt="NotionListPages
|
||||
Flow Example"
|
||||
sources={{
|
||||
light: "img/notion/NotionListPages_flow_example.png",
|
||||
dark: "img/notion/NotionListPages_flow_example_dark.png",
|
||||
}}
|
||||
style={{ width: "100%", margin: "20px 0" }}
|
||||
/>
|
||||
|
||||
In this example, the `NotionListPages` component is used to retrieve specific pages from a Notion database based on the provided filters and sorting options. The retrieved data can then be processed further in the subsequent components of the flow.
|
||||
</Admonition>
|
||||
|
||||
## Best Practices
|
||||
|
||||
When using the `NotionListPages
|
||||
` component, consider the following best practices:
|
||||
|
||||
- Ensure that you have a valid Notion integration token with the necessary permissions to query the desired database.
|
||||
- Construct the `query_payload` JSON string carefully, following the Notion API documentation for filtering and sorting options.
|
||||
|
||||
The `NotionListPages
|
||||
` component provides a powerful way to integrate Notion database querying capabilities into your Langflow workflows. By leveraging this component, you can easily retrieve specific pages from a Notion database based on custom filters and sorting options, enabling you to build more dynamic and data-driven flows.
|
||||
|
||||
We encourage you to explore the capabilities of the `NotionListPages
|
||||
` component further and experiment with different querying scenarios to unlock the full potential of integrating Notion databases into your Langflow workflows.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
If you encounter any issues while using the `NotionListPages` component, consider the following:
|
||||
|
||||
- Double-check that the `notion_secret` and `database_id` are correct and valid.
|
||||
- Verify that the `query_payload` JSON string is properly formatted and contains valid filtering and sorting options.
|
||||
- Check the Notion API documentation for any updates or changes that may affect the component's functionality.
|
||||
127
docs/docs/integrations/notion/list-users.md
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
import Admonition from "@theme/Admonition";
|
||||
import ThemedImage from "@theme/ThemedImage";
|
||||
import useBaseUrl from "@docusaurus/useBaseUrl";
|
||||
import ZoomableImage from "/src/theme/ZoomableImage.js";
|
||||
|
||||
# User List
|
||||
|
||||
The `NotionUserList` component retrieves users from Notion. It provides a convenient way to integrate Notion user data into your Langflow workflows.
|
||||
|
||||
[Notion Reference](https://developers.notion.com/reference/get-users)
|
||||
|
||||
<Admonition type="tip" title="Component Functionality">
|
||||
The `NotionUserList` component enables you to:
|
||||
|
||||
- Retrieve user data from Notion
|
||||
- Access user information such as ID, type, name, and avatar URL
|
||||
- Integrate Notion user data seamlessly into your Langflow workflows
|
||||
</Admonition>
|
||||
|
||||
## Component Usage
|
||||
|
||||
To use the `NotionUserList` component in a Langflow flow, follow these steps:
|
||||
|
||||
1. Add the `NotionUserList` component to your flow.
|
||||
2. Configure the component by providing the required Notion secret token.
|
||||
3. Connect the component to other nodes in your flow as needed.
|
||||
|
||||
## Component Python code
|
||||
|
||||
```python
|
||||
import requests
|
||||
from typing import List
|
||||
|
||||
from langflow import CustomComponent
|
||||
from langflow.schema import Record
|
||||
|
||||
|
||||
class NotionUserList(CustomComponent):
|
||||
display_name = "List Users [Notion]"
|
||||
description = "Retrieve users from Notion."
|
||||
documentation: str = "https://docs.langflow.org/integrations/notion/list-users"
|
||||
icon = "NotionDirectoryLoader"
|
||||
|
||||
def build_config(self):
|
||||
return {
|
||||
"notion_secret": {
|
||||
"display_name": "Notion Secret",
|
||||
"field_type": "str",
|
||||
"info": "The Notion integration token.",
|
||||
"password": True,
|
||||
},
|
||||
}
|
||||
|
||||
def build(
|
||||
self,
|
||||
notion_secret: str,
|
||||
) -> List[Record]:
|
||||
url = "https://api.notion.com/v1/users"
|
||||
headers = {
|
||||
"Authorization": f"Bearer {notion_secret}",
|
||||
"Notion-Version": "2022-06-28",
|
||||
}
|
||||
|
||||
response = requests.get(url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
data = response.json()
|
||||
results = data['results']
|
||||
|
||||
records = []
|
||||
for user in results:
|
||||
id = user['id']
|
||||
type = user['type']
|
||||
name = user.get('name', '')
|
||||
avatar_url = user.get('avatar_url', '')
|
||||
|
||||
record_data = {
|
||||
"id": id,
|
||||
"type": type,
|
||||
"name": name,
|
||||
"avatar_url": avatar_url,
|
||||
}
|
||||
|
||||
output = "User:\n"
|
||||
for key, value in record_data.items():
|
||||
output += f"{key.replace('_', ' ').title()}: {value}\n"
|
||||
output += "________________________\n"
|
||||
|
||||
record = Record(text=output, data=record_data)
|
||||
records.append(record)
|
||||
|
||||
self.status = "\n".join(record.text for record in records)
|
||||
return records
|
||||
```
|
||||
|
||||
## Example Usage
|
||||
<Admonition type="info" title="Example Usage">
|
||||
Here's an example of how you can use the `NotionUserList` component in a Langflow flow and passing the outputs to the Prompt component:
|
||||
|
||||
<ZoomableImage
|
||||
alt="NotionUserList Flow Example"
|
||||
sources={{
|
||||
light: "img/notion/NotionUserList_flow_example.png",
|
||||
dark: "img/notion/NotionUserList_flow_example_dark.png",
|
||||
}}
|
||||
style={{ width: "100%", margin: "20px 0" }}
|
||||
/>
|
||||
|
||||
</Admonition>
|
||||
|
||||
## Best Practices
|
||||
|
||||
When using the `NotionUserList` component, consider the following best practices:
|
||||
|
||||
- Ensure that you have a valid Notion integration token with the necessary permissions to retrieve user data.
|
||||
- Handle the retrieved user data securely and in compliance with Notion's API usage guidelines.
|
||||
|
||||
The `NotionUserList` component provides a seamless way to integrate Notion user data into your Langflow workflows. By leveraging this component, you can easily retrieve and utilize user information from Notion, enhancing the capabilities of your Langflow applications. Feel free to explore and experiment with the `NotionUserList` component to unlock new possibilities in your Langflow projects!
|
||||
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
If you encounter any issues while using the `NotionUserList` component, consider the following:
|
||||
|
||||
- Double-check that your Notion integration token is valid and has the required permissions.
|
||||
- Verify that you have installed the necessary dependencies (`requests`) for the component to function properly.
|
||||
- Check the Notion API documentation for any updates or changes that may affect the component's functionality.
|
||||
142
docs/docs/integrations/notion/page-content-viewer.md
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
import Admonition from "@theme/Admonition";
|
||||
import ThemedImage from "@theme/ThemedImage";
|
||||
import useBaseUrl from "@docusaurus/useBaseUrl";
|
||||
import ZoomableImage from "/src/theme/ZoomableImage.js";
|
||||
|
||||
# Page Content
|
||||
|
||||
The `NotionPageContent` component retrieves the content of a Notion page as plain text. It provides a convenient way to integrate Notion page content into your Langflow workflows.
|
||||
|
||||
[Notion Reference](https://developers.notion.com/reference/get-page)
|
||||
|
||||
<Admonition type="tip" title="Component Functionality">
|
||||
|
||||
The `NotionPageContent` component enables you to:
|
||||
|
||||
- Retrieve the content of a Notion page as plain text
|
||||
- Extract text from various block types, including paragraphs, headings, lists, and more
|
||||
- Integrate Notion page content seamlessly into your Langflow workflows
|
||||
|
||||
</Admonition>
|
||||
|
||||
## Component Usage
|
||||
|
||||
To use the `NotionPageContent` component in a Langflow flow, follow these steps:
|
||||
|
||||
1. Add the `NotionPageContent` component to your flow.
|
||||
2. Configure the component by providing the required inputs:
|
||||
- `page_id`: The ID of the Notion page you want to retrieve.
|
||||
- `notion_secret`: Your Notion integration token for authentication.
|
||||
3. Connect the output of the `NotionPageContent` component to other components in your flow as needed.
|
||||
|
||||
## Component Python code
|
||||
|
||||
```python
|
||||
import requests
|
||||
from typing import Dict, Any
|
||||
|
||||
from langflow import CustomComponent
|
||||
from langflow.schema import Record
|
||||
|
||||
|
||||
class NotionPageContent(CustomComponent):
|
||||
display_name = "Page Content Viewer [Notion]"
|
||||
description = "Retrieve the content of a Notion page as plain text."
|
||||
documentation: str = "https://docs.langflow.org/integrations/notion/page-content-viewer"
|
||||
icon = "NotionDirectoryLoader"
|
||||
|
||||
def build_config(self):
|
||||
return {
|
||||
"page_id": {
|
||||
"display_name": "Page ID",
|
||||
"field_type": "str",
|
||||
"info": "The ID of the Notion page to retrieve.",
|
||||
},
|
||||
"notion_secret": {
|
||||
"display_name": "Notion Secret",
|
||||
"field_type": "str",
|
||||
"info": "The Notion integration token.",
|
||||
"password": True,
|
||||
},
|
||||
}
|
||||
|
||||
def build(
|
||||
self,
|
||||
page_id: str,
|
||||
notion_secret: str,
|
||||
) -> Record:
|
||||
blocks_url = f"https://api.notion.com/v1/blocks/{page_id}/children?page_size=100"
|
||||
headers = {
|
||||
"Authorization": f"Bearer {notion_secret}",
|
||||
"Notion-Version": "2022-06-28", # Use the latest supported version
|
||||
}
|
||||
|
||||
# Retrieve the child blocks
|
||||
blocks_response = requests.get(blocks_url, headers=headers)
|
||||
blocks_response.raise_for_status()
|
||||
blocks_data = blocks_response.json()
|
||||
|
||||
# Parse the blocks and extract the content as plain text
|
||||
content = self.parse_blocks(blocks_data["results"])
|
||||
|
||||
self.status = content
|
||||
return Record(data={"content": content}, text=content)
|
||||
|
||||
def parse_blocks(self, blocks: list) -> str:
|
||||
content = ""
|
||||
for block in blocks:
|
||||
block_type = block["type"]
|
||||
if block_type in ["paragraph", "heading_1", "heading_2", "heading_3", "quote"]:
|
||||
content += self.parse_rich_text(block[block_type]["rich_text"]) + "\n\n"
|
||||
elif block_type in ["bulleted_list_item", "numbered_list_item"]:
|
||||
content += self.parse_rich_text(block[block_type]["rich_text"]) + "\n"
|
||||
elif block_type == "to_do":
|
||||
content += self.parse_rich_text(block["to_do"]["rich_text"]) + "\n"
|
||||
elif block_type == "code":
|
||||
content += self.parse_rich_text(block["code"]["rich_text"]) + "\n\n"
|
||||
elif block_type == "image":
|
||||
content += f"[Image: {block['image']['external']['url']}]\n\n"
|
||||
elif block_type == "divider":
|
||||
content += "---\n\n"
|
||||
return content.strip()
|
||||
|
||||
def parse_rich_text(self, rich_text: list) -> str:
|
||||
text = ""
|
||||
for segment in rich_text:
|
||||
text += segment["plain_text"]
|
||||
return text
|
||||
```
|
||||
|
||||
## Example Usage
|
||||
|
||||
<Admonition type="info" title="Example Usage">
|
||||
|
||||
Here's an example of how you can use the `NotionPageContent` component in a Langflow flow:
|
||||
|
||||
<ZoomableImage
|
||||
alt="NotionPageContent Flow Example"
|
||||
sources={{
|
||||
light: "img/notion/NotionPageContent_flow_example.png",
|
||||
dark: "img/notion/NotionPageContent_flow_example_dark.png",
|
||||
}}
|
||||
style={{ width: "100%", margin: "20px 0" }}
|
||||
/>
|
||||
</Admonition>
|
||||
|
||||
## Best Practices
|
||||
|
||||
When using the `NotionPageContent` component, consider the following best practices:
|
||||
|
||||
- Ensure that you have the necessary permissions to access the Notion page you want to retrieve.
|
||||
- Keep your Notion integration token secure and avoid sharing it publicly.
|
||||
- Be mindful of the content you retrieve and ensure that it aligns with your intended use case.
|
||||
|
||||
The `NotionPageContent` component provides a seamless way to integrate Notion page content into your Langflow workflows. By leveraging this component, you can easily retrieve and process the content of Notion pages, enabling you to build powerful and dynamic applications. Explore the capabilities of the `NotionPageContent` component and unlock new possibilities in your Langflow projects!
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
If you encounter any issues while using the `NotionPageContent` component, consider the following:
|
||||
|
||||
- Double-check that you have provided the correct Notion page ID.
|
||||
- Verify that your Notion integration token is valid and has the necessary permissions.
|
||||
- Check the Notion API documentation for any updates or changes that may affect the component's functionality.
|
||||
129
docs/docs/integrations/notion/page-create.md
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
import Admonition from "@theme/Admonition";
|
||||
import ThemedImage from "@theme/ThemedImage";
|
||||
import useBaseUrl from "@docusaurus/useBaseUrl";
|
||||
import ZoomableImage from "/src/theme/ZoomableImage.js";
|
||||
|
||||
# Page Create
|
||||
|
||||
The `NotionPageCreator` component creates pages in a Notion database. It provides a convenient way to integrate Notion page creation into your Langflow workflows.
|
||||
|
||||
[Notion Reference](https://developers.notion.com/reference/patch-block-children)
|
||||
|
||||
<Admonition type="tip" title="Component Functionality">
|
||||
The `NotionPageCreator` component enables you to:
|
||||
- Create new pages in a specified Notion database
|
||||
- Set custom properties for the created pages
|
||||
- Retrieve the ID and URL of the newly created pages
|
||||
</Admonition>
|
||||
|
||||
## Component Usage
|
||||
|
||||
To use the `NotionPageCreator` component in a Langflow flow, follow these steps:
|
||||
|
||||
1. Add the `NotionPageCreator` component to your flow.
|
||||
2. Configure the component by providing the required inputs:
|
||||
- `database_id`: The ID of the Notion database where the pages will be created.
|
||||
- `notion_secret`: The Notion integration token for authentication.
|
||||
- `properties`: The properties of the new page, specified as a JSON string.
|
||||
3. Connect the component to other components in your flow as needed.
|
||||
4. Run the flow to create Notion pages based on the configured inputs.
|
||||
|
||||
## Component Python Code
|
||||
|
||||
```python
|
||||
import json
|
||||
from typing import Optional
|
||||
|
||||
import requests
|
||||
from langflow.custom import CustomComponent
|
||||
|
||||
|
||||
class NotionPageCreator(CustomComponent):
|
||||
display_name = "Create Page [Notion]"
|
||||
description = "A component for creating Notion pages."
|
||||
documentation: str = "https://docs.langflow.org/integrations/notion/page-create"
|
||||
icon = "NotionDirectoryLoader"
|
||||
|
||||
def build_config(self):
|
||||
return {
|
||||
"database_id": {
|
||||
"display_name": "Database ID",
|
||||
"field_type": "str",
|
||||
"info": "The ID of the Notion database.",
|
||||
},
|
||||
"notion_secret": {
|
||||
"display_name": "Notion Secret",
|
||||
"field_type": "str",
|
||||
"info": "The Notion integration token.",
|
||||
"password": True,
|
||||
},
|
||||
"properties": {
|
||||
"display_name": "Properties",
|
||||
"field_type": "str",
|
||||
"info": "The properties of the new page. Depending on your database setup, this can change. E.G: {'Task name': {'id': 'title', 'type': 'title', 'title': [{'type': 'text', 'text': {'content': 'Send Notion Components to LF', 'link': null}}]}}",
|
||||
},
|
||||
}
|
||||
|
||||
def build(
|
||||
self,
|
||||
database_id: str,
|
||||
notion_secret: str,
|
||||
properties: str = '{"Task name": {"id": "title", "type": "title", "title": [{"type": "text", "text": {"content": "Send Notion Components to LF", "link": null}}]}}',
|
||||
) -> str:
|
||||
if not database_id or not properties:
|
||||
raise ValueError("Invalid input. Please provide 'database_id' and 'properties'.")
|
||||
|
||||
headers = {
|
||||
"Authorization": f"Bearer {notion_secret}",
|
||||
"Content-Type": "application/json",
|
||||
"Notion-Version": "2022-06-28",
|
||||
}
|
||||
|
||||
data = {
|
||||
"parent": {"database_id": database_id},
|
||||
"properties": json.loads(properties),
|
||||
}
|
||||
|
||||
response = requests.post("https://api.notion.com/v1/pages", headers=headers, json=data)
|
||||
|
||||
if response.status_code == 200:
|
||||
page_id = response.json()["id"]
|
||||
self.status = f"Successfully created Notion page with ID: {page_id}\n {str(response.json())}"
|
||||
return response.json()
|
||||
else:
|
||||
error_message = f"Failed to create Notion page. Status code: {response.status_code}, Error: {response.text}"
|
||||
self.status = error_message
|
||||
raise Exception(error_message)
|
||||
```
|
||||
|
||||
## Example Usage
|
||||
<Admonition type="info" title="Example Usage">
|
||||
Here's an example of how to use the `NotionPageCreator` component in a Langflow flow:
|
||||
|
||||
<ZoomableImage
|
||||
alt="NotionPageCreator Flow Example"
|
||||
sources={{
|
||||
light: "img/notion/NotionPageCreator_flow_example.png",
|
||||
dark: "img/notion/NotionPageCreator_flow_example_dark.png",
|
||||
}}
|
||||
style={{ width: "100%", margin: "20px 0" }}
|
||||
/>
|
||||
</Admonition>
|
||||
|
||||
## Best Practices
|
||||
|
||||
When using the `NotionPageCreator` component, consider the following best practices:
|
||||
|
||||
- Ensure that you have a valid Notion integration token with the necessary permissions to create pages in the specified database.
|
||||
- Properly format the `properties` input as a JSON string, matching the structure and field types of your Notion database.
|
||||
- Handle any errors or exceptions that may occur during the page creation process and provide appropriate error messages.
|
||||
- To avoid the hassle of messing with JSON, we recommend using the LLM to create the JSON for you as input.
|
||||
|
||||
The `NotionPageCreator` component simplifies the process of creating pages in a Notion database directly from your Langflow workflows. By leveraging this component, you can seamlessly integrate Notion page creation functionality into your automated processes, saving time and effort. Feel free to explore the capabilities of the `NotionPageCreator` component and adapt it to suit your specific requirements.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
If you encounter any issues while using the `NotionPageCreator` component, consider the following:
|
||||
- Double-check that the `database_id` and `notion_secret` inputs are correct and valid.
|
||||
- Verify that the `properties` input is properly formatted as a JSON string and matches the structure of your Notion database.
|
||||
- Check the Notion API documentation for any updates or changes that may affect the component's functionality.
|
||||
139
docs/docs/integrations/notion/page-update.md
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
import Admonition from "@theme/Admonition";
|
||||
import ThemedImage from "@theme/ThemedImage";
|
||||
import useBaseUrl from "@docusaurus/useBaseUrl";
|
||||
import ZoomableImage from "/src/theme/ZoomableImage.js";
|
||||
|
||||
# Page Update
|
||||
|
||||
The `NotionPageUpdate` component updates the properties of a Notion page. It provides a convenient way to integrate updating Notion page properties into your Langflow workflows.
|
||||
|
||||
[Notion Reference](https://developers.notion.com/reference/patch-page)
|
||||
|
||||
## Component Usage
|
||||
|
||||
To use the `NotionPageUpdate` component in your Langflow flow:
|
||||
|
||||
1. Drag and drop the `NotionPageUpdate` component onto the canvas.
|
||||
2. Double-click the component to open its configuration.
|
||||
3. Provide the required parameters as defined in the component's `build_config` method.
|
||||
4. Connect the component to other nodes in your flow as needed.
|
||||
|
||||
## Component Python Code
|
||||
|
||||
```python
|
||||
import json
|
||||
import requests
|
||||
from typing import Dict, Any
|
||||
|
||||
from langflow import CustomComponent
|
||||
from langflow.schema import Record
|
||||
|
||||
|
||||
class NotionPageUpdate(CustomComponent):
|
||||
display_name = "Update Page Property [Notion]"
|
||||
description = "Update the properties of a Notion page."
|
||||
documentation: str = "https://docs.langflow.org/integrations/notion/page-update"
|
||||
icon = "NotionDirectoryLoader"
|
||||
|
||||
def build_config(self):
|
||||
return {
|
||||
"page_id": {
|
||||
"display_name": "Page ID",
|
||||
"field_type": "str",
|
||||
"info": "The ID of the Notion page to update.",
|
||||
},
|
||||
"properties": {
|
||||
"display_name": "Properties",
|
||||
"field_type": "str",
|
||||
"info": "The properties to update on the page (as a JSON string).",
|
||||
"multiline": True,
|
||||
},
|
||||
"notion_secret": {
|
||||
"display_name": "Notion Secret",
|
||||
"field_type": "str",
|
||||
"info": "The Notion integration token.",
|
||||
"password": True,
|
||||
},
|
||||
}
|
||||
|
||||
def build(
|
||||
self,
|
||||
page_id: str,
|
||||
properties: str,
|
||||
notion_secret: str,
|
||||
) -> Record:
|
||||
url = f"https://api.notion.com/v1/pages/{page_id}"
|
||||
headers = {
|
||||
"Authorization": f"Bearer {notion_secret}",
|
||||
"Content-Type": "application/json",
|
||||
"Notion-Version": "2022-06-28", # Use the latest supported version
|
||||
}
|
||||
|
||||
try:
|
||||
parsed_properties = json.loads(properties)
|
||||
except json.JSONDecodeError as e:
|
||||
raise ValueError("Invalid JSON format for properties") from e
|
||||
|
||||
data = {
|
||||
"properties": parsed_properties
|
||||
}
|
||||
|
||||
response = requests.patch(url, headers=headers, json=data)
|
||||
response.raise_for_status()
|
||||
|
||||
updated_page = response.json()
|
||||
|
||||
output = "Updated page properties:\n"
|
||||
for prop_name, prop_value in updated_page["properties"].items():
|
||||
output += f"{prop_name}: {prop_value}\n"
|
||||
|
||||
self.status = output
|
||||
return Record(data=updated_page)
|
||||
```
|
||||
|
||||
Let's break down the key parts of this component:
|
||||
|
||||
- The `build_config` method defines the configuration fields for the component. It specifies the required parameters and their properties, such as display names, field types, and any additional information or validation.
|
||||
|
||||
- The `build` method contains the main logic of the component. It takes the configured parameters as input and performs the necessary operations to update the properties of a Notion page.
|
||||
|
||||
- The component interacts with the Notion API to update the page properties. It constructs the API URL, headers, and request data based on the provided parameters.
|
||||
|
||||
- The processed data is returned as a `Record` object, which can be connected to other components in the Langflow flow. The `Record` object contains the updated page data.
|
||||
|
||||
- The component also stores the updated page properties in the `status` attribute for logging and debugging purposes.
|
||||
|
||||
## Example Usage
|
||||
|
||||
<Admonition type="info" title="Example Usage">
|
||||
Here's an example of how to use the `NotionPageUpdate` component in a Langflow flow using:
|
||||
|
||||
<ZoomableImage
|
||||
alt="NotionPageUpdate Flow Example"
|
||||
sources={{
|
||||
light: "img/notion/NotionPageUpdate_flow_example.png",
|
||||
dark: "img/notion/NotionPageUpdate_flow_example_dark.png",
|
||||
}}
|
||||
style={{ width: "100%", margin: "20px 0" }}
|
||||
/>
|
||||
</Admonition>
|
||||
|
||||
## Best Practices
|
||||
|
||||
When using the `NotionPageUpdate` component, consider the following best practices:
|
||||
|
||||
- Ensure that you have a valid Notion integration token with the necessary permissions to update page properties.
|
||||
- Handle edge cases and error scenarios gracefully, such as invalid JSON format for properties or API request failures.
|
||||
- We recommend using an LLM to generate the inputs for this component, to allow flexibilty
|
||||
|
||||
By leveraging the `NotionPageUpdate` component in Langflow, you can easily integrate updating Notion page properties into your language model workflows and build powerful applications that extend Langflow's capabilities.
|
||||
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
If you encounter any issues while using the `NotionPageUpdate` component, consider the following:
|
||||
|
||||
- Double-check that you have correctly configured the component with the required parameters, including the page ID, properties JSON, and Notion integration token.
|
||||
- Verify that your Notion integration token has the necessary permissions to update page properties.
|
||||
- Check the Langflow logs for any error messages or exceptions related to the component, such as invalid JSON format or API request failures.
|
||||
- Consult the [Notion API Documentation](https://developers.notion.com/reference/patch-page) for specific troubleshooting steps or common issues related to updating page properties.
|
||||
183
docs/docs/integrations/notion/search.md
Normal file
|
|
@ -0,0 +1,183 @@
|
|||
import Admonition from "@theme/Admonition";
|
||||
import ThemedImage from "@theme/ThemedImage";
|
||||
import useBaseUrl from "@docusaurus/useBaseUrl";
|
||||
import ZoomableImage from "/src/theme/ZoomableImage.js";
|
||||
|
||||
# Notion Search
|
||||
|
||||
The `NotionSearch` component is designed to search all pages and databases that have been shared with an integration in Notion. It provides a convenient way to integrate Notion search capabilities into your Langflow workflows.
|
||||
|
||||
[Notion Reference](https://developers.notion.com/reference/search)
|
||||
|
||||
<Admonition type="tip" title="Component Functionality">
|
||||
The `NotionSearch` component enables you to:
|
||||
|
||||
- Search for pages and databases in Notion that have been shared with an integration
|
||||
- Filter the search results based on object type (pages or databases)
|
||||
- Sort the search results in ascending or descending order based on the last edited time
|
||||
|
||||
</Admonition>
|
||||
|
||||
## Component Usage
|
||||
|
||||
To use the `NotionSearch` component in a Langflow flow, follow these steps:
|
||||
|
||||
1. **Add the `NotionSearch` component to your flow.**
|
||||
2. **Configure the component by providing the required parameters:**
|
||||
- `notion_secret`: The Notion integration token for authentication.
|
||||
- `query`: The text to search for in page and database titles.
|
||||
- `filter_value`: The type of objects to include in the search results (pages or databases).
|
||||
- `sort_direction`: The direction to sort the search results (ascending or descending).
|
||||
3. **Connect the `NotionSearch` component to other components in your flow as needed.**
|
||||
|
||||
## Component Python Code
|
||||
|
||||
```python
|
||||
import requests
|
||||
from typing import Dict, Any, List
|
||||
from langflow.custom import CustomComponent
|
||||
from langflow.schema import Record
|
||||
|
||||
class NotionSearch(CustomComponent):
|
||||
display_name = "Search Notion"
|
||||
description = (
|
||||
"Searches all pages and databases that have been shared with an integration."
|
||||
)
|
||||
documentation: str = "https://docs.langflow.org/integrations/notion/search"
|
||||
icon = "NotionDirectoryLoader"
|
||||
|
||||
field_order = [
|
||||
"notion_secret",
|
||||
"query",
|
||||
"filter_value",
|
||||
"sort_direction",
|
||||
]
|
||||
|
||||
def build_config(self):
|
||||
return {
|
||||
"notion_secret": {
|
||||
"display_name": "Notion Secret",
|
||||
"field_type": "str",
|
||||
"info": "The Notion integration token.",
|
||||
"password": True,
|
||||
},
|
||||
"query": {
|
||||
"display_name": "Search Query",
|
||||
"field_type": "str",
|
||||
"info": "The text that the API compares page and database titles against.",
|
||||
},
|
||||
"filter_value": {
|
||||
"display_name": "Filter Type",
|
||||
"field_type": "str",
|
||||
"info": "Limits the results to either only pages or only databases.",
|
||||
"options": ["page", "database"],
|
||||
"default_value": "page",
|
||||
},
|
||||
"sort_direction": {
|
||||
"display_name": "Sort Direction",
|
||||
"field_type": "str",
|
||||
"info": "The direction to sort the results.",
|
||||
"options": ["ascending", "descending"],
|
||||
"default_value": "descending",
|
||||
},
|
||||
}
|
||||
|
||||
def build(
|
||||
self,
|
||||
notion_secret: str,
|
||||
query: str = "",
|
||||
filter_value: str = "page",
|
||||
sort_direction: str = "descending",
|
||||
) -> List[Record]:
|
||||
try:
|
||||
url = "https://api.notion.com/v1/search"
|
||||
headers = {
|
||||
"Authorization": f"Bearer {notion_secret}",
|
||||
"Content-Type": "application/json",
|
||||
"Notion-Version": "2022-06-28",
|
||||
}
|
||||
|
||||
data = {
|
||||
"query": query,
|
||||
"filter": {
|
||||
"value": filter_value,
|
||||
"property": "object"
|
||||
},
|
||||
"sort":{
|
||||
"direction": sort_direction,
|
||||
"timestamp": "last_edited_time"
|
||||
}
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=data)
|
||||
response.raise_for_status()
|
||||
|
||||
results = response.json()
|
||||
records = []
|
||||
combined_text = f"Results found: {len(results['results'])}\n\n"
|
||||
for result in results['results']:
|
||||
result_data = {
|
||||
'id': result['id'],
|
||||
'type': result['object'],
|
||||
'last_edited_time': result['last_edited_time'],
|
||||
}
|
||||
|
||||
if result['object'] == 'page':
|
||||
result_data['title_or_url'] = result['url']
|
||||
text = f"id: {result['id']}\ntitle_or_url: {result['url']}\n"
|
||||
elif result['object'] == 'database':
|
||||
if 'title' in result and isinstance(result['title'], list) and len(result['title']) > 0:
|
||||
result_data['title_or_url'] = result['title'][0]['plain_text']
|
||||
text = f"id: {result['id']}\ntitle_or_url: {result['title'][0]['plain_text']}\n"
|
||||
else:
|
||||
result_data['title_or_url'] = "N/A"
|
||||
text = f"id: {result['id']}\ntitle_or_url: N/A\n"
|
||||
|
||||
text += f"type: {result['object']}\nlast_edited_time: {result['last_edited_time']}\n\n"
|
||||
combined_text += text
|
||||
records.append(Record(text=text, data=result_data))
|
||||
|
||||
self.status = combined_text
|
||||
return records
|
||||
|
||||
except Exception as e:
|
||||
self.status = f"An error occurred: {str(e)}"
|
||||
return [Record(text=self.status, data=[])]
|
||||
```
|
||||
|
||||
## Example Usage
|
||||
<Admonition type="info" title="Example Usage">
|
||||
Here's an example of how you can use the `NotionSearch` component in a Langflow flow:
|
||||
|
||||
<ZoomableImage
|
||||
alt="NotionSearch Flow Example"
|
||||
sources={{
|
||||
light: "img/notion/NotionSearch_flow_example.png",
|
||||
dark: "img/notion/NotionSearch_flow_example_dark.png",
|
||||
}}
|
||||
style={{ width: "100%", margin: "20px 0" }}
|
||||
/>
|
||||
|
||||
In this example, the `NotionSearch` component is used to search for pages and databases in Notion based on the provided query and filter criteria. The retrieved data can then be processed further in the subsequent components of the flow.
|
||||
</Admonition>
|
||||
|
||||
## Best Practices
|
||||
|
||||
When using the `NotionSearch` component, consider these best practices:
|
||||
|
||||
- Ensure you have a valid Notion integration token with the necessary permissions to search for pages and databases.
|
||||
- Provide a meaningful search query to narrow down the results to the desired pages or databases.
|
||||
- Choose the appropriate filter type (`page` or `database`) based on your search requirements.
|
||||
- Consider the sorting direction (`ascending` or `descending`) to organize the search results effectively.
|
||||
|
||||
The `NotionSearch` component provides a powerful way to integrate Notion search capabilities into your Langflow workflows. By leveraging this component, you can easily search for pages and databases in Notion based on custom queries and filters, enabling you to build more dynamic and data-driven flows.
|
||||
|
||||
We encourage you to explore the capabilities of the `NotionSearch` component further and experiment with different search scenarios to unlock the full potential of integrating Notion search into your Langflow workflows.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
If you encounter any issues while using the `NotionSearch` component, consider the following:
|
||||
|
||||
- Double-check that the `notion_secret` is correct and valid.
|
||||
- Verify that the Notion integration has the necessary permissions to access the desired pages and databases.
|
||||
- Check the Notion API documentation for any updates or changes that may affect the component's functionality.
|
||||
79
docs/docs/integrations/notion/setup.md
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
import Admonition from "@theme/Admonition";
|
||||
|
||||
# Setting up a Notion App
|
||||
|
||||
To use Notion components in Langflow, you first need to create a Notion integration and configure it with the necessary capabilities. This guide will walk you through the process of setting up a Notion integration and granting it access to your Notion databases.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- A Notion account with access to the workspace where you want to use the integration.
|
||||
- Admin permissions in the Notion workspace to create and manage integrations.
|
||||
|
||||
## Step 1: Create a Notion Integration
|
||||
|
||||
1. Go to the [Notion Integrations](https://www.notion.com/my-integrations) page.
|
||||
2. Click on the "New integration" button.
|
||||
3. Give your integration a name and select the workspace where you want to use it.
|
||||
4. Click "Submit" to create the integration.
|
||||
|
||||
<Admonition type="info" title="Integration Capabilities">
|
||||
When creating the integration, make sure to enable the necessary capabilities based on your requirements. Refer to the [Notion Integration Capabilities](https://developers.notion.com/reference/capabilities) documentation for more information on each capability.
|
||||
</Admonition>
|
||||
|
||||
## Step 2: Configure Integration Capabilities
|
||||
|
||||
After creating the integration, you need to configure its capabilities to define what actions it can perform and what data it can access.
|
||||
|
||||
1. In the integration settings page, go to the **Capabilities** tab.
|
||||
2. Enable the required capabilities for your integration. For example:
|
||||
- If your integration needs to read data from Notion, enable the "Read content" capability.
|
||||
- If your integration needs to create new content in Notion, enable the "Insert content" capability.
|
||||
- If your integration needs to update existing content in Notion, enable the "Update content" capability.
|
||||
3. Configure the user information access level based on your integration's requirements.
|
||||
4. Save the changes.
|
||||
|
||||
## Step 3: Obtain Integration Token
|
||||
|
||||
To authenticate your integration with Notion, you need to obtain an integration token.
|
||||
|
||||
1. In the integration settings page, go to the "Secrets" tab.
|
||||
2. Copy the "Internal Integration Token" value. This token will be used to authenticate your integration with Notion.
|
||||
|
||||
<Admonition type="warning" title="Keep Your Token Secure">
|
||||
Your integration token is a sensitive piece of information. Make sure to keep it secure and never share it publicly. Store it safely in your Langflow configuration or environment variables.
|
||||
</Admonition>
|
||||
|
||||
## Step 4: Grant Integration Access to Notion Databases
|
||||
|
||||
For your integration to interact with Notion databases, you need to grant it access to the specific databases it will be working with.
|
||||
|
||||
1. Open the Notion database that you want your integration to access.
|
||||
2. Click on the "Share" button in the top-right corner of the page.
|
||||
3. In the "Invite" section, select your integration from the list.
|
||||
4. Click "Invite" to grant the integration access to the database.
|
||||
|
||||
<Admonition type="info" title="Nested Databases">
|
||||
If your database contains references to other databases, you need to grant the integration access to those referenced databases as well. Repeat step 4 for each referenced database to ensure your integration has the necessary access.
|
||||
</Admonition>
|
||||
|
||||
## Using Notion Components in Langflow
|
||||
|
||||
Once you have set up your Notion integration and granted it access to the required databases, you can start using the Notion components in Langflow.
|
||||
|
||||
Langflow provides the following Notion components:
|
||||
|
||||
- **List Pages**: Retrieves a list of pages from a Notion database.
|
||||
- **List Database Properties**: Retrieves the properties of a Notion database.
|
||||
- **Add Page Content**: Adds content to a Notion page.
|
||||
- **List Users**: Retrieves a list of users with access to a Notion workspace.
|
||||
- **Update Property**: Updates the value of a property in a Notion page.
|
||||
|
||||
Refer to the individual component documentation for more details on how to use each component in your Langflow flows.
|
||||
|
||||
## Additional Resources
|
||||
|
||||
- [Notion API Documentation](https://developers.notion.com/docs/getting-started)
|
||||
- [Notion Integration Capabilities](https://developers.notion.com/reference/capabilities)
|
||||
|
||||
If you encounter any issues or have questions, please reach out to our support team or consult the Langflow community forums.
|
||||
|
||||
|
|
@ -131,5 +131,28 @@ module.exports = {
|
|||
"contributing/contribute-component",
|
||||
],
|
||||
},
|
||||
{
|
||||
type: "category",
|
||||
label: "Integrations",
|
||||
collapsed: false,
|
||||
items: [
|
||||
{
|
||||
type: "category",
|
||||
label: "Notion",
|
||||
items: [
|
||||
"integrations/notion/intro",
|
||||
"integrations/notion/setup",
|
||||
"integrations/notion/search",
|
||||
"integrations/notion/list-database-properties",
|
||||
"integrations/notion/list-pages",
|
||||
"integrations/notion/list-users",
|
||||
"integrations/notion/page-create",
|
||||
"integrations/notion/add-content-to-page",
|
||||
"integrations/notion/page-update",
|
||||
"integrations/notion/page-content-viewer",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
|
|
|||
BIN
docs/static/img/notion/AddContentToPage_flow_example.png
vendored
Normal file
|
After Width: | Height: | Size: 44 KiB |
BIN
docs/static/img/notion/AddContentToPage_flow_example_dark.png
vendored
Normal file
|
After Width: | Height: | Size: 44 KiB |
BIN
docs/static/img/notion/NotionDatabaseProperties_flow_example.png
vendored
Normal file
|
After Width: | Height: | Size: 83 KiB |
BIN
docs/static/img/notion/NotionDatabaseProperties_flow_example_dark.png
vendored
Normal file
|
After Width: | Height: | Size: 82 KiB |
BIN
docs/static/img/notion/NotionListPages_flow_example.png
vendored
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
docs/static/img/notion/NotionListPages_flow_example_dark.png
vendored
Normal file
|
After Width: | Height: | Size: 29 KiB |
BIN
docs/static/img/notion/NotionPageContent_flow_example.png
vendored
Normal file
|
After Width: | Height: | Size: 36 KiB |
BIN
docs/static/img/notion/NotionPageContent_flow_example_dark.png
vendored
Normal file
|
After Width: | Height: | Size: 36 KiB |
BIN
docs/static/img/notion/NotionPageCreator_flow_example.png
vendored
Normal file
|
After Width: | Height: | Size: 35 KiB |
BIN
docs/static/img/notion/NotionPageCreator_flow_example_dark.png
vendored
Normal file
|
After Width: | Height: | Size: 35 KiB |
BIN
docs/static/img/notion/NotionPageUpdate_flow_example.png
vendored
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
docs/static/img/notion/NotionPageUpdate_flow_example_dark.png
vendored
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
docs/static/img/notion/NotionSearch_flow_example.png
vendored
Normal file
|
After Width: | Height: | Size: 29 KiB |
BIN
docs/static/img/notion/NotionSearch_flow_example_dark.png
vendored
Normal file
|
After Width: | Height: | Size: 29 KiB |
BIN
docs/static/img/notion/NotionUserList_flow_example.png
vendored
Normal file
|
After Width: | Height: | Size: 59 KiB |
BIN
docs/static/img/notion/NotionUserList_flow_example_dark.png
vendored
Normal file
|
After Width: | Height: | Size: 58 KiB |
BIN
docs/static/img/notion/notion_components_bundle.png
vendored
Normal file
|
After Width: | Height: | Size: 113 KiB |
BIN
docs/static/img/notion/notion_components_bundle_dark.png
vendored
Normal file
|
After Width: | Height: | Size: 115 KiB |