@kyoji2/intercom-cli 0.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/LICENSE +21 -0
- package/README.md +236 -0
- package/dist/index.js +25859 -0
- package/package.json +66 -0
- package/src/client.ts +132 -0
- package/src/commands/admins.ts +77 -0
- package/src/commands/articles.ts +229 -0
- package/src/commands/auth.ts +115 -0
- package/src/commands/companies.ts +176 -0
- package/src/commands/contacts.ts +410 -0
- package/src/commands/conversations.ts +350 -0
- package/src/commands/events.ts +91 -0
- package/src/commands/index.ts +82 -0
- package/src/commands/overview.ts +128 -0
- package/src/commands/tags.ts +112 -0
- package/src/index.ts +689 -0
- package/src/utils/config.ts +114 -0
- package/src/utils/index.ts +12 -0
- package/src/utils/output.ts +37 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import ora from "ora";
|
|
2
|
+
import { createClient, handleIntercomError } from "../client.ts";
|
|
3
|
+
import { CLIError, type GlobalOptions, getTokenAsync, output } from "../utils/index.ts";
|
|
4
|
+
|
|
5
|
+
export interface CompanyCreateOptions extends GlobalOptions {
|
|
6
|
+
companyId: string;
|
|
7
|
+
name: string;
|
|
8
|
+
plan?: string;
|
|
9
|
+
size?: string;
|
|
10
|
+
website?: string;
|
|
11
|
+
json?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface CompanyGetOptions extends GlobalOptions {
|
|
15
|
+
id: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface CompanyListOptions extends GlobalOptions {
|
|
19
|
+
limit?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface CompanyUpdateOptions extends GlobalOptions {
|
|
23
|
+
id: string;
|
|
24
|
+
json: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function requireToken(): Promise<string> {
|
|
28
|
+
const token = await getTokenAsync();
|
|
29
|
+
if (!token) {
|
|
30
|
+
throw new CLIError("Not logged in", 401, "Run 'intercom login' to authenticate.");
|
|
31
|
+
}
|
|
32
|
+
return token;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function cmdCompanyCreate(options: CompanyCreateOptions): Promise<void> {
|
|
36
|
+
const token = await requireToken();
|
|
37
|
+
const spinner = ora("Creating company...").start();
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
const client = createClient({ token, dryRun: options.dryRun });
|
|
41
|
+
|
|
42
|
+
let payload: Record<string, unknown> = {
|
|
43
|
+
company_id: options.companyId,
|
|
44
|
+
name: options.name,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
if (options.json) {
|
|
48
|
+
const parsed = JSON.parse(options.json);
|
|
49
|
+
payload = { ...payload, ...parsed };
|
|
50
|
+
} else {
|
|
51
|
+
if (options.plan) payload.plan = options.plan;
|
|
52
|
+
if (options.size) payload.size = Number.parseInt(options.size, 10);
|
|
53
|
+
if (options.website) payload.website = options.website;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const company = await client.companies.createOrUpdate(
|
|
57
|
+
payload as Parameters<typeof client.companies.createOrUpdate>[0],
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
spinner.succeed("Company created");
|
|
61
|
+
|
|
62
|
+
output(
|
|
63
|
+
{
|
|
64
|
+
id: company.id,
|
|
65
|
+
company_id: company.company_id,
|
|
66
|
+
name: company.name,
|
|
67
|
+
plan: company.plan,
|
|
68
|
+
size: company.size,
|
|
69
|
+
website: company.website,
|
|
70
|
+
created_at: company.created_at,
|
|
71
|
+
},
|
|
72
|
+
options.format,
|
|
73
|
+
);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
spinner.fail("Failed to create company");
|
|
76
|
+
handleIntercomError(error);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export async function cmdCompanyGet(options: CompanyGetOptions): Promise<void> {
|
|
81
|
+
const token = await requireToken();
|
|
82
|
+
const spinner = ora("Fetching company...").start();
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
const client = createClient({ token, dryRun: options.dryRun });
|
|
86
|
+
const company = await client.companies.find({ company_id: options.id });
|
|
87
|
+
|
|
88
|
+
spinner.stop();
|
|
89
|
+
|
|
90
|
+
output(
|
|
91
|
+
{
|
|
92
|
+
id: company.id,
|
|
93
|
+
company_id: company.company_id,
|
|
94
|
+
name: company.name,
|
|
95
|
+
plan: company.plan,
|
|
96
|
+
size: company.size,
|
|
97
|
+
website: company.website,
|
|
98
|
+
industry: company.industry,
|
|
99
|
+
created_at: company.created_at,
|
|
100
|
+
updated_at: company.updated_at,
|
|
101
|
+
session_count: company.session_count,
|
|
102
|
+
user_count: company.user_count,
|
|
103
|
+
monthly_spend: company.monthly_spend,
|
|
104
|
+
custom_attributes: company.custom_attributes,
|
|
105
|
+
tags: company.tags,
|
|
106
|
+
segments: company.segments,
|
|
107
|
+
},
|
|
108
|
+
options.format,
|
|
109
|
+
);
|
|
110
|
+
} catch (error) {
|
|
111
|
+
spinner.fail("Failed to fetch company");
|
|
112
|
+
handleIntercomError(error);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export async function cmdCompanyList(options: CompanyListOptions): Promise<void> {
|
|
117
|
+
const token = await requireToken();
|
|
118
|
+
const spinner = ora("Listing companies...").start();
|
|
119
|
+
|
|
120
|
+
try {
|
|
121
|
+
const client = createClient({ token, dryRun: options.dryRun });
|
|
122
|
+
const limit = options.limit ? Number.parseInt(options.limit, 10) : 25;
|
|
123
|
+
|
|
124
|
+
const result = await client.companies.list({ per_page: Math.min(limit, 50) });
|
|
125
|
+
|
|
126
|
+
spinner.stop();
|
|
127
|
+
|
|
128
|
+
const companies: unknown[] = [];
|
|
129
|
+
for await (const company of result) {
|
|
130
|
+
companies.push({
|
|
131
|
+
id: company.id,
|
|
132
|
+
company_id: company.company_id,
|
|
133
|
+
name: company.name,
|
|
134
|
+
plan: company.plan,
|
|
135
|
+
size: company.size,
|
|
136
|
+
user_count: company.user_count,
|
|
137
|
+
created_at: company.created_at,
|
|
138
|
+
});
|
|
139
|
+
if (companies.length >= limit) break;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
output({ total: companies.length, companies }, options.format);
|
|
143
|
+
} catch (error) {
|
|
144
|
+
spinner.fail("Failed to list companies");
|
|
145
|
+
handleIntercomError(error);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export async function cmdCompanyUpdate(options: CompanyUpdateOptions): Promise<void> {
|
|
150
|
+
const token = await requireToken();
|
|
151
|
+
const spinner = ora("Updating company...").start();
|
|
152
|
+
|
|
153
|
+
try {
|
|
154
|
+
const client = createClient({ token, dryRun: options.dryRun });
|
|
155
|
+
|
|
156
|
+
const parsed = JSON.parse(options.json);
|
|
157
|
+
const payload = { company_id: options.id, ...parsed };
|
|
158
|
+
|
|
159
|
+
const company = await client.companies.update(payload as Parameters<typeof client.companies.update>[0]);
|
|
160
|
+
|
|
161
|
+
spinner.succeed("Company updated");
|
|
162
|
+
|
|
163
|
+
output(
|
|
164
|
+
{
|
|
165
|
+
id: company.id,
|
|
166
|
+
company_id: company.company_id,
|
|
167
|
+
name: company.name,
|
|
168
|
+
updated_at: company.updated_at,
|
|
169
|
+
},
|
|
170
|
+
options.format,
|
|
171
|
+
);
|
|
172
|
+
} catch (error) {
|
|
173
|
+
spinner.fail("Failed to update company");
|
|
174
|
+
handleIntercomError(error);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
import ora from "ora";
|
|
2
|
+
import { createClient, handleIntercomError } from "../client.ts";
|
|
3
|
+
import { CLIError, type GlobalOptions, getTokenAsync, output } from "../utils/index.ts";
|
|
4
|
+
|
|
5
|
+
export interface ContactCreateOptions extends GlobalOptions {
|
|
6
|
+
email?: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
phone?: string;
|
|
9
|
+
userId?: string;
|
|
10
|
+
json?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ContactGetOptions extends GlobalOptions {
|
|
14
|
+
id: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ContactUpdateOptions extends GlobalOptions {
|
|
18
|
+
id: string;
|
|
19
|
+
name?: string;
|
|
20
|
+
email?: string;
|
|
21
|
+
phone?: string;
|
|
22
|
+
json?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ContactDeleteOptions extends GlobalOptions {
|
|
26
|
+
id: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface ContactSearchOptions extends GlobalOptions {
|
|
30
|
+
email?: string;
|
|
31
|
+
json?: string;
|
|
32
|
+
limit?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface ContactListOptions extends GlobalOptions {
|
|
36
|
+
limit?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface ContactNoteOptions extends GlobalOptions {
|
|
40
|
+
id: string;
|
|
41
|
+
body: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface ContactNotesListOptions extends GlobalOptions {
|
|
45
|
+
id: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface ContactTagOptions extends GlobalOptions {
|
|
49
|
+
contactId: string;
|
|
50
|
+
tagId: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface ContactAttachCompanyOptions extends GlobalOptions {
|
|
54
|
+
contactId: string;
|
|
55
|
+
companyId: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function requireToken(): Promise<string> {
|
|
59
|
+
const token = await getTokenAsync();
|
|
60
|
+
if (!token) {
|
|
61
|
+
throw new CLIError("Not logged in", 401, "Run 'intercom login' to authenticate.");
|
|
62
|
+
}
|
|
63
|
+
return token;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function cmdContactCreate(options: ContactCreateOptions): Promise<void> {
|
|
67
|
+
const token = await requireToken();
|
|
68
|
+
const spinner = ora("Creating contact...").start();
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
const client = createClient({ token, dryRun: options.dryRun });
|
|
72
|
+
|
|
73
|
+
let payload: Record<string, unknown>;
|
|
74
|
+
if (options.json) {
|
|
75
|
+
payload = JSON.parse(options.json);
|
|
76
|
+
} else {
|
|
77
|
+
payload = {};
|
|
78
|
+
if (options.email) payload.email = options.email;
|
|
79
|
+
if (options.name) payload.name = options.name;
|
|
80
|
+
if (options.phone) payload.phone = options.phone;
|
|
81
|
+
if (options.userId) payload.external_id = options.userId;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const createPayload = { ...payload, role: (payload.role as string) ?? "user" };
|
|
85
|
+
const contact = await client.contacts.create(createPayload as Parameters<typeof client.contacts.create>[0]);
|
|
86
|
+
|
|
87
|
+
spinner.succeed("Contact created");
|
|
88
|
+
|
|
89
|
+
output(
|
|
90
|
+
{
|
|
91
|
+
id: contact.id,
|
|
92
|
+
external_id: contact.external_id,
|
|
93
|
+
email: contact.email,
|
|
94
|
+
name: contact.name,
|
|
95
|
+
phone: contact.phone,
|
|
96
|
+
role: contact.role,
|
|
97
|
+
created_at: contact.created_at,
|
|
98
|
+
},
|
|
99
|
+
options.format,
|
|
100
|
+
);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
spinner.fail("Failed to create contact");
|
|
103
|
+
handleIntercomError(error);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export async function cmdContactGet(options: ContactGetOptions): Promise<void> {
|
|
108
|
+
const token = await requireToken();
|
|
109
|
+
const spinner = ora("Fetching contact...").start();
|
|
110
|
+
|
|
111
|
+
try {
|
|
112
|
+
const client = createClient({ token, dryRun: options.dryRun });
|
|
113
|
+
const contact = await client.contacts.find({ contact_id: options.id });
|
|
114
|
+
|
|
115
|
+
spinner.stop();
|
|
116
|
+
|
|
117
|
+
output(
|
|
118
|
+
{
|
|
119
|
+
id: contact.id,
|
|
120
|
+
external_id: contact.external_id,
|
|
121
|
+
email: contact.email,
|
|
122
|
+
name: contact.name,
|
|
123
|
+
phone: contact.phone,
|
|
124
|
+
role: contact.role,
|
|
125
|
+
created_at: contact.created_at,
|
|
126
|
+
updated_at: contact.updated_at,
|
|
127
|
+
signed_up_at: contact.signed_up_at,
|
|
128
|
+
last_seen_at: contact.last_seen_at,
|
|
129
|
+
custom_attributes: contact.custom_attributes,
|
|
130
|
+
tags: contact.tags,
|
|
131
|
+
companies: contact.companies,
|
|
132
|
+
location: contact.location,
|
|
133
|
+
social_profiles: contact.social_profiles,
|
|
134
|
+
},
|
|
135
|
+
options.format,
|
|
136
|
+
);
|
|
137
|
+
} catch (error) {
|
|
138
|
+
spinner.fail("Failed to fetch contact");
|
|
139
|
+
handleIntercomError(error);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export async function cmdContactUpdate(options: ContactUpdateOptions): Promise<void> {
|
|
144
|
+
const token = await requireToken();
|
|
145
|
+
const spinner = ora("Updating contact...").start();
|
|
146
|
+
|
|
147
|
+
try {
|
|
148
|
+
const client = createClient({ token, dryRun: options.dryRun });
|
|
149
|
+
|
|
150
|
+
let payload: Record<string, unknown> = { contact_id: options.id };
|
|
151
|
+
if (options.json) {
|
|
152
|
+
const parsed = JSON.parse(options.json);
|
|
153
|
+
payload = { ...payload, ...parsed };
|
|
154
|
+
} else {
|
|
155
|
+
if (options.name) payload.name = options.name;
|
|
156
|
+
if (options.email) payload.email = options.email;
|
|
157
|
+
if (options.phone) payload.phone = options.phone;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const updatePayload = { contact_id: options.id, ...payload } as const;
|
|
161
|
+
const contact = await client.contacts.update(updatePayload);
|
|
162
|
+
|
|
163
|
+
spinner.succeed("Contact updated");
|
|
164
|
+
|
|
165
|
+
output(
|
|
166
|
+
{
|
|
167
|
+
id: contact.id,
|
|
168
|
+
email: contact.email,
|
|
169
|
+
name: contact.name,
|
|
170
|
+
phone: contact.phone,
|
|
171
|
+
updated_at: contact.updated_at,
|
|
172
|
+
},
|
|
173
|
+
options.format,
|
|
174
|
+
);
|
|
175
|
+
} catch (error) {
|
|
176
|
+
spinner.fail("Failed to update contact");
|
|
177
|
+
handleIntercomError(error);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export async function cmdContactDelete(options: ContactDeleteOptions): Promise<void> {
|
|
182
|
+
const token = await requireToken();
|
|
183
|
+
const spinner = ora("Deleting contact...").start();
|
|
184
|
+
|
|
185
|
+
try {
|
|
186
|
+
const client = createClient({ token, dryRun: options.dryRun });
|
|
187
|
+
const result = await client.contacts.delete({ contact_id: options.id });
|
|
188
|
+
|
|
189
|
+
spinner.succeed("Contact deleted");
|
|
190
|
+
|
|
191
|
+
output({ deleted: true, id: result.id }, options.format);
|
|
192
|
+
} catch (error) {
|
|
193
|
+
spinner.fail("Failed to delete contact");
|
|
194
|
+
handleIntercomError(error);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export async function cmdContactSearch(options: ContactSearchOptions): Promise<void> {
|
|
199
|
+
const token = await requireToken();
|
|
200
|
+
const spinner = ora("Searching contacts...").start();
|
|
201
|
+
|
|
202
|
+
try {
|
|
203
|
+
const client = createClient({ token, dryRun: options.dryRun });
|
|
204
|
+
|
|
205
|
+
let query: Record<string, unknown>;
|
|
206
|
+
if (options.json) {
|
|
207
|
+
query = JSON.parse(options.json);
|
|
208
|
+
} else if (options.email) {
|
|
209
|
+
query = {
|
|
210
|
+
query: {
|
|
211
|
+
field: "email",
|
|
212
|
+
operator: "=",
|
|
213
|
+
value: options.email,
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
} else {
|
|
217
|
+
throw new CLIError("Search requires --email or --json", 400);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (options.limit) {
|
|
221
|
+
query.pagination = { per_page: Number.parseInt(options.limit, 10) };
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const searchPayload = { query: query.query, pagination: query.pagination };
|
|
225
|
+
const result = await client.contacts.search(searchPayload as Parameters<typeof client.contacts.search>[0]);
|
|
226
|
+
|
|
227
|
+
spinner.stop();
|
|
228
|
+
|
|
229
|
+
const contacts: unknown[] = [];
|
|
230
|
+
for await (const contact of result) {
|
|
231
|
+
contacts.push({
|
|
232
|
+
id: contact.id,
|
|
233
|
+
email: contact.email,
|
|
234
|
+
name: contact.name,
|
|
235
|
+
role: contact.role,
|
|
236
|
+
created_at: contact.created_at,
|
|
237
|
+
});
|
|
238
|
+
if (options.limit && contacts.length >= Number.parseInt(options.limit, 10)) break;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
output({ total: contacts.length, contacts }, options.format);
|
|
242
|
+
} catch (error) {
|
|
243
|
+
spinner.fail("Failed to search contacts");
|
|
244
|
+
handleIntercomError(error);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export async function cmdContactList(options: ContactListOptions): Promise<void> {
|
|
249
|
+
const token = await requireToken();
|
|
250
|
+
const spinner = ora("Listing contacts...").start();
|
|
251
|
+
|
|
252
|
+
try {
|
|
253
|
+
const client = createClient({ token, dryRun: options.dryRun });
|
|
254
|
+
|
|
255
|
+
const limit = options.limit ? Number.parseInt(options.limit, 10) : 25;
|
|
256
|
+
const result = await client.contacts.list({ per_page: Math.min(limit, 50) });
|
|
257
|
+
|
|
258
|
+
spinner.stop();
|
|
259
|
+
|
|
260
|
+
const contacts: unknown[] = [];
|
|
261
|
+
for await (const contact of result) {
|
|
262
|
+
contacts.push({
|
|
263
|
+
id: contact.id,
|
|
264
|
+
email: contact.email,
|
|
265
|
+
name: contact.name,
|
|
266
|
+
role: contact.role,
|
|
267
|
+
created_at: contact.created_at,
|
|
268
|
+
});
|
|
269
|
+
if (contacts.length >= limit) break;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
output({ total: contacts.length, contacts }, options.format);
|
|
273
|
+
} catch (error) {
|
|
274
|
+
spinner.fail("Failed to list contacts");
|
|
275
|
+
handleIntercomError(error);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export async function cmdContactNote(options: ContactNoteOptions): Promise<void> {
|
|
280
|
+
const token = await requireToken();
|
|
281
|
+
const spinner = ora("Adding note...").start();
|
|
282
|
+
|
|
283
|
+
try {
|
|
284
|
+
const client = createClient({ token, dryRun: options.dryRun });
|
|
285
|
+
const note = await client.notes.create({
|
|
286
|
+
contact_id: options.id,
|
|
287
|
+
body: options.body,
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
spinner.succeed("Note added");
|
|
291
|
+
|
|
292
|
+
output(
|
|
293
|
+
{
|
|
294
|
+
id: note.id,
|
|
295
|
+
body: note.body,
|
|
296
|
+
created_at: note.created_at,
|
|
297
|
+
author: note.author,
|
|
298
|
+
},
|
|
299
|
+
options.format,
|
|
300
|
+
);
|
|
301
|
+
} catch (error) {
|
|
302
|
+
spinner.fail("Failed to add note");
|
|
303
|
+
handleIntercomError(error);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export async function cmdContactNotes(options: ContactNotesListOptions): Promise<void> {
|
|
308
|
+
const token = await requireToken();
|
|
309
|
+
const spinner = ora("Fetching notes...").start();
|
|
310
|
+
|
|
311
|
+
try {
|
|
312
|
+
const client = createClient({ token, dryRun: options.dryRun });
|
|
313
|
+
const result = await client.notes.list({ contact_id: options.id });
|
|
314
|
+
|
|
315
|
+
spinner.stop();
|
|
316
|
+
|
|
317
|
+
const notes: unknown[] = [];
|
|
318
|
+
for await (const note of result) {
|
|
319
|
+
notes.push({
|
|
320
|
+
id: note.id,
|
|
321
|
+
body: note.body,
|
|
322
|
+
created_at: note.created_at,
|
|
323
|
+
author: note.author,
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
output({ total: notes.length, notes }, options.format);
|
|
328
|
+
} catch (error) {
|
|
329
|
+
spinner.fail("Failed to fetch notes");
|
|
330
|
+
handleIntercomError(error);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export async function cmdContactTag(options: ContactTagOptions): Promise<void> {
|
|
335
|
+
const token = await requireToken();
|
|
336
|
+
const spinner = ora("Tagging contact...").start();
|
|
337
|
+
|
|
338
|
+
try {
|
|
339
|
+
const client = createClient({ token, dryRun: options.dryRun });
|
|
340
|
+
const result = await client.tags.tagContact({
|
|
341
|
+
contact_id: options.contactId,
|
|
342
|
+
id: options.tagId,
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
spinner.succeed("Contact tagged");
|
|
346
|
+
|
|
347
|
+
output(
|
|
348
|
+
{
|
|
349
|
+
id: result.id,
|
|
350
|
+
name: result.name,
|
|
351
|
+
},
|
|
352
|
+
options.format,
|
|
353
|
+
);
|
|
354
|
+
} catch (error) {
|
|
355
|
+
spinner.fail("Failed to tag contact");
|
|
356
|
+
handleIntercomError(error);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
export async function cmdContactUntag(options: ContactTagOptions): Promise<void> {
|
|
361
|
+
const token = await requireToken();
|
|
362
|
+
const spinner = ora("Removing tag...").start();
|
|
363
|
+
|
|
364
|
+
try {
|
|
365
|
+
const client = createClient({ token, dryRun: options.dryRun });
|
|
366
|
+
const result = await client.tags.untagContact({
|
|
367
|
+
contact_id: options.contactId,
|
|
368
|
+
tag_id: options.tagId,
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
spinner.succeed("Tag removed");
|
|
372
|
+
|
|
373
|
+
output(
|
|
374
|
+
{
|
|
375
|
+
id: result.id,
|
|
376
|
+
name: result.name,
|
|
377
|
+
},
|
|
378
|
+
options.format,
|
|
379
|
+
);
|
|
380
|
+
} catch (error) {
|
|
381
|
+
spinner.fail("Failed to remove tag");
|
|
382
|
+
handleIntercomError(error);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
export async function cmdContactAttachCompany(options: ContactAttachCompanyOptions): Promise<void> {
|
|
387
|
+
const token = await requireToken();
|
|
388
|
+
const spinner = ora("Attaching company...").start();
|
|
389
|
+
|
|
390
|
+
try {
|
|
391
|
+
const client = createClient({ token, dryRun: options.dryRun });
|
|
392
|
+
const result = await client.companies.attachContact({
|
|
393
|
+
contact_id: options.contactId,
|
|
394
|
+
id: options.companyId,
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
spinner.succeed("Company attached");
|
|
398
|
+
|
|
399
|
+
output(
|
|
400
|
+
{
|
|
401
|
+
id: result.id,
|
|
402
|
+
name: result.name,
|
|
403
|
+
},
|
|
404
|
+
options.format,
|
|
405
|
+
);
|
|
406
|
+
} catch (error) {
|
|
407
|
+
spinner.fail("Failed to attach company");
|
|
408
|
+
handleIntercomError(error);
|
|
409
|
+
}
|
|
410
|
+
}
|