Skip to content

Commit

Permalink
Merge pull request #7 from takoba/6-fix-resolving-title
Browse files Browse the repository at this point in the history
🐛 #6 fix resolving title
  • Loading branch information
takoba committed Feb 4, 2022
2 parents 6a798af + 013a4f2 commit a4b4b2c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,18 @@ app.message(

const title = ((obj: GetPageResponse | GetDatabaseResponse) => {
if (obj.object === 'page') {
return (('properties' in obj ? obj.properties : []) as { type: string; plain_text: string }[]).find(
(elem) => elem.type === 'title'
)?.plain_text
const titleProp = (
('properties' in obj ? Object.values(obj.properties) : []) as {
type: string
[key: string | symbol]: string | object | boolean | null
}[]
).find((elem) => elem.type === 'title') as {
id: 'title'
type: 'title'
title: { plain_text: string; [key: string | symbol]: string | object | boolean | null }[]
}
const titleObj = titleProp.title[0] ?? {}
return titleObj && 'plain_text' in titleObj ? titleObj.plain_text : 'missing title :cry:'
} else if (obj.object === 'database') {
return (
'title' in obj
Expand Down

0 comments on commit a4b4b2c

Please sign in to comment.