Skip to content

Commit 574d1f7

Browse files
committed
feat: enhance Notion service to support dynamic content property detection for transcribed text, improving page creation process
1 parent d064e0e commit 574d1f7

File tree

1 file changed

+52
-17
lines changed

1 file changed

+52
-17
lines changed

src/services/notion.service.js

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ class NotionService {
7171
// Find a multiselect property for tags (look for 'tags', 'tag', 'categories', etc.)
7272
const tagsPropertyName = this.findTagsProperty(dbProperties);
7373

74+
// Find a suitable content property for the transcribed text
75+
const contentPropertyName = this.findContentProperty(dbProperties);
76+
7477
console.log("📄 Creating new page in Notion database...");
7578

7679
// Create the page properties dynamically based on available properties
@@ -98,28 +101,32 @@ class NotionService {
98101
console.log(`✅ Using tags property: "${tagsPropertyName}"`);
99102
}
100103

101-
// Create the page with content
104+
if (contentPropertyName) {
105+
properties[contentPropertyName] = {
106+
rich_text: [
107+
{
108+
type: "text",
109+
text: {
110+
content: transcribedText,
111+
},
112+
},
113+
],
114+
};
115+
console.log(
116+
`✅ Using content property: "${contentPropertyName}" for transcribed text`
117+
);
118+
} else {
119+
console.log(
120+
"⚠️ No content property found in database. Transcribed text will not be stored."
121+
);
122+
}
123+
124+
// Create the page (content now goes to Content property instead of page body)
102125
const response = await this.client.pages.create({
103126
parent: {
104127
database_id: this.extractDatabaseId(config.notion.databaseId),
105128
},
106129
properties: properties,
107-
children: [
108-
{
109-
object: "block",
110-
type: "paragraph",
111-
paragraph: {
112-
rich_text: [
113-
{
114-
type: "text",
115-
text: {
116-
content: transcribedText,
117-
},
118-
},
119-
],
120-
},
121-
},
122-
],
123130
});
124131

125132
console.log("✅ Notion page created successfully");
@@ -168,6 +175,34 @@ class NotionService {
168175
return null;
169176
}
170177

178+
// Helper method to find a suitable content property
179+
findContentProperty(properties) {
180+
// Look for rich_text properties with content-like names
181+
const contentNames = ["content", "text", "body", "description", "notes"];
182+
183+
for (const [name, config] of Object.entries(properties)) {
184+
if (config.type === "rich_text") {
185+
// Check if the property name contains any content-like words
186+
if (
187+
contentNames.some((contentName) =>
188+
name.toLowerCase().includes(contentName)
189+
)
190+
) {
191+
return name;
192+
}
193+
}
194+
}
195+
196+
// If no content-like property found, return the first rich_text property
197+
for (const [name, config] of Object.entries(properties)) {
198+
if (config.type === "rich_text") {
199+
return name;
200+
}
201+
}
202+
203+
return null;
204+
}
205+
171206
async getDatabaseProperties() {
172207
try {
173208
const response = await this.client.databases.retrieve({

0 commit comments

Comments
 (0)