@@ -748,18 +748,33 @@ async function createGoogleTaskNotification(title, notes) {
748748 if ( ! tokenRes . ok ) return ;
749749 const { access_token } = await tokenRes . json ( ) ;
750750
751- const taskRes = await fetch ( "https://tasks.googleapis.com/tasks/v1/lists/@default/tasks" , {
752- method : "POST" ,
753- headers : {
754- Authorization : `Bearer ${ access_token } ` ,
755- "Content-Type" : "application/json" ,
756- } ,
757- body : JSON . stringify ( {
758- title,
759- notes,
760- due : new Date ( Date . now ( ) + 24 * 60 * 60 * 1000 ) . toISOString ( ) ,
761- } ) ,
751+ let targetListId = "@default" ;
752+ const listsRes = await fetch ( "https://tasks.googleapis.com/tasks/v1/users/@me/lists?maxResults=100" , {
753+ headers : { Authorization : `Bearer ${ access_token } ` } ,
762754 } ) ;
755+ if ( listsRes . ok ) {
756+ const listsData = await listsRes . json ( ) ;
757+ const found = ( listsData . items || [ ] ) . find (
758+ ( l ) => ( l . title || "" ) . trim ( ) . toLowerCase ( ) === "codingcat.dev posts"
759+ ) ;
760+ if ( found ?. id ) targetListId = found . id ;
761+ }
762+
763+ const taskRes = await fetch (
764+ `https://tasks.googleapis.com/tasks/v1/lists/${ encodeURIComponent ( targetListId ) } /tasks` ,
765+ {
766+ method : "POST" ,
767+ headers : {
768+ Authorization : `Bearer ${ access_token } ` ,
769+ "Content-Type" : "application/json" ,
770+ } ,
771+ body : JSON . stringify ( {
772+ title,
773+ notes,
774+ due : new Date ( Date . now ( ) + 24 * 60 * 60 * 1000 ) . toISOString ( ) ,
775+ } ) ,
776+ }
777+ ) ;
763778 if ( taskRes . ok ) {
764779 console . log ( `✓ Created Google Task: "${ title } "` ) ;
765780 }
@@ -987,9 +1002,18 @@ async function runForDataset(targetDataset) {
9871002
9881003 if ( targetDataset === "production" && createdDraftInfo ) {
9891004 const { signal, draftDoc, socialDrafts } = createdDraftInfo ;
1005+ const baseDraftId = String ( draftDoc . _id ) . replace ( / ^ d r a f t s \. / , "" ) ;
1006+ const studioDraftUrl = `https://codingcat-prod.sanity.studio/intent/edit/id=${ baseDraftId } ;type=post/` ;
9901007 await createGoogleTaskNotification (
9911008 `🔥 [Trend Radar] Review Draft: ${ signal . title } ` ,
992- `Score: ${ signal . score } /100 (${ signal . rawMetrics } )\nSource: ${ signal . sourceUrl } \nSanity Draft ID: ${ draftDoc . _id } \n\nReady-to-post X Draft:\n${ socialDrafts . x } `
1009+ [
1010+ `Studio Draft: ${ studioDraftUrl } ` ,
1011+ `Score: ${ signal . score } /100 (${ signal . rawMetrics } )` ,
1012+ `Source: ${ signal . sourceUrl } ` ,
1013+ `` ,
1014+ `Ready-to-post X Draft:` ,
1015+ socialDrafts . x ,
1016+ ] . join ( "\n" )
9931017 ) ;
9941018 }
9951019}
0 commit comments