From 013a4f23164a5805586a41607646cf5a74eaa933 Mon Sep 17 00:00:00 2001 From: takoba Date: Fri, 4 Feb 2022 21:17:59 +0900 Subject: [PATCH] :bug: #6 fix on resolving title --- src/app.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/app.ts b/src/app.ts index 04280d2..3f163a8 100644 --- a/src/app.ts +++ b/src/app.ts @@ -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