Skip to content

Commit f66eb99

Browse files
authored
Merge pull request #2 from timdev-ger/v1.0.3
Add WhatsApp, custom object, and report resources
2 parents 2fa39a2 + 85da76a commit f66eb99

5 files changed

Lines changed: 520 additions & 10 deletions

File tree

lib/close.com.d.ts

Lines changed: 155 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,24 @@ declare module 'closecrm-node' {
196196
[key: string]: any;
197197
}
198198

199+
export interface WhatsAppMessage extends Activity {
200+
_type: 'WhatsAppMessage';
201+
external_whatsapp_message_id: string;
202+
message_markdown: string;
203+
message_html?: string;
204+
direction?: 'incoming' | 'outgoing';
205+
status?: string;
206+
response_to_id?: string;
207+
integration_link?: string;
208+
attachments?: Array<{
209+
url: string;
210+
filename: string;
211+
content_type: string;
212+
size?: number;
213+
}>;
214+
[key: string]: any;
215+
}
216+
199217
export interface Task {
200218
id: string;
201219
lead_id?: string;
@@ -221,13 +239,41 @@ declare module 'closecrm-node' {
221239
accepts_multiple_values?: boolean;
222240
editable_with_roles?: string[];
223241
required?: boolean;
242+
custom_object_type_id?: string;
224243
organization_id: string;
225244
created_by?: string;
226245
date_created: string;
227246
date_updated: string;
228247
[key: string]: any;
229248
}
230249

250+
export interface CustomObjectType {
251+
id: string;
252+
name: string;
253+
name_plural: string;
254+
description?: string;
255+
api_create_only?: boolean;
256+
editable_with_roles?: string[];
257+
fields?: CustomField[];
258+
back_reference_fields?: CustomField[];
259+
organization_id: string;
260+
date_created: string;
261+
date_updated: string;
262+
[key: string]: any;
263+
}
264+
265+
export interface CustomObject {
266+
id: string;
267+
custom_object_type_id: string;
268+
lead_id: string;
269+
name: string;
270+
custom?: Record<string, any>;
271+
date_created: string;
272+
date_updated: string;
273+
organization_id: string;
274+
[key: string]: any;
275+
}
276+
231277
export interface User {
232278
id: string;
233279
email: string;
@@ -438,13 +484,22 @@ declare module 'closecrm-node' {
438484
delete(id: string): Promise<void>;
439485
}
440486

487+
export interface WhatsAppMessageResource {
488+
search(options?: SearchOptions): Promise<PaginatedResponse<WhatsAppMessage>>;
489+
create(data: Partial<WhatsAppMessage>, queryParams?: { send_to_inbox?: boolean }): Promise<WhatsAppMessage>;
490+
read(id: string): Promise<WhatsAppMessage>;
491+
update(id: string, data: Partial<WhatsAppMessage>): Promise<WhatsAppMessage>;
492+
delete(id: string): Promise<void>;
493+
}
494+
441495
export interface ActivityResource {
442496
search(options?: SearchOptions): Promise<PaginatedResponse<Activity>>;
443497
note: NoteResource;
444498
email: EmailResource;
445499
call: CallResource;
446500
sms: SMSResource;
447501
meeting: MeetingResource;
502+
whatsapp_message: WhatsAppMessageResource;
448503
}
449504

450505
export interface OpportunityResource {
@@ -476,6 +531,7 @@ declare module 'closecrm-node' {
476531
contact: CustomFieldSubResource;
477532
opportunity: CustomFieldSubResource;
478533
activity: CustomFieldSubResource;
534+
custom_object_type: CustomFieldSubResource;
479535
}
480536

481537
export interface CustomActivityResource {
@@ -486,6 +542,22 @@ declare module 'closecrm-node' {
486542
delete(type: string, id: string): Promise<void>;
487543
}
488544

545+
export interface CustomObjectTypeResource {
546+
list(options?: SearchOptions): Promise<PaginatedResponse<CustomObjectType>>;
547+
create(data: Partial<CustomObjectType>): Promise<CustomObjectType>;
548+
read(id: string): Promise<CustomObjectType>;
549+
update(id: string, data: Partial<CustomObjectType>): Promise<CustomObjectType>;
550+
delete(id: string): Promise<void>;
551+
}
552+
553+
export interface CustomObjectResource {
554+
list(options?: SearchOptions): Promise<PaginatedResponse<CustomObject>>;
555+
create(data: Partial<CustomObject>): Promise<CustomObject>;
556+
read(id: string): Promise<CustomObject>;
557+
update(id: string, data: Partial<CustomObject>): Promise<CustomObject>;
558+
delete(id: string): Promise<void>;
559+
}
560+
489561
export interface UserResource {
490562
me(): Promise<User>;
491563
list(options?: SearchOptions): Promise<PaginatedResponse<User>>;
@@ -553,8 +625,87 @@ declare module 'closecrm-node' {
553625
}
554626

555627
export interface ReportResource {
556-
list(options?: SearchOptions): Promise<PaginatedResponse<Report>>;
557-
read(id: string, options?: SearchOptions): Promise<Report>;
628+
// List predefined metrics used in activity reports
629+
activity_metrics(): Promise<PaginatedResponse<any>>;
630+
631+
// Get an activity report
632+
activity(data: {
633+
datetime_range?: { start: string; end: string };
634+
relative_range?: string;
635+
query?: any;
636+
users?: string[];
637+
type: 'overview' | 'comparison';
638+
metrics: string[];
639+
}): Promise<any>;
640+
641+
// Get sent emails report grouped by template
642+
sent_emails(organizationId: string, options?: {
643+
user_id?: string;
644+
date_start?: string;
645+
date_end?: string;
646+
}): Promise<any>;
647+
648+
// Get lead status change report
649+
lead_statuses(organizationId: string, options?: {
650+
date_start?: string;
651+
date_end?: string;
652+
query?: string;
653+
smart_view_id?: string;
654+
}): Promise<any>;
655+
656+
// Get opportunity status change report
657+
opportunity_statuses(organizationId: string, options?: {
658+
user_id?: string;
659+
date_start?: string;
660+
date_end?: string;
661+
query?: string;
662+
smart_view_id?: string;
663+
}): Promise<any>;
664+
665+
// Get custom report
666+
custom(organizationId: string, options?: {
667+
query?: string;
668+
x?: string;
669+
y?: string;
670+
interval?: string;
671+
transform_y?: 'sum' | 'avg' | 'min' | 'max';
672+
group_by?: string;
673+
start?: string;
674+
end?: string;
675+
}): Promise<any>;
676+
677+
// Get custom report fields
678+
custom_fields(): Promise<any>;
679+
680+
// Get opportunity funnel report (totals)
681+
funnel_totals(data: {
682+
pipeline: string;
683+
type: 'created-cohort' | 'active-stage-cohort';
684+
report_relative_range?: string;
685+
report_datetime_range?: { start: string; end: string };
686+
cohort_relative_range?: string;
687+
cohort_datetime_range?: { start: string; end: string };
688+
compared_relative_range?: string;
689+
compared_datetime_range?: string;
690+
compared_custom_range?: { start: string; end: string };
691+
query?: any;
692+
users?: string[];
693+
}): Promise<any>;
694+
695+
// Get opportunity funnel report (stages)
696+
funnel_stages(data: {
697+
pipeline: string;
698+
type: 'created-cohort' | 'active-stage-cohort';
699+
report_relative_range?: string;
700+
report_datetime_range?: { start: string; end: string };
701+
cohort_relative_range?: string;
702+
cohort_datetime_range?: { start: string; end: string };
703+
compared_relative_range?: string;
704+
compared_datetime_range?: string;
705+
compared_custom_range?: { start: string; end: string };
706+
query?: any;
707+
users?: string[];
708+
}): Promise<any>;
558709
}
559710

560711
export interface EventResource {
@@ -618,6 +769,8 @@ declare module 'closecrm-node' {
618769
task: TaskResource;
619770
custom_field: CustomFieldResource;
620771
custom_activity: CustomActivityResource;
772+
custom_object_type: CustomObjectTypeResource;
773+
custom_object: CustomObjectResource;
621774
user: UserResource;
622775
organization: OrganizationResource;
623776
pipeline: PipelineResource;

lib/close.com.js

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Closecom {
1414
this._initTasks();
1515
this._initCustomFields();
1616
this._initCustomActivities();
17+
this._initCustomObjects();
1718
this._initUsers();
1819
this._initOrganizations();
1920
this._initPipelines();
@@ -138,6 +139,17 @@ class Closecom {
138139
read: (id) => this._get(`/activity/meeting/${id}/`),
139140
update: (id, data) => this._put(`/activity/meeting/${id}/`, data),
140141
delete: (id) => this._delete(`/activity/meeting/${id}/`)
142+
},
143+
144+
whatsapp_message: {
145+
search: (options = {}) => this._get('/activity/whatsapp_message/', this._normalizeSearchParams({ ...options })),
146+
create: (data, queryParams = {}) => {
147+
const path = '/activity/whatsapp_message/';
148+
return this._request({ method: 'POST', path, body: data, params: queryParams });
149+
},
150+
read: (id) => this._get(`/activity/whatsapp_message/${id}/`),
151+
update: (id, data) => this._put(`/activity/whatsapp_message/${id}/`, data),
152+
delete: (id) => this._delete(`/activity/whatsapp_message/${id}/`)
141153
}
142154
};
143155
}
@@ -194,6 +206,14 @@ class Closecom {
194206
read: (id) => this._get(`/custom_field/activity/${id}/`),
195207
update: (id, data) => this._put(`/custom_field/activity/${id}/`, data),
196208
delete: (id) => this._delete(`/custom_field/activity/${id}/`)
209+
},
210+
211+
custom_object_type: {
212+
list: () => this._get('/custom_field/custom_object_type/'),
213+
create: (data) => this._post('/custom_field/custom_object_type/', data),
214+
read: (id) => this._get(`/custom_field/custom_object_type/${id}/`),
215+
update: (id, data) => this._put(`/custom_field/custom_object_type/${id}/`, data),
216+
delete: (id) => this._delete(`/custom_field/custom_object_type/${id}/`)
197217
}
198218
};
199219
}
@@ -208,6 +228,24 @@ class Closecom {
208228
};
209229
}
210230

231+
_initCustomObjects() {
232+
this.custom_object_type = {
233+
list: (options = {}) => this._get('/custom_object_type/', this._normalizeSearchParams({ ...options })),
234+
create: (data) => this._post('/custom_object_type/', data),
235+
read: (id) => this._get(`/custom_object_type/${id}/`),
236+
update: (id, data) => this._put(`/custom_object_type/${id}/`, data),
237+
delete: (id) => this._delete(`/custom_object_type/${id}/`)
238+
};
239+
240+
this.custom_object = {
241+
list: (options = {}) => this._get('/custom_object/', this._normalizeSearchParams({ ...options })),
242+
create: (data) => this._post('/custom_object/', data),
243+
read: (id) => this._get(`/custom_object/${id}/`),
244+
update: (id, data) => this._put(`/custom_object/${id}/`, data),
245+
delete: (id) => this._delete(`/custom_object/${id}/`)
246+
};
247+
}
248+
211249
_initUsers() {
212250
this.user = {
213251
me: () => this._get('/me/'),
@@ -299,8 +337,36 @@ class Closecom {
299337

300338
_initReports() {
301339
this.report = {
302-
list: (options = {}) => this._get('/report/', this._normalizeSearchParams({ ...options })),
303-
read: (id, options = {}) => this._get(`/report/${id}/`, this._normalizeSearchParams({ ...options }))
340+
// List predefined metrics used in activity reports
341+
activity_metrics: () => this._get('/report/activity/metrics/'),
342+
343+
// Get an activity report (POST)
344+
activity: (data) => this._post('/report/activity/', data),
345+
346+
// Get sent emails report grouped by template
347+
sent_emails: (organizationId, options = {}) =>
348+
this._get(`/report/sent_emails/${organizationId}/`, this._normalizeSearchParams({ ...options })),
349+
350+
// Get lead status change report
351+
lead_statuses: (organizationId, options = {}) =>
352+
this._get(`/report/statuses/lead/${organizationId}/`, this._normalizeSearchParams({ ...options })),
353+
354+
// Get opportunity status change report
355+
opportunity_statuses: (organizationId, options = {}) =>
356+
this._get(`/report/statuses/opportunity/${organizationId}/`, this._normalizeSearchParams({ ...options })),
357+
358+
// Get custom report
359+
custom: (organizationId, options = {}) =>
360+
this._get(`/report/custom/${organizationId}/`, this._normalizeSearchParams({ ...options })),
361+
362+
// Get custom report fields
363+
custom_fields: () => this._get('/report/custom/fields/'),
364+
365+
// Get opportunity funnel report (totals)
366+
funnel_totals: (data) => this._post('/report/funnel/opportunity/totals/', data),
367+
368+
// Get opportunity funnel report (stages)
369+
funnel_stages: (data) => this._post('/report/funnel/opportunity/stages/', data)
304370
};
305371
}
306372

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "closecrm-node",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "Unofficial Close.com API client for Node.js with TypeScript support",
55
"main": "lib/close.com.js",
66
"types": "lib/close.com.d.ts",

0 commit comments

Comments
 (0)