@@ -16,6 +16,7 @@ import (
1616 "github.com/priyanshujain/openbotkit/oauth/google"
1717 "github.com/priyanshujain/openbotkit/remote"
1818 ansrc "github.com/priyanshujain/openbotkit/source/applenotes"
19+ contactsrc "github.com/priyanshujain/openbotkit/source/contacts"
1920 slacksrc "github.com/priyanshujain/openbotkit/source/slack"
2021 "github.com/priyanshujain/openbotkit/source/slack/desktop"
2122 "github.com/priyanshujain/openbotkit/store"
@@ -69,6 +70,7 @@ var setupCmd = &cobra.Command{
6970 sourceOptions = append (sourceOptions , huh .NewOption ("Slack" , "slack" ))
7071 if runtime .GOOS == "darwin" {
7172 sourceOptions = append (sourceOptions , huh .NewOption ("Apple Notes" , "applenotes" ))
73+ sourceOptions = append (sourceOptions , huh .NewOption ("Apple Contacts" , "applecontacts" ))
7274 }
7375
7476 err = huh .NewForm (
@@ -123,6 +125,10 @@ var setupCmd = &cobra.Command{
123125 if err := setupAppleNotes (cfg ); err != nil {
124126 return err
125127 }
128+ case "applecontacts" :
129+ if err := setupAppleContacts (cfg ); err != nil {
130+ return err
131+ }
126132 case "models" :
127133 if err := setupModels (cfg ); err != nil {
128134 return err
@@ -164,6 +170,8 @@ var setupCmd = &cobra.Command{
164170 fmt .Println (" - Run: obk auth whatsapp login" )
165171 case "applenotes" :
166172 fmt .Println (" - Apple Notes is ready (synced during setup)" )
173+ case "applecontacts" :
174+ fmt .Println (" - Apple Contacts is ready (synced during setup)" )
167175 case "slack" :
168176 fmt .Println (" - Slack is ready! Try: obk slack channels" )
169177 }
@@ -395,13 +403,24 @@ func setupGWS(cfg *config.Config, services []string) error {
395403}
396404
397405func setupAppleNotes (cfg * config.Config ) error {
406+ fmt .Println ("\n Setting up Apple Notes..." )
407+ fmt .Println (" macOS will ask for permission to access Notes." )
408+ fmt .Println (" Click \" OK\" to grant access." )
409+ fmt .Println ()
410+
411+ if err := ansrc .CheckPermission (); err != nil {
412+ fmt .Println (" Permission denied or Notes not accessible." )
413+ fmt .Println (" Grant access in System Settings > Privacy & Security > Automation." )
414+ fmt .Println (" Then re-run: obk setup" )
415+ return fmt .Errorf ("apple notes permission: %w" , err )
416+ }
417+
418+ fmt .Println (" Permission granted. Running initial sync..." )
419+
398420 if err := config .EnsureSourceDir ("applenotes" ); err != nil {
399421 return fmt .Errorf ("create applenotes dir: %w" , err )
400422 }
401423
402- fmt .Println ("\n Setting up Apple Notes..." )
403- fmt .Println (" Running initial sync (this may take a few seconds)..." )
404-
405424 db , err := store .Open (store.Config {
406425 Driver : cfg .AppleNotes .Storage .Driver ,
407426 DSN : cfg .AppleNotesDataDSN (),
@@ -424,6 +443,49 @@ func setupAppleNotes(cfg *config.Config) error {
424443 return nil
425444}
426445
446+ func setupAppleContacts (cfg * config.Config ) error {
447+ fmt .Println ("\n Setting up Apple Contacts..." )
448+ fmt .Println (" macOS will ask for permission to access Contacts." )
449+ fmt .Println (" Click \" OK\" to grant access." )
450+ fmt .Println ()
451+
452+ if err := contactsrc .CheckAppleContactsPermission (); err != nil {
453+ fmt .Println (" Permission denied or Contacts not accessible." )
454+ fmt .Println (" Grant access in System Settings > Privacy & Security > Automation." )
455+ fmt .Println (" Then re-run: obk setup" )
456+ return fmt .Errorf ("apple contacts permission: %w" , err )
457+ }
458+
459+ fmt .Println (" Permission granted. Running initial sync..." )
460+
461+ if err := config .EnsureSourceDir ("contacts" ); err != nil {
462+ return fmt .Errorf ("create contacts dir: %w" , err )
463+ }
464+
465+ db , err := store .Open (store.Config {
466+ Driver : cfg .Contacts .Storage .Driver ,
467+ DSN : cfg .ContactsDataDSN (),
468+ })
469+ if err != nil {
470+ return fmt .Errorf ("open database: %w" , err )
471+ }
472+ defer db .Close ()
473+
474+ result , err := contactsrc .Sync (db , nil , contactsrc.SyncOptions {
475+ Sources : []string {"applecontacts" },
476+ })
477+ if err != nil {
478+ return fmt .Errorf ("apple contacts sync: %w" , err )
479+ }
480+
481+ if err := config .LinkSource ("contacts" ); err != nil {
482+ return fmt .Errorf ("link source: %w" , err )
483+ }
484+
485+ fmt .Printf (" Synced %d contacts (%d new, %d linked)\n " , result .Created + result .Linked , result .Created , result .Linked )
486+ return nil
487+ }
488+
427489func setupSlack (cfg * config.Config ) error {
428490 fmt .Println ("\n -- Slack Setup --" )
429491
0 commit comments