@startanaicompany/crm 1.0.3 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +546 -0
- package/package.json +10 -3
package/index.js
CHANGED
|
@@ -596,4 +596,550 @@ program
|
|
|
596
596
|
}
|
|
597
597
|
});
|
|
598
598
|
|
|
599
|
+
// ============================================================
|
|
600
|
+
// CONTACTS
|
|
601
|
+
// ============================================================
|
|
602
|
+
|
|
603
|
+
const contactsCmd = program
|
|
604
|
+
.command('contacts')
|
|
605
|
+
.description('Manage contacts (people separate from leads)');
|
|
606
|
+
|
|
607
|
+
contactsCmd
|
|
608
|
+
.command('create')
|
|
609
|
+
.description('Create a new contact')
|
|
610
|
+
.requiredOption('--first-name <name>', 'First name')
|
|
611
|
+
.option('--last-name <name>', 'Last name')
|
|
612
|
+
.option('--email <email>', 'Email address (unique)')
|
|
613
|
+
.option('--phone <phone>', 'Phone number')
|
|
614
|
+
.option('--company <company>', 'Company name')
|
|
615
|
+
.option('--title <title>', 'Job title')
|
|
616
|
+
.option('--tags <tags>', 'Comma-separated tags')
|
|
617
|
+
.option('--do-not-contact', 'Mark as do not contact')
|
|
618
|
+
.option('--notes <notes>', 'Notes')
|
|
619
|
+
.action(async (opts) => {
|
|
620
|
+
const globalOpts = program.opts();
|
|
621
|
+
const client = getClient(globalOpts);
|
|
622
|
+
try {
|
|
623
|
+
const body = {
|
|
624
|
+
first_name: opts.firstName,
|
|
625
|
+
last_name: opts.lastName,
|
|
626
|
+
email: opts.email,
|
|
627
|
+
phone: opts.phone,
|
|
628
|
+
company: opts.company,
|
|
629
|
+
title: opts.title,
|
|
630
|
+
notes: opts.notes,
|
|
631
|
+
do_not_contact: opts.doNotContact === true,
|
|
632
|
+
};
|
|
633
|
+
if (opts.tags) body.tags = opts.tags.split(',').map(t => t.trim());
|
|
634
|
+
const res = await client.post('/contacts', body);
|
|
635
|
+
printJSON(res.data);
|
|
636
|
+
} catch (err) {
|
|
637
|
+
handleError(err);
|
|
638
|
+
}
|
|
639
|
+
});
|
|
640
|
+
|
|
641
|
+
contactsCmd
|
|
642
|
+
.command('list')
|
|
643
|
+
.description('List contacts')
|
|
644
|
+
.option('--email <email>', 'Filter by email (partial match)')
|
|
645
|
+
.option('--company <company>', 'Filter by company (partial match)')
|
|
646
|
+
.option('--tag <tag>', 'Filter by tag')
|
|
647
|
+
.option('--page <n>', 'Page number', '1')
|
|
648
|
+
.option('--per-page <n>', 'Results per page', '20')
|
|
649
|
+
.action(async (opts) => {
|
|
650
|
+
const globalOpts = program.opts();
|
|
651
|
+
const client = getClient(globalOpts);
|
|
652
|
+
try {
|
|
653
|
+
const params = { page: opts.page, per_page: opts.perPage };
|
|
654
|
+
if (opts.email) params.email = opts.email;
|
|
655
|
+
if (opts.company) params.company = opts.company;
|
|
656
|
+
if (opts.tag) params.tag = opts.tag;
|
|
657
|
+
const res = await client.get('/contacts', { params });
|
|
658
|
+
printJSON(res.data);
|
|
659
|
+
} catch (err) {
|
|
660
|
+
handleError(err);
|
|
661
|
+
}
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
contactsCmd
|
|
665
|
+
.command('get <id>')
|
|
666
|
+
.description('Get a contact by ID')
|
|
667
|
+
.action(async (id) => {
|
|
668
|
+
const globalOpts = program.opts();
|
|
669
|
+
const client = getClient(globalOpts);
|
|
670
|
+
try {
|
|
671
|
+
const res = await client.get(`/contacts/${id}`);
|
|
672
|
+
printJSON(res.data);
|
|
673
|
+
} catch (err) {
|
|
674
|
+
handleError(err);
|
|
675
|
+
}
|
|
676
|
+
});
|
|
677
|
+
|
|
678
|
+
contactsCmd
|
|
679
|
+
.command('update <id>')
|
|
680
|
+
.description('Update a contact')
|
|
681
|
+
.option('--first-name <name>', 'First name')
|
|
682
|
+
.option('--last-name <name>', 'Last name')
|
|
683
|
+
.option('--email <email>', 'Email address')
|
|
684
|
+
.option('--phone <phone>', 'Phone number')
|
|
685
|
+
.option('--company <company>', 'Company name')
|
|
686
|
+
.option('--title <title>', 'Job title')
|
|
687
|
+
.option('--tags <tags>', 'Comma-separated tags')
|
|
688
|
+
.option('--notes <notes>', 'Notes')
|
|
689
|
+
.action(async (id, opts) => {
|
|
690
|
+
const globalOpts = program.opts();
|
|
691
|
+
const client = getClient(globalOpts);
|
|
692
|
+
try {
|
|
693
|
+
const body = {};
|
|
694
|
+
if (opts.firstName !== undefined) body.first_name = opts.firstName;
|
|
695
|
+
if (opts.lastName !== undefined) body.last_name = opts.lastName;
|
|
696
|
+
if (opts.email !== undefined) body.email = opts.email;
|
|
697
|
+
if (opts.phone !== undefined) body.phone = opts.phone;
|
|
698
|
+
if (opts.company !== undefined) body.company = opts.company;
|
|
699
|
+
if (opts.title !== undefined) body.title = opts.title;
|
|
700
|
+
if (opts.tags !== undefined) body.tags = opts.tags.split(',').map(t => t.trim());
|
|
701
|
+
if (opts.notes !== undefined) body.notes = opts.notes;
|
|
702
|
+
const res = await client.patch(`/contacts/${id}`, body);
|
|
703
|
+
printJSON(res.data);
|
|
704
|
+
} catch (err) {
|
|
705
|
+
handleError(err);
|
|
706
|
+
}
|
|
707
|
+
});
|
|
708
|
+
|
|
709
|
+
contactsCmd
|
|
710
|
+
.command('delete <id>')
|
|
711
|
+
.description('Soft-delete a contact')
|
|
712
|
+
.action(async (id) => {
|
|
713
|
+
const globalOpts = program.opts();
|
|
714
|
+
const client = getClient(globalOpts);
|
|
715
|
+
try {
|
|
716
|
+
const res = await client.delete(`/contacts/${id}`);
|
|
717
|
+
printJSON(res.data);
|
|
718
|
+
} catch (err) {
|
|
719
|
+
handleError(err);
|
|
720
|
+
}
|
|
721
|
+
});
|
|
722
|
+
|
|
723
|
+
contactsCmd
|
|
724
|
+
.command('leads <id>')
|
|
725
|
+
.description('List leads linked to a contact')
|
|
726
|
+
.action(async (id) => {
|
|
727
|
+
const globalOpts = program.opts();
|
|
728
|
+
const client = getClient(globalOpts);
|
|
729
|
+
try {
|
|
730
|
+
const res = await client.get(`/contacts/${id}/leads`);
|
|
731
|
+
printJSON(res.data);
|
|
732
|
+
} catch (err) {
|
|
733
|
+
handleError(err);
|
|
734
|
+
}
|
|
735
|
+
});
|
|
736
|
+
|
|
737
|
+
// ============================================================
|
|
738
|
+
// BOARD — sales pipeline board
|
|
739
|
+
// ============================================================
|
|
740
|
+
|
|
741
|
+
program
|
|
742
|
+
.command('board')
|
|
743
|
+
.description('Show sales pipeline board (leads grouped by stage)')
|
|
744
|
+
.action(async () => {
|
|
745
|
+
const globalOpts = program.opts();
|
|
746
|
+
const client = getClient(globalOpts);
|
|
747
|
+
try {
|
|
748
|
+
const res = await client.get('/board');
|
|
749
|
+
printJSON(res.data);
|
|
750
|
+
} catch (err) {
|
|
751
|
+
handleError(err);
|
|
752
|
+
}
|
|
753
|
+
});
|
|
754
|
+
|
|
755
|
+
// ============================================================
|
|
756
|
+
// CALLS
|
|
757
|
+
// ============================================================
|
|
758
|
+
|
|
759
|
+
const callsCmd = program
|
|
760
|
+
.command('calls')
|
|
761
|
+
.description('Manage call logs');
|
|
762
|
+
|
|
763
|
+
callsCmd
|
|
764
|
+
.command('create')
|
|
765
|
+
.description('Log a call')
|
|
766
|
+
.requiredOption('--direction <dir>', 'inbound or outbound')
|
|
767
|
+
.option('--lead-id <id>', 'Lead ID associated with this call')
|
|
768
|
+
.option('--contact-id <id>', 'Contact ID associated with this call')
|
|
769
|
+
.option('--outcome <outcome>', 'connected | left_voicemail | no_answer | busy | wrong_number | meeting_booked | demo_completed')
|
|
770
|
+
.option('--duration <seconds>', 'Duration in seconds')
|
|
771
|
+
.option('--notes <notes>', 'Call notes')
|
|
772
|
+
.option('--call-time <iso>', 'Call time (ISO8601, defaults to now)')
|
|
773
|
+
.action(async (opts) => {
|
|
774
|
+
const globalOpts = program.opts();
|
|
775
|
+
const client = getClient(globalOpts);
|
|
776
|
+
try {
|
|
777
|
+
const body = { direction: opts.direction };
|
|
778
|
+
if (opts.leadId) body.lead_id = opts.leadId;
|
|
779
|
+
if (opts.contactId) body.contact_id = opts.contactId;
|
|
780
|
+
if (opts.outcome) body.outcome = opts.outcome;
|
|
781
|
+
if (opts.duration) body.duration_seconds = parseInt(opts.duration);
|
|
782
|
+
if (opts.notes) body.notes = opts.notes;
|
|
783
|
+
if (opts.callTime) body.call_time = opts.callTime;
|
|
784
|
+
const res = await client.post('/calls', body);
|
|
785
|
+
printJSON(res.data);
|
|
786
|
+
} catch (err) {
|
|
787
|
+
handleError(err);
|
|
788
|
+
}
|
|
789
|
+
});
|
|
790
|
+
|
|
791
|
+
callsCmd
|
|
792
|
+
.command('list')
|
|
793
|
+
.description('List call logs')
|
|
794
|
+
.option('--lead-id <id>', 'Filter by lead ID')
|
|
795
|
+
.option('--contact-id <id>', 'Filter by contact ID')
|
|
796
|
+
.option('--direction <dir>', 'Filter by direction (inbound/outbound)')
|
|
797
|
+
.option('--outcome <outcome>', 'Filter by outcome')
|
|
798
|
+
.option('--page <n>', 'Page number', '1')
|
|
799
|
+
.option('--per-page <n>', 'Results per page', '20')
|
|
800
|
+
.action(async (opts) => {
|
|
801
|
+
const globalOpts = program.opts();
|
|
802
|
+
const client = getClient(globalOpts);
|
|
803
|
+
try {
|
|
804
|
+
const params = { page: opts.page, per_page: opts.perPage };
|
|
805
|
+
if (opts.leadId) params.lead_id = opts.leadId;
|
|
806
|
+
if (opts.contactId) params.contact_id = opts.contactId;
|
|
807
|
+
if (opts.direction) params.direction = opts.direction;
|
|
808
|
+
if (opts.outcome) params.outcome = opts.outcome;
|
|
809
|
+
const res = await client.get('/calls', { params });
|
|
810
|
+
printJSON(res.data);
|
|
811
|
+
} catch (err) {
|
|
812
|
+
handleError(err);
|
|
813
|
+
}
|
|
814
|
+
});
|
|
815
|
+
|
|
816
|
+
callsCmd
|
|
817
|
+
.command('get <id>')
|
|
818
|
+
.description('Get a call log by ID')
|
|
819
|
+
.action(async (id) => {
|
|
820
|
+
const globalOpts = program.opts();
|
|
821
|
+
const client = getClient(globalOpts);
|
|
822
|
+
try {
|
|
823
|
+
const res = await client.get(`/calls/${id}`);
|
|
824
|
+
printJSON(res.data);
|
|
825
|
+
} catch (err) {
|
|
826
|
+
handleError(err);
|
|
827
|
+
}
|
|
828
|
+
});
|
|
829
|
+
|
|
830
|
+
callsCmd
|
|
831
|
+
.command('update <id>')
|
|
832
|
+
.description('Update a call log')
|
|
833
|
+
.option('--outcome <outcome>', 'New outcome')
|
|
834
|
+
.option('--duration <seconds>', 'Duration in seconds')
|
|
835
|
+
.option('--notes <notes>', 'Call notes')
|
|
836
|
+
.action(async (id, opts) => {
|
|
837
|
+
const globalOpts = program.opts();
|
|
838
|
+
const client = getClient(globalOpts);
|
|
839
|
+
try {
|
|
840
|
+
const body = {};
|
|
841
|
+
if (opts.outcome !== undefined) body.outcome = opts.outcome;
|
|
842
|
+
if (opts.duration !== undefined) body.duration_seconds = parseInt(opts.duration);
|
|
843
|
+
if (opts.notes !== undefined) body.notes = opts.notes;
|
|
844
|
+
const res = await client.patch(`/calls/${id}`, body);
|
|
845
|
+
printJSON(res.data);
|
|
846
|
+
} catch (err) {
|
|
847
|
+
handleError(err);
|
|
848
|
+
}
|
|
849
|
+
});
|
|
850
|
+
|
|
851
|
+
callsCmd
|
|
852
|
+
.command('delete <id>')
|
|
853
|
+
.description('Soft-delete a call log')
|
|
854
|
+
.action(async (id) => {
|
|
855
|
+
const globalOpts = program.opts();
|
|
856
|
+
const client = getClient(globalOpts);
|
|
857
|
+
try {
|
|
858
|
+
const res = await client.delete(`/calls/${id}`);
|
|
859
|
+
printJSON(res.data);
|
|
860
|
+
} catch (err) {
|
|
861
|
+
handleError(err);
|
|
862
|
+
}
|
|
863
|
+
});
|
|
864
|
+
|
|
865
|
+
|
|
866
|
+
// ============================================================
|
|
867
|
+
// LEADS STAGE — pipeline stage management
|
|
868
|
+
// ============================================================
|
|
869
|
+
|
|
870
|
+
const leadsStageCmd = program
|
|
871
|
+
.command('leads-stage')
|
|
872
|
+
.description('Manage lead pipeline stages (sales board)');
|
|
873
|
+
|
|
874
|
+
leadsStageCmd
|
|
875
|
+
.command('get <lead-id>')
|
|
876
|
+
.description('Get the current pipeline stage of a lead')
|
|
877
|
+
.action(async (leadId) => {
|
|
878
|
+
const globalOpts = program.opts();
|
|
879
|
+
const client = getClient(globalOpts);
|
|
880
|
+
try {
|
|
881
|
+
const res = await client.get(`/leads/${leadId}/stage`);
|
|
882
|
+
printJSON(res.data);
|
|
883
|
+
} catch (err) {
|
|
884
|
+
handleError(err);
|
|
885
|
+
}
|
|
886
|
+
});
|
|
887
|
+
|
|
888
|
+
leadsStageCmd
|
|
889
|
+
.command('set <lead-id> <stage>')
|
|
890
|
+
.description('Set pipeline stage: new | qualified | proposal | negotiation | closed_won | closed_lost')
|
|
891
|
+
.option('--note <note>', 'Optional note about why stage changed')
|
|
892
|
+
.action(async (leadId, stage, opts) => {
|
|
893
|
+
const globalOpts = program.opts();
|
|
894
|
+
const client = getClient(globalOpts);
|
|
895
|
+
try {
|
|
896
|
+
const body = { stage };
|
|
897
|
+
if (opts.note) body.note = opts.note;
|
|
898
|
+
const res = await client.patch(`/leads/${leadId}/stage`, body);
|
|
899
|
+
printJSON(res.data);
|
|
900
|
+
} catch (err) {
|
|
901
|
+
handleError(err);
|
|
902
|
+
}
|
|
903
|
+
});
|
|
904
|
+
|
|
905
|
+
leadsStageCmd
|
|
906
|
+
.command('history <lead-id>')
|
|
907
|
+
.description('Get stage transition history for a lead')
|
|
908
|
+
.action(async (leadId) => {
|
|
909
|
+
const globalOpts = program.opts();
|
|
910
|
+
const client = getClient(globalOpts);
|
|
911
|
+
try {
|
|
912
|
+
const res = await client.get(`/leads/${leadId}/stage/history`);
|
|
913
|
+
printJSON(res.data);
|
|
914
|
+
} catch (err) {
|
|
915
|
+
handleError(err);
|
|
916
|
+
}
|
|
917
|
+
});
|
|
918
|
+
|
|
919
|
+
|
|
920
|
+
// ============================================================
|
|
921
|
+
// MEETINGS
|
|
922
|
+
// ============================================================
|
|
923
|
+
|
|
924
|
+
const meetingsCmd = program
|
|
925
|
+
.command('meetings')
|
|
926
|
+
.description('Manage booked meetings');
|
|
927
|
+
|
|
928
|
+
meetingsCmd
|
|
929
|
+
.command('create')
|
|
930
|
+
.description('Log a new meeting')
|
|
931
|
+
.requiredOption('--title <title>', 'Meeting title')
|
|
932
|
+
.requiredOption('--scheduled-at <iso>', 'Scheduled datetime (ISO8601, e.g. 2026-03-01T14:00:00Z)')
|
|
933
|
+
.option('--contact-id <id>', 'Contact ID')
|
|
934
|
+
.option('--lead-id <id>', 'Lead ID')
|
|
935
|
+
.option('--duration <minutes>', 'Duration in minutes')
|
|
936
|
+
.option('--location <location>', 'Physical location or address')
|
|
937
|
+
.option('--video-link <url>', 'Video call link (Zoom, Meet, etc.)')
|
|
938
|
+
.option('--notes <notes>', 'Meeting notes or agenda')
|
|
939
|
+
.option('--outcome <outcome>', 'scheduled | completed | cancelled | no_show')
|
|
940
|
+
.action(async (opts) => {
|
|
941
|
+
const globalOpts = program.opts();
|
|
942
|
+
const client = getClient(globalOpts);
|
|
943
|
+
try {
|
|
944
|
+
const body = {
|
|
945
|
+
title: opts.title,
|
|
946
|
+
scheduled_at: opts.scheduledAt,
|
|
947
|
+
};
|
|
948
|
+
if (opts.contactId) body.contact_id = opts.contactId;
|
|
949
|
+
if (opts.leadId) body.lead_id = opts.leadId;
|
|
950
|
+
if (opts.duration) body.duration_minutes = parseInt(opts.duration);
|
|
951
|
+
if (opts.location) body.location = opts.location;
|
|
952
|
+
if (opts.videoLink) body.video_link = opts.videoLink;
|
|
953
|
+
if (opts.notes) body.notes = opts.notes;
|
|
954
|
+
if (opts.outcome) body.outcome = opts.outcome;
|
|
955
|
+
const res = await client.post('/meetings', body);
|
|
956
|
+
printJSON(res.data);
|
|
957
|
+
} catch (err) {
|
|
958
|
+
handleError(err);
|
|
959
|
+
}
|
|
960
|
+
});
|
|
961
|
+
|
|
962
|
+
meetingsCmd
|
|
963
|
+
.command('list')
|
|
964
|
+
.description('List meetings')
|
|
965
|
+
.option('--contact-id <id>', 'Filter by contact ID')
|
|
966
|
+
.option('--lead-id <id>', 'Filter by lead ID')
|
|
967
|
+
.option('--outcome <outcome>', 'Filter by outcome')
|
|
968
|
+
.option('--scheduled-after <iso>', 'Filter meetings scheduled after date')
|
|
969
|
+
.option('--scheduled-before <iso>', 'Filter meetings scheduled before date')
|
|
970
|
+
.option('--page <n>', 'Page number', '1')
|
|
971
|
+
.option('--per-page <n>', 'Results per page', '20')
|
|
972
|
+
.action(async (opts) => {
|
|
973
|
+
const globalOpts = program.opts();
|
|
974
|
+
const client = getClient(globalOpts);
|
|
975
|
+
try {
|
|
976
|
+
const params = { page: opts.page, per_page: opts.perPage };
|
|
977
|
+
if (opts.contactId) params.contact_id = opts.contactId;
|
|
978
|
+
if (opts.leadId) params.lead_id = opts.leadId;
|
|
979
|
+
if (opts.outcome) params.outcome = opts.outcome;
|
|
980
|
+
if (opts.scheduledAfter) params.scheduled_after = opts.scheduledAfter;
|
|
981
|
+
if (opts.scheduledBefore) params.scheduled_before = opts.scheduledBefore;
|
|
982
|
+
const res = await client.get('/meetings', { params });
|
|
983
|
+
printJSON(res.data);
|
|
984
|
+
} catch (err) {
|
|
985
|
+
handleError(err);
|
|
986
|
+
}
|
|
987
|
+
});
|
|
988
|
+
|
|
989
|
+
meetingsCmd
|
|
990
|
+
.command('get <id>')
|
|
991
|
+
.description('Get a meeting by ID')
|
|
992
|
+
.action(async (id) => {
|
|
993
|
+
const globalOpts = program.opts();
|
|
994
|
+
const client = getClient(globalOpts);
|
|
995
|
+
try {
|
|
996
|
+
const res = await client.get(`/meetings/${id}`);
|
|
997
|
+
printJSON(res.data);
|
|
998
|
+
} catch (err) {
|
|
999
|
+
handleError(err);
|
|
1000
|
+
}
|
|
1001
|
+
});
|
|
1002
|
+
|
|
1003
|
+
meetingsCmd
|
|
1004
|
+
.command('update <id>')
|
|
1005
|
+
.description('Update a meeting')
|
|
1006
|
+
.option('--title <title>', 'New title')
|
|
1007
|
+
.option('--scheduled-at <iso>', 'New scheduled time (ISO8601)')
|
|
1008
|
+
.option('--duration <minutes>', 'Duration in minutes')
|
|
1009
|
+
.option('--location <location>', 'Location')
|
|
1010
|
+
.option('--video-link <url>', 'Video link')
|
|
1011
|
+
.option('--notes <notes>', 'Notes')
|
|
1012
|
+
.option('--outcome <outcome>', 'scheduled | completed | cancelled | no_show')
|
|
1013
|
+
.action(async (id, opts) => {
|
|
1014
|
+
const globalOpts = program.opts();
|
|
1015
|
+
const client = getClient(globalOpts);
|
|
1016
|
+
try {
|
|
1017
|
+
const body = {};
|
|
1018
|
+
if (opts.title !== undefined) body.title = opts.title;
|
|
1019
|
+
if (opts.scheduledAt !== undefined) body.scheduled_at = opts.scheduledAt;
|
|
1020
|
+
if (opts.duration !== undefined) body.duration_minutes = parseInt(opts.duration);
|
|
1021
|
+
if (opts.location !== undefined) body.location = opts.location;
|
|
1022
|
+
if (opts.videoLink !== undefined) body.video_link = opts.videoLink;
|
|
1023
|
+
if (opts.notes !== undefined) body.notes = opts.notes;
|
|
1024
|
+
if (opts.outcome !== undefined) body.outcome = opts.outcome;
|
|
1025
|
+
const res = await client.patch(`/meetings/${id}`, body);
|
|
1026
|
+
printJSON(res.data);
|
|
1027
|
+
} catch (err) {
|
|
1028
|
+
handleError(err);
|
|
1029
|
+
}
|
|
1030
|
+
});
|
|
1031
|
+
|
|
1032
|
+
meetingsCmd
|
|
1033
|
+
.command('cancel <id>')
|
|
1034
|
+
.description('Cancel a meeting')
|
|
1035
|
+
.option('--reason <reason>', 'Cancellation reason')
|
|
1036
|
+
.action(async (id, opts) => {
|
|
1037
|
+
const globalOpts = program.opts();
|
|
1038
|
+
const client = getClient(globalOpts);
|
|
1039
|
+
try {
|
|
1040
|
+
const body = {};
|
|
1041
|
+
if (opts.reason) body.reason = opts.reason;
|
|
1042
|
+
const res = await client.delete(`/meetings/${id}`, { data: body });
|
|
1043
|
+
printJSON(res.data);
|
|
1044
|
+
} catch (err) {
|
|
1045
|
+
handleError(err);
|
|
1046
|
+
}
|
|
1047
|
+
});
|
|
1048
|
+
|
|
1049
|
+
// ============================================================
|
|
1050
|
+
// EMAILS
|
|
1051
|
+
// ============================================================
|
|
1052
|
+
|
|
1053
|
+
const emailsCmd = program
|
|
1054
|
+
.command('emails')
|
|
1055
|
+
.description('Log and retrieve email interactions');
|
|
1056
|
+
|
|
1057
|
+
emailsCmd
|
|
1058
|
+
.command('log')
|
|
1059
|
+
.description('Log an email interaction (sent or received)')
|
|
1060
|
+
.requiredOption('--direction <dir>', 'sent or received')
|
|
1061
|
+
.requiredOption('--subject <subject>', 'Email subject line')
|
|
1062
|
+
.option('--contact-id <id>', 'Contact ID')
|
|
1063
|
+
.option('--lead-id <id>', 'Lead ID')
|
|
1064
|
+
.option('--body <summary>', 'Body summary (max 1000 chars)')
|
|
1065
|
+
.option('--thread-id <id>', 'Thread ID for grouping related emails')
|
|
1066
|
+
.option('--email-time <iso>', 'When the email was sent/received (ISO8601, defaults to now)')
|
|
1067
|
+
.action(async (opts) => {
|
|
1068
|
+
const globalOpts = program.opts();
|
|
1069
|
+
const client = getClient(globalOpts);
|
|
1070
|
+
try {
|
|
1071
|
+
const body = {
|
|
1072
|
+
direction: opts.direction,
|
|
1073
|
+
subject: opts.subject,
|
|
1074
|
+
};
|
|
1075
|
+
if (opts.contactId) body.contact_id = opts.contactId;
|
|
1076
|
+
if (opts.leadId) body.lead_id = opts.leadId;
|
|
1077
|
+
if (opts.body) body.body_summary = opts.body;
|
|
1078
|
+
if (opts.threadId) body.thread_id = opts.threadId;
|
|
1079
|
+
if (opts.emailTime) body.email_timestamp = opts.emailTime;
|
|
1080
|
+
const res = await client.post('/emails', body);
|
|
1081
|
+
printJSON(res.data);
|
|
1082
|
+
} catch (err) {
|
|
1083
|
+
handleError(err);
|
|
1084
|
+
}
|
|
1085
|
+
});
|
|
1086
|
+
|
|
1087
|
+
emailsCmd
|
|
1088
|
+
.command('list')
|
|
1089
|
+
.description('List email logs')
|
|
1090
|
+
.option('--contact-id <id>', 'Filter by contact ID')
|
|
1091
|
+
.option('--lead-id <id>', 'Filter by lead ID')
|
|
1092
|
+
.option('--direction <dir>', 'Filter by direction (sent/received)')
|
|
1093
|
+
.option('--thread-id <id>', 'Filter by thread ID')
|
|
1094
|
+
.option('--after <iso>', 'Filter emails after this date')
|
|
1095
|
+
.option('--before <iso>', 'Filter emails before this date')
|
|
1096
|
+
.option('--page <n>', 'Page number', '1')
|
|
1097
|
+
.option('--per-page <n>', 'Results per page', '20')
|
|
1098
|
+
.action(async (opts) => {
|
|
1099
|
+
const globalOpts = program.opts();
|
|
1100
|
+
const client = getClient(globalOpts);
|
|
1101
|
+
try {
|
|
1102
|
+
const params = { page: opts.page, per_page: opts.perPage };
|
|
1103
|
+
if (opts.contactId) params.contact_id = opts.contactId;
|
|
1104
|
+
if (opts.leadId) params.lead_id = opts.leadId;
|
|
1105
|
+
if (opts.direction) params.direction = opts.direction;
|
|
1106
|
+
if (opts.threadId) params.thread_id = opts.threadId;
|
|
1107
|
+
if (opts.after) params.after = opts.after;
|
|
1108
|
+
if (opts.before) params.before = opts.before;
|
|
1109
|
+
const res = await client.get('/emails', { params });
|
|
1110
|
+
printJSON(res.data);
|
|
1111
|
+
} catch (err) {
|
|
1112
|
+
handleError(err);
|
|
1113
|
+
}
|
|
1114
|
+
});
|
|
1115
|
+
|
|
1116
|
+
emailsCmd
|
|
1117
|
+
.command('get <id>')
|
|
1118
|
+
.description('Get an email log entry by ID')
|
|
1119
|
+
.action(async (id) => {
|
|
1120
|
+
const globalOpts = program.opts();
|
|
1121
|
+
const client = getClient(globalOpts);
|
|
1122
|
+
try {
|
|
1123
|
+
const res = await client.get(`/emails/${id}`);
|
|
1124
|
+
printJSON(res.data);
|
|
1125
|
+
} catch (err) {
|
|
1126
|
+
handleError(err);
|
|
1127
|
+
}
|
|
1128
|
+
});
|
|
1129
|
+
|
|
1130
|
+
emailsCmd
|
|
1131
|
+
.command('thread <thread-id>')
|
|
1132
|
+
.description('Get all emails in a thread by thread ID')
|
|
1133
|
+
.action(async (threadId) => {
|
|
1134
|
+
const globalOpts = program.opts();
|
|
1135
|
+
const client = getClient(globalOpts);
|
|
1136
|
+
try {
|
|
1137
|
+
const res = await client.get(`/emails/thread/${threadId}`);
|
|
1138
|
+
printJSON(res.data);
|
|
1139
|
+
} catch (err) {
|
|
1140
|
+
handleError(err);
|
|
1141
|
+
}
|
|
1142
|
+
});
|
|
1143
|
+
|
|
1144
|
+
|
|
599
1145
|
program.parse(process.argv);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startanaicompany/crm",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"description": "AI-first CRM CLI
|
|
3
|
+
"version": "2.1.0",
|
|
4
|
+
"description": "AI-first CRM CLI \u2014 manage leads and API keys from the terminal",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"saac_crm": "./index.js"
|
|
@@ -9,7 +9,14 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"test": "echo \"No tests yet\""
|
|
11
11
|
},
|
|
12
|
-
"keywords": [
|
|
12
|
+
"keywords": [
|
|
13
|
+
"crm",
|
|
14
|
+
"ai",
|
|
15
|
+
"leads",
|
|
16
|
+
"api",
|
|
17
|
+
"saac",
|
|
18
|
+
"agent"
|
|
19
|
+
],
|
|
13
20
|
"license": "MIT",
|
|
14
21
|
"repository": {
|
|
15
22
|
"type": "git",
|