@instantkom/cli 3.129.2
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/README.md +34 -0
- package/bin/run.js +3 -0
- package/dist/api-client.d.ts +55 -0
- package/dist/api-client.js +199 -0
- package/dist/auth/device-flow-client.d.ts +22 -0
- package/dist/auth/device-flow-client.js +70 -0
- package/dist/auth/token-resolver.d.ts +31 -0
- package/dist/auth/token-resolver.js +48 -0
- package/dist/auth/token-store.d.ts +13 -0
- package/dist/auth/token-store.js +39 -0
- package/dist/base-command.d.ts +18 -0
- package/dist/base-command.js +84 -0
- package/dist/commands/ai/reply.d.ts +18 -0
- package/dist/commands/ai/reply.js +46 -0
- package/dist/commands/auth/login.d.ts +15 -0
- package/dist/commands/auth/login.js +37 -0
- package/dist/commands/auth/logout.d.ts +14 -0
- package/dist/commands/auth/logout.js +17 -0
- package/dist/commands/auth/tokens/create.d.ts +17 -0
- package/dist/commands/auth/tokens/create.js +62 -0
- package/dist/commands/auth/tokens/list.d.ts +14 -0
- package/dist/commands/auth/tokens/list.js +41 -0
- package/dist/commands/auth/tokens/revoke.d.ts +20 -0
- package/dist/commands/auth/tokens/revoke.js +41 -0
- package/dist/commands/autocomplete/script.d.ts +11 -0
- package/dist/commands/autocomplete/script.js +90 -0
- package/dist/commands/autocomplete.d.ts +13 -0
- package/dist/commands/autocomplete.js +95 -0
- package/dist/commands/bots/create.d.ts +22 -0
- package/dist/commands/bots/create.js +39 -0
- package/dist/commands/bots/delete.d.ts +20 -0
- package/dist/commands/bots/delete.js +19 -0
- package/dist/commands/bots/env-vars/bots.d.ts +20 -0
- package/dist/commands/bots/env-vars/bots.js +18 -0
- package/dist/commands/bots/env-vars/create.d.ts +18 -0
- package/dist/commands/bots/env-vars/create.js +28 -0
- package/dist/commands/bots/env-vars/delete.d.ts +20 -0
- package/dist/commands/bots/env-vars/delete.js +19 -0
- package/dist/commands/bots/env-vars/get.d.ts +20 -0
- package/dist/commands/bots/env-vars/get.js +19 -0
- package/dist/commands/bots/env-vars/list.d.ts +18 -0
- package/dist/commands/bots/env-vars/list.js +28 -0
- package/dist/commands/bots/env-vars/update.d.ts +23 -0
- package/dist/commands/bots/env-vars/update.js +29 -0
- package/dist/commands/bots/env-vars/values/delete.d.ts +20 -0
- package/dist/commands/bots/env-vars/values/delete.js +18 -0
- package/dist/commands/bots/env-vars/values/update.d.ts +23 -0
- package/dist/commands/bots/env-vars/values/update.js +28 -0
- package/dist/commands/bots/env-vars/values.d.ts +24 -0
- package/dist/commands/bots/env-vars/values.js +30 -0
- package/dist/commands/bots/filters/create.d.ts +28 -0
- package/dist/commands/bots/filters/create.js +38 -0
- package/dist/commands/bots/filters/delete.d.ts +24 -0
- package/dist/commands/bots/filters/delete.js +19 -0
- package/dist/commands/bots/filters/get.d.ts +24 -0
- package/dist/commands/bots/filters/get.js +19 -0
- package/dist/commands/bots/filters/list.d.ts +24 -0
- package/dist/commands/bots/filters/list.js +30 -0
- package/dist/commands/bots/filters/update.d.ts +32 -0
- package/dist/commands/bots/filters/update.js +39 -0
- package/dist/commands/bots/get.d.ts +20 -0
- package/dist/commands/bots/get.js +19 -0
- package/dist/commands/bots/list.d.ts +21 -0
- package/dist/commands/bots/list.js +34 -0
- package/dist/commands/bots/matches.d.ts +23 -0
- package/dist/commands/bots/matches.js +28 -0
- package/dist/commands/bots/tags/add.d.ts +24 -0
- package/dist/commands/bots/tags/add.js +19 -0
- package/dist/commands/bots/tags/list.d.ts +20 -0
- package/dist/commands/bots/tags/list.js +18 -0
- package/dist/commands/bots/tags/remove.d.ts +24 -0
- package/dist/commands/bots/tags/remove.js +19 -0
- package/dist/commands/bots/update.d.ts +27 -0
- package/dist/commands/bots/update.js +36 -0
- package/dist/commands/broadcast/create.d.ts +25 -0
- package/dist/commands/broadcast/create.js +117 -0
- package/dist/commands/channels/create.d.ts +19 -0
- package/dist/commands/channels/create.js +43 -0
- package/dist/commands/channels/get.d.ts +20 -0
- package/dist/commands/channels/get.js +25 -0
- package/dist/commands/channels/kpis.d.ts +21 -0
- package/dist/commands/channels/kpis.js +29 -0
- package/dist/commands/channels/list.d.ts +19 -0
- package/dist/commands/channels/list.js +43 -0
- package/dist/commands/channels/update.d.ts +24 -0
- package/dist/commands/channels/update.js +43 -0
- package/dist/commands/chats/reply.d.ts +21 -0
- package/dist/commands/chats/reply.js +28 -0
- package/dist/commands/config/get.d.ts +17 -0
- package/dist/commands/config/get.js +29 -0
- package/dist/commands/config/set.d.ts +18 -0
- package/dist/commands/config/set.js +30 -0
- package/dist/commands/config/unset.d.ts +17 -0
- package/dist/commands/config/unset.js +25 -0
- package/dist/commands/contacts/create.d.ts +18 -0
- package/dist/commands/contacts/create.js +39 -0
- package/dist/commands/contacts/delete.d.ts +20 -0
- package/dist/commands/contacts/delete.js +25 -0
- package/dist/commands/contacts/export.d.ts +19 -0
- package/dist/commands/contacts/export.js +50 -0
- package/dist/commands/contacts/get.d.ts +20 -0
- package/dist/commands/contacts/get.js +25 -0
- package/dist/commands/contacts/import.d.ts +16 -0
- package/dist/commands/contacts/import.js +62 -0
- package/dist/commands/contacts/list.d.ts +25 -0
- package/dist/commands/contacts/list.js +71 -0
- package/dist/commands/contacts/update.d.ts +23 -0
- package/dist/commands/contacts/update.js +39 -0
- package/dist/commands/exports/create.d.ts +23 -0
- package/dist/commands/exports/create.js +69 -0
- package/dist/commands/exports/delete.d.ts +20 -0
- package/dist/commands/exports/delete.js +25 -0
- package/dist/commands/exports/download.d.ts +21 -0
- package/dist/commands/exports/download.js +37 -0
- package/dist/commands/exports/get.d.ts +20 -0
- package/dist/commands/exports/get.js +25 -0
- package/dist/commands/exports/list.d.ts +18 -0
- package/dist/commands/exports/list.js +39 -0
- package/dist/commands/flow/edges/create.d.ts +25 -0
- package/dist/commands/flow/edges/create.js +32 -0
- package/dist/commands/flow/edges/delete.d.ts +24 -0
- package/dist/commands/flow/edges/delete.js +19 -0
- package/dist/commands/flow/edges/get.d.ts +24 -0
- package/dist/commands/flow/edges/get.js +19 -0
- package/dist/commands/flow/edges/list.d.ts +20 -0
- package/dist/commands/flow/edges/list.js +18 -0
- package/dist/commands/flow/edges/update.d.ts +29 -0
- package/dist/commands/flow/edges/update.js +33 -0
- package/dist/commands/flow/nodes/create.d.ts +25 -0
- package/dist/commands/flow/nodes/create.js +32 -0
- package/dist/commands/flow/nodes/delete.d.ts +24 -0
- package/dist/commands/flow/nodes/delete.js +19 -0
- package/dist/commands/flow/nodes/get.d.ts +24 -0
- package/dist/commands/flow/nodes/get.js +19 -0
- package/dist/commands/flow/nodes/list.d.ts +20 -0
- package/dist/commands/flow/nodes/list.js +18 -0
- package/dist/commands/flow/nodes/update.d.ts +29 -0
- package/dist/commands/flow/nodes/update.js +33 -0
- package/dist/commands/flows/create.d.ts +20 -0
- package/dist/commands/flows/create.js +32 -0
- package/dist/commands/flows/delete.d.ts +20 -0
- package/dist/commands/flows/delete.js +19 -0
- package/dist/commands/flows/get.d.ts +20 -0
- package/dist/commands/flows/get.js +19 -0
- package/dist/commands/flows/list.d.ts +19 -0
- package/dist/commands/flows/list.js +30 -0
- package/dist/commands/flows/update.d.ts +25 -0
- package/dist/commands/flows/update.js +33 -0
- package/dist/commands/send.d.ts +23 -0
- package/dist/commands/send.js +129 -0
- package/dist/commands/status.d.ts +23 -0
- package/dist/commands/status.js +81 -0
- package/dist/commands/tail.d.ts +15 -0
- package/dist/commands/tail.js +36 -0
- package/dist/commands/templates/get.d.ts +20 -0
- package/dist/commands/templates/get.js +24 -0
- package/dist/commands/templates/list.d.ts +18 -0
- package/dist/commands/templates/list.js +37 -0
- package/dist/commands/templates/render.d.ts +21 -0
- package/dist/commands/templates/render.js +30 -0
- package/dist/commands/ticket/messages/create.d.ts +22 -0
- package/dist/commands/ticket/messages/create.js +26 -0
- package/dist/commands/ticket/messages/delete.d.ts +24 -0
- package/dist/commands/ticket/messages/delete.js +20 -0
- package/dist/commands/ticket/messages/get.d.ts +24 -0
- package/dist/commands/ticket/messages/get.js +19 -0
- package/dist/commands/ticket/messages/list.d.ts +20 -0
- package/dist/commands/ticket/messages/list.js +18 -0
- package/dist/commands/tickets/create.d.ts +22 -0
- package/dist/commands/tickets/create.js +34 -0
- package/dist/commands/tickets/delete.d.ts +21 -0
- package/dist/commands/tickets/delete.js +21 -0
- package/dist/commands/tickets/get.d.ts +21 -0
- package/dist/commands/tickets/get.js +21 -0
- package/dist/commands/tickets/list.d.ts +17 -0
- package/dist/commands/tickets/list.js +24 -0
- package/dist/commands/tickets/update.d.ts +25 -0
- package/dist/commands/tickets/update.js +31 -0
- package/dist/commands/webhooks/add.d.ts +16 -0
- package/dist/commands/webhooks/add.js +38 -0
- package/dist/commands/webhooks/list.d.ts +14 -0
- package/dist/commands/webhooks/list.js +18 -0
- package/dist/commands/webhooks/remove.d.ts +17 -0
- package/dist/commands/webhooks/remove.js +24 -0
- package/dist/commands/whoami.d.ts +15 -0
- package/dist/commands/whoami.js +40 -0
- package/dist/config/config-file.d.ts +36 -0
- package/dist/config/config-file.js +111 -0
- package/dist/config/config-path.d.ts +8 -0
- package/dist/config/config-path.js +25 -0
- package/dist/crud/csv.d.ts +6 -0
- package/dist/crud/csv.js +89 -0
- package/dist/crud/data.d.ts +4 -0
- package/dist/crud/data.js +38 -0
- package/dist/crud/request.d.ts +14 -0
- package/dist/crud/request.js +26 -0
- package/dist/errors/api-error.d.ts +6 -0
- package/dist/errors/api-error.js +10 -0
- package/dist/errors/exit-codes.d.ts +12 -0
- package/dist/errors/exit-codes.js +24 -0
- package/dist/errors/redact-token.d.ts +10 -0
- package/dist/errors/redact-token.js +17 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/output/formatter.d.ts +15 -0
- package/dist/output/formatter.js +57 -0
- package/dist/output/text-format.d.ts +13 -0
- package/dist/output/text-format.js +67 -0
- package/dist/send/api.d.ts +3 -0
- package/dist/send/api.js +21 -0
- package/dist/send/fallback.d.ts +5 -0
- package/dist/send/fallback.js +38 -0
- package/dist/send/media.d.ts +2 -0
- package/dist/send/media.js +41 -0
- package/dist/send/payload.d.ts +23 -0
- package/dist/send/payload.js +22 -0
- package/dist/send/recipient-resolver.d.ts +13 -0
- package/dist/send/recipient-resolver.js +28 -0
- package/dist/send/schedule.d.ts +1 -0
- package/dist/send/schedule.js +19 -0
- package/dist/tail/sse.d.ts +24 -0
- package/dist/tail/sse.js +139 -0
- package/dist/templates/render-template.d.ts +14 -0
- package/dist/templates/render-template.js +46 -0
- package/npm-shrinkwrap.json +11444 -0
- package/oclif.manifest.json +9286 -0
- package/package.json +157 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import { BaseCommand } from '../../base-command.js';
|
|
3
|
+
import { cleanQuery } from '../../crud/data.js';
|
|
4
|
+
import { createResource } from '../../crud/request.js';
|
|
5
|
+
import { createCliApiClient } from '../../send/api.js';
|
|
6
|
+
const SMART_REPLY_STYLES = [
|
|
7
|
+
'professional',
|
|
8
|
+
'friendly',
|
|
9
|
+
'concise',
|
|
10
|
+
'detailed',
|
|
11
|
+
'empathetic',
|
|
12
|
+
];
|
|
13
|
+
export default class AiReply extends BaseCommand {
|
|
14
|
+
static description = 'Generate AI reply suggestions for a message';
|
|
15
|
+
static flags = {
|
|
16
|
+
...BaseCommand.baseFlags,
|
|
17
|
+
'message-id': Flags.integer({
|
|
18
|
+
description: 'Message ID to use as smart-reply anchor',
|
|
19
|
+
required: true,
|
|
20
|
+
}),
|
|
21
|
+
limit: Flags.integer({
|
|
22
|
+
description: 'Number of suggestions to generate (1-5)',
|
|
23
|
+
}),
|
|
24
|
+
'context-length': Flags.integer({
|
|
25
|
+
description: 'Number of recent messages to use as context (1-20)',
|
|
26
|
+
}),
|
|
27
|
+
style: Flags.string({
|
|
28
|
+
description: 'Response style',
|
|
29
|
+
options: SMART_REPLY_STYLES,
|
|
30
|
+
}),
|
|
31
|
+
};
|
|
32
|
+
async run() {
|
|
33
|
+
const { flags } = await this.parse(AiReply);
|
|
34
|
+
this.flags = flags;
|
|
35
|
+
const client = await createCliApiClient(flags);
|
|
36
|
+
const response = await createResource(client, '/v1/ai/reply', cleanQuery({
|
|
37
|
+
messageId: flags['message-id'],
|
|
38
|
+
limit: flags.limit,
|
|
39
|
+
contextLength: flags['context-length'],
|
|
40
|
+
style: flags.style,
|
|
41
|
+
}));
|
|
42
|
+
if (!flags.quiet) {
|
|
43
|
+
this.log(this.toFormatted(response));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base-command.js';
|
|
2
|
+
export default class Login extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static flags: {
|
|
5
|
+
scope: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
6
|
+
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
format: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
9
|
+
quiet: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
10
|
+
'no-color': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
11
|
+
profile: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
'api-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
};
|
|
14
|
+
run(): Promise<void>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import { BaseCommand } from '../../base-command.js';
|
|
3
|
+
import { EXIT_CODES } from '../../errors/exit-codes.js';
|
|
4
|
+
import * as tokenStore from '../../auth/token-store.js';
|
|
5
|
+
import * as deviceFlowClient from '../../auth/device-flow-client.js';
|
|
6
|
+
import { ApiClient } from '../../api-client.js';
|
|
7
|
+
export default class Login extends BaseCommand {
|
|
8
|
+
static description = 'Authenticate with the instantKOM API via device authorization flow';
|
|
9
|
+
static flags = {
|
|
10
|
+
...BaseCommand.baseFlags,
|
|
11
|
+
scope: Flags.string({
|
|
12
|
+
description: 'Requested token scope',
|
|
13
|
+
options: ['full', 'send', 'read', 'admin'],
|
|
14
|
+
default: 'read',
|
|
15
|
+
}),
|
|
16
|
+
};
|
|
17
|
+
async run() {
|
|
18
|
+
const { flags } = await this.parse(Login);
|
|
19
|
+
this.flags = flags;
|
|
20
|
+
const apiUrl = flags['api-url'] ?? process.env.IKM_API_URL ?? 'https://api.instantkom.app';
|
|
21
|
+
const profile = flags.profile ?? 'default';
|
|
22
|
+
const scope = flags.scope ?? 'read';
|
|
23
|
+
const result = await deviceFlowClient.run({ apiUrl, scope });
|
|
24
|
+
await tokenStore.set(profile, result.access_token);
|
|
25
|
+
// Confirm login by fetching the user profile
|
|
26
|
+
const client = new ApiClient({
|
|
27
|
+
id: profile,
|
|
28
|
+
name: 'ikm-cli',
|
|
29
|
+
apiUrl,
|
|
30
|
+
apiKey: result.access_token,
|
|
31
|
+
scope: 'customer',
|
|
32
|
+
});
|
|
33
|
+
const me = await client.get('/v1/users/me');
|
|
34
|
+
this.log(`Logged in as ${me.email}. Scope: ${result.scope}.`);
|
|
35
|
+
this.exit(EXIT_CODES.OK);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base-command.js';
|
|
2
|
+
export default class Logout extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static flags: {
|
|
5
|
+
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
6
|
+
format: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
8
|
+
quiet: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
9
|
+
'no-color': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
10
|
+
profile: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
'api-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
};
|
|
13
|
+
run(): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base-command.js';
|
|
2
|
+
import { EXIT_CODES } from '../../errors/exit-codes.js';
|
|
3
|
+
import * as tokenStore from '../../auth/token-store.js';
|
|
4
|
+
export default class Logout extends BaseCommand {
|
|
5
|
+
static description = 'Remove the stored API token for the current profile';
|
|
6
|
+
static flags = {
|
|
7
|
+
...BaseCommand.baseFlags,
|
|
8
|
+
};
|
|
9
|
+
async run() {
|
|
10
|
+
const { flags } = await this.parse(Logout);
|
|
11
|
+
this.flags = flags;
|
|
12
|
+
const profile = flags.profile ?? 'default';
|
|
13
|
+
await tokenStore.del(profile);
|
|
14
|
+
this.log(`Logged out of profile ${profile}.`);
|
|
15
|
+
this.exit(EXIT_CODES.OK);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseCommand } from '../../../base-command.js';
|
|
2
|
+
export default class TokensCreate extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static flags: {
|
|
5
|
+
scope: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
6
|
+
name: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
'expires-in': import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
format: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
11
|
+
quiet: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
12
|
+
'no-color': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
13
|
+
profile: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
|
+
'api-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
15
|
+
};
|
|
16
|
+
run(): Promise<void>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import { BaseCommand } from '../../../base-command.js';
|
|
3
|
+
import { EXIT_CODES } from '../../../errors/exit-codes.js';
|
|
4
|
+
import { ApiError } from '../../../errors/api-error.js';
|
|
5
|
+
import { resolveToken } from '../../../auth/token-resolver.js';
|
|
6
|
+
import { ApiClient } from '../../../api-client.js';
|
|
7
|
+
export default class TokensCreate extends BaseCommand {
|
|
8
|
+
static description = 'Create a new scoped API token';
|
|
9
|
+
static flags = {
|
|
10
|
+
...BaseCommand.baseFlags,
|
|
11
|
+
scope: Flags.string({
|
|
12
|
+
description: 'Token scope',
|
|
13
|
+
options: ['full', 'send', 'read', 'admin'],
|
|
14
|
+
required: true,
|
|
15
|
+
}),
|
|
16
|
+
name: Flags.string({
|
|
17
|
+
description: 'Token name (stored in apis2.nm)',
|
|
18
|
+
required: true,
|
|
19
|
+
}),
|
|
20
|
+
'expires-in': Flags.integer({
|
|
21
|
+
description: 'Token lifetime in seconds (omit for non-expiring)',
|
|
22
|
+
}),
|
|
23
|
+
};
|
|
24
|
+
async run() {
|
|
25
|
+
const { flags } = await this.parse(TokensCreate);
|
|
26
|
+
this.flags = flags;
|
|
27
|
+
const token = await resolveToken({
|
|
28
|
+
flag: flags['api-key'],
|
|
29
|
+
env: process.env.IKM_API_KEY,
|
|
30
|
+
profile: flags.profile ?? 'default',
|
|
31
|
+
});
|
|
32
|
+
if (!token) {
|
|
33
|
+
throw new ApiError('unauthorized', 'Not logged in. Run: ikm auth login');
|
|
34
|
+
}
|
|
35
|
+
const apiUrl = flags['api-url'] ?? process.env.IKM_API_URL ?? 'https://api.instantkom.app';
|
|
36
|
+
const client = new ApiClient({
|
|
37
|
+
id: flags.profile ?? 'default',
|
|
38
|
+
name: 'ikm-cli',
|
|
39
|
+
apiUrl,
|
|
40
|
+
apiKey: token,
|
|
41
|
+
scope: 'customer',
|
|
42
|
+
});
|
|
43
|
+
const body = {
|
|
44
|
+
name: flags.name,
|
|
45
|
+
scope: flags.scope,
|
|
46
|
+
};
|
|
47
|
+
if (flags['expires-in'] !== undefined) {
|
|
48
|
+
body.expires_in = flags['expires-in'];
|
|
49
|
+
}
|
|
50
|
+
const created = await client.post('/v1/api-keys/scoped', body);
|
|
51
|
+
this.warn('Store this token now. It will not be shown again.');
|
|
52
|
+
this.log(this.toFormatted({
|
|
53
|
+
id: created.id,
|
|
54
|
+
name: created.name,
|
|
55
|
+
token: created.token,
|
|
56
|
+
scope: created.tokenScope,
|
|
57
|
+
created_at: created.createdAt,
|
|
58
|
+
expires_at: created.expiresAt,
|
|
59
|
+
}));
|
|
60
|
+
this.exit(EXIT_CODES.OK);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseCommand } from '../../../base-command.js';
|
|
2
|
+
export default class TokensList extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static flags: {
|
|
5
|
+
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
6
|
+
format: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
8
|
+
quiet: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
9
|
+
'no-color': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
10
|
+
profile: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
'api-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
};
|
|
13
|
+
run(): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { BaseCommand } from '../../../base-command.js';
|
|
2
|
+
import { EXIT_CODES } from '../../../errors/exit-codes.js';
|
|
3
|
+
import { ApiError } from '../../../errors/api-error.js';
|
|
4
|
+
import { resolveToken } from '../../../auth/token-resolver.js';
|
|
5
|
+
import { ApiClient } from '../../../api-client.js';
|
|
6
|
+
export default class TokensList extends BaseCommand {
|
|
7
|
+
static description = 'List all API tokens for the current account';
|
|
8
|
+
static flags = {
|
|
9
|
+
...BaseCommand.baseFlags,
|
|
10
|
+
};
|
|
11
|
+
async run() {
|
|
12
|
+
const { flags } = await this.parse(TokensList);
|
|
13
|
+
this.flags = flags;
|
|
14
|
+
const token = await resolveToken({
|
|
15
|
+
flag: flags['api-key'],
|
|
16
|
+
env: process.env.IKM_API_KEY,
|
|
17
|
+
profile: flags.profile ?? 'default',
|
|
18
|
+
});
|
|
19
|
+
if (!token) {
|
|
20
|
+
throw new ApiError('unauthorized', 'Not logged in. Run: ikm auth login');
|
|
21
|
+
}
|
|
22
|
+
const apiUrl = flags['api-url'] ?? process.env.IKM_API_URL ?? 'https://api.instantkom.app';
|
|
23
|
+
const client = new ApiClient({
|
|
24
|
+
id: flags.profile ?? 'default',
|
|
25
|
+
name: 'ikm-cli',
|
|
26
|
+
apiUrl,
|
|
27
|
+
apiKey: token,
|
|
28
|
+
scope: 'customer',
|
|
29
|
+
});
|
|
30
|
+
const result = await client.get('/v1/api-keys');
|
|
31
|
+
const items = (Array.isArray(result) ? result : result.data ?? []).map((item) => ({
|
|
32
|
+
id: item.id,
|
|
33
|
+
name: item.nm ?? item.name ?? '',
|
|
34
|
+
scope: item.token_scope ?? item.tokenScope ?? '',
|
|
35
|
+
last_used: item.last_used_at ?? item.lastUsedAt ?? '',
|
|
36
|
+
expires: item.expires_at ?? item.expiresAt ?? '',
|
|
37
|
+
}));
|
|
38
|
+
this.log(this.toFormatted(items));
|
|
39
|
+
this.exit(EXIT_CODES.OK);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseCommand } from '../../../base-command.js';
|
|
2
|
+
export default class TokensRevoke extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static args: {
|
|
5
|
+
id: import("@oclif/core/interfaces").Arg<number, {
|
|
6
|
+
max?: number;
|
|
7
|
+
min?: number;
|
|
8
|
+
}>;
|
|
9
|
+
};
|
|
10
|
+
static flags: {
|
|
11
|
+
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
format: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
14
|
+
quiet: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
15
|
+
'no-color': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
16
|
+
profile: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
17
|
+
'api-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
18
|
+
};
|
|
19
|
+
run(): Promise<void>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Args } from '@oclif/core';
|
|
2
|
+
import { BaseCommand } from '../../../base-command.js';
|
|
3
|
+
import { EXIT_CODES } from '../../../errors/exit-codes.js';
|
|
4
|
+
import { ApiError } from '../../../errors/api-error.js';
|
|
5
|
+
import { resolveToken } from '../../../auth/token-resolver.js';
|
|
6
|
+
import { ApiClient } from '../../../api-client.js';
|
|
7
|
+
export default class TokensRevoke extends BaseCommand {
|
|
8
|
+
static description = 'Delete an API token by ID';
|
|
9
|
+
static args = {
|
|
10
|
+
id: Args.integer({
|
|
11
|
+
description: 'Token ID to revoke',
|
|
12
|
+
required: true,
|
|
13
|
+
}),
|
|
14
|
+
};
|
|
15
|
+
static flags = {
|
|
16
|
+
...BaseCommand.baseFlags,
|
|
17
|
+
};
|
|
18
|
+
async run() {
|
|
19
|
+
const { args, flags } = await this.parse(TokensRevoke);
|
|
20
|
+
this.flags = flags;
|
|
21
|
+
const token = await resolveToken({
|
|
22
|
+
flag: flags['api-key'],
|
|
23
|
+
env: process.env.IKM_API_KEY,
|
|
24
|
+
profile: flags.profile ?? 'default',
|
|
25
|
+
});
|
|
26
|
+
if (!token) {
|
|
27
|
+
throw new ApiError('unauthorized', 'Not logged in. Run: ikm auth login');
|
|
28
|
+
}
|
|
29
|
+
const apiUrl = flags['api-url'] ?? process.env.IKM_API_URL ?? 'https://api.instantkom.app';
|
|
30
|
+
const client = new ApiClient({
|
|
31
|
+
id: flags.profile ?? 'default',
|
|
32
|
+
name: 'ikm-cli',
|
|
33
|
+
apiUrl,
|
|
34
|
+
apiKey: token,
|
|
35
|
+
scope: 'customer',
|
|
36
|
+
});
|
|
37
|
+
await client.delete(`/v1/api-keys/${args.id}`);
|
|
38
|
+
this.log(`Token ${args.id} revoked.`);
|
|
39
|
+
this.exit(EXIT_CODES.OK);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class AutocompleteScript extends Command {
|
|
3
|
+
static description: string;
|
|
4
|
+
static hidden: boolean;
|
|
5
|
+
static args: {
|
|
6
|
+
shell: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
7
|
+
};
|
|
8
|
+
run(): Promise<void>;
|
|
9
|
+
private generateFishCompletion;
|
|
10
|
+
private commandList;
|
|
11
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Args } from '@oclif/core';
|
|
2
|
+
import { Command } from '@oclif/core';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
const SUPPORTED_SHELLS = ['zsh', 'bash', 'fish', 'powershell'];
|
|
5
|
+
export default class AutocompleteScript extends Command {
|
|
6
|
+
static description = 'outputs autocomplete config script for shells';
|
|
7
|
+
static hidden = true;
|
|
8
|
+
static args = {
|
|
9
|
+
shell: Args.string({
|
|
10
|
+
description: 'Shell type',
|
|
11
|
+
options: SUPPORTED_SHELLS,
|
|
12
|
+
required: false,
|
|
13
|
+
}),
|
|
14
|
+
};
|
|
15
|
+
async run() {
|
|
16
|
+
const { args } = await this.parse(AutocompleteScript);
|
|
17
|
+
const shell = args.shell ?? this.config.shell;
|
|
18
|
+
if (shell === 'fish') {
|
|
19
|
+
this.log(this.generateFishCompletion());
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (shell === 'powershell') {
|
|
23
|
+
const completionFuncPath = path.join(this.config.cacheDir, 'autocomplete', 'functions', 'powershell', `${this.config.bin}.ps1`);
|
|
24
|
+
this.log(`. ${completionFuncPath}`);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const setupVar = `_${this.config.bin.toUpperCase().replace(/[^A-Z0-9]/g, '_')}_AC_${shell.toUpperCase()}_SETUP_PATH`;
|
|
28
|
+
const setupPath = path.join(this.config.cacheDir, 'autocomplete', `${shell}_setup`);
|
|
29
|
+
this.log(`\n${setupVar}=${setupPath} && test -f $${setupVar} && source $${setupVar}; # ${this.config.bin} autocomplete setup`);
|
|
30
|
+
}
|
|
31
|
+
generateFishCompletion() {
|
|
32
|
+
const commands = this.commandList();
|
|
33
|
+
const lines = [
|
|
34
|
+
`# ${this.config.bin} fish completion`,
|
|
35
|
+
`# Generated by: ${this.config.bin} autocomplete script fish`,
|
|
36
|
+
'',
|
|
37
|
+
`complete -c ${this.config.bin} -f`,
|
|
38
|
+
`complete -c ${this.config.bin} -l help -d "Show CLI help"`,
|
|
39
|
+
`complete -c ${this.config.bin} -l json -d "Output in JSON format"`,
|
|
40
|
+
`complete -c ${this.config.bin} -l api-url -d "Override the API base URL"`,
|
|
41
|
+
`complete -c ${this.config.bin} -l profile -d "Named configuration profile"`,
|
|
42
|
+
'',
|
|
43
|
+
`function __${this.config.bin}_seen_exact`,
|
|
44
|
+
' set -l tokens (commandline -opc)',
|
|
45
|
+
' set -e tokens[1]',
|
|
46
|
+
' test (string join " " $tokens) = "$argv"',
|
|
47
|
+
'end',
|
|
48
|
+
'',
|
|
49
|
+
];
|
|
50
|
+
const seen = new Set();
|
|
51
|
+
for (const command of commands) {
|
|
52
|
+
const parts = command.id.split(' ');
|
|
53
|
+
for (let depth = 0; depth < parts.length; depth += 1) {
|
|
54
|
+
const parent = parts.slice(0, depth).join(' ');
|
|
55
|
+
const word = parts[depth];
|
|
56
|
+
const key = `${parent}=>${word}`;
|
|
57
|
+
if (seen.has(key))
|
|
58
|
+
continue;
|
|
59
|
+
seen.add(key);
|
|
60
|
+
const condition = depth === 0
|
|
61
|
+
? '__fish_use_subcommand'
|
|
62
|
+
: `__${this.config.bin}_seen_exact ${escapeFish(parent)}`;
|
|
63
|
+
const description = depth === parts.length - 1
|
|
64
|
+
? command.summary ?? command.description ?? command.id
|
|
65
|
+
: `${parts.slice(0, depth + 1).join(' ')} commands`;
|
|
66
|
+
lines.push(`complete -c ${this.config.bin} -f -n ${escapeFishDouble(condition)} -a ${escapeFish(word)} -d ${escapeFish(description)}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return `${lines.join('\n')}\n`;
|
|
70
|
+
}
|
|
71
|
+
commandList() {
|
|
72
|
+
const commands = this.config.commands;
|
|
73
|
+
const list = Array.isArray(commands)
|
|
74
|
+
? commands
|
|
75
|
+
: [...(commands?.values?.() ?? [])];
|
|
76
|
+
return list
|
|
77
|
+
.filter((command) => command.id && !command.hidden)
|
|
78
|
+
.map((command) => ({
|
|
79
|
+
...command,
|
|
80
|
+
id: command.id.replaceAll(':', ' '),
|
|
81
|
+
}))
|
|
82
|
+
.sort((a, b) => a.id.localeCompare(b.id));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function escapeFish(value) {
|
|
86
|
+
return `'${value.replaceAll('\\', '\\\\').replaceAll("'", "\\'")}'`;
|
|
87
|
+
}
|
|
88
|
+
function escapeFishDouble(value) {
|
|
89
|
+
return `"${value.replaceAll('\\', '\\\\').replaceAll('"', '\\"')}"`;
|
|
90
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class Autocomplete extends Command {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static args: {
|
|
6
|
+
shell: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
7
|
+
};
|
|
8
|
+
static flags: {
|
|
9
|
+
'refresh-cache': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
10
|
+
};
|
|
11
|
+
run(): Promise<void>;
|
|
12
|
+
private printShellInstructions;
|
|
13
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Args, Flags, ux } from '@oclif/core';
|
|
2
|
+
import { Command } from '@oclif/core';
|
|
3
|
+
const SUPPORTED_SHELLS = ['zsh', 'bash', 'fish', 'powershell'];
|
|
4
|
+
export default class Autocomplete extends Command {
|
|
5
|
+
static description = 'Display autocomplete installation instructions.';
|
|
6
|
+
static examples = [
|
|
7
|
+
'$ <%= config.bin %> autocomplete',
|
|
8
|
+
'$ <%= config.bin %> autocomplete bash',
|
|
9
|
+
'$ <%= config.bin %> autocomplete zsh',
|
|
10
|
+
'$ <%= config.bin %> autocomplete fish',
|
|
11
|
+
'$ <%= config.bin %> autocomplete powershell',
|
|
12
|
+
'$ <%= config.bin %> autocomplete --refresh-cache',
|
|
13
|
+
];
|
|
14
|
+
static args = {
|
|
15
|
+
shell: Args.string({
|
|
16
|
+
description: 'Shell type',
|
|
17
|
+
options: SUPPORTED_SHELLS,
|
|
18
|
+
required: false,
|
|
19
|
+
}),
|
|
20
|
+
};
|
|
21
|
+
static flags = {
|
|
22
|
+
'refresh-cache': Flags.boolean({
|
|
23
|
+
char: 'r',
|
|
24
|
+
description: 'Refresh cache (ignores displaying instructions)',
|
|
25
|
+
}),
|
|
26
|
+
};
|
|
27
|
+
async run() {
|
|
28
|
+
const { args, flags } = await this.parse(Autocomplete);
|
|
29
|
+
const shell = args.shell ?? this.config.shell;
|
|
30
|
+
ux.action.start('Building the autocomplete cache');
|
|
31
|
+
await this.config.runCommand('autocomplete:create', []);
|
|
32
|
+
ux.action.stop();
|
|
33
|
+
if (!flags['refresh-cache']) {
|
|
34
|
+
this.printShellInstructions(shell);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
printShellInstructions(shell) {
|
|
38
|
+
const scriptCommand = `${this.config.bin} autocomplete${this.config.topicSeparator}script ${shell}`;
|
|
39
|
+
switch (shell) {
|
|
40
|
+
case 'bash':
|
|
41
|
+
this.log(`
|
|
42
|
+
Setup Instructions for ${this.config.bin.toUpperCase()} CLI Autocomplete
|
|
43
|
+
|
|
44
|
+
1) Run this command:
|
|
45
|
+
|
|
46
|
+
printf "$(${scriptCommand})" >> ~/.bashrc; source ~/.bashrc
|
|
47
|
+
|
|
48
|
+
2) Start using autocomplete:
|
|
49
|
+
|
|
50
|
+
${this.config.bin} <TAB><TAB>
|
|
51
|
+
`);
|
|
52
|
+
return;
|
|
53
|
+
case 'fish':
|
|
54
|
+
this.log(`
|
|
55
|
+
Setup Instructions for ${this.config.bin.toUpperCase()} CLI Fish Autocomplete
|
|
56
|
+
|
|
57
|
+
1) Run this command:
|
|
58
|
+
|
|
59
|
+
mkdir -p ~/.config/fish/completions && ${scriptCommand} > ~/.config/fish/completions/${this.config.bin}.fish
|
|
60
|
+
|
|
61
|
+
2) Start using autocomplete:
|
|
62
|
+
|
|
63
|
+
${this.config.bin} <TAB>
|
|
64
|
+
`);
|
|
65
|
+
return;
|
|
66
|
+
case 'powershell':
|
|
67
|
+
this.log(`
|
|
68
|
+
Setup Instructions for ${this.config.bin.toUpperCase()} CLI PowerShell Autocomplete
|
|
69
|
+
|
|
70
|
+
1) Run these commands:
|
|
71
|
+
|
|
72
|
+
New-Item -Type Directory -Path (Split-Path -Parent $PROFILE) -ErrorAction SilentlyContinue
|
|
73
|
+
Add-Content -Path $PROFILE -Value (Invoke-Expression -Command "${scriptCommand}"); .$PROFILE
|
|
74
|
+
|
|
75
|
+
2) Start using autocomplete:
|
|
76
|
+
|
|
77
|
+
${this.config.bin} <TAB>
|
|
78
|
+
`);
|
|
79
|
+
return;
|
|
80
|
+
case 'zsh':
|
|
81
|
+
default:
|
|
82
|
+
this.log(`
|
|
83
|
+
Setup Instructions for ${this.config.bin.toUpperCase()} CLI Autocomplete
|
|
84
|
+
|
|
85
|
+
1) Run this command:
|
|
86
|
+
|
|
87
|
+
printf "$(${scriptCommand})" >> ~/.zshrc; source ~/.zshrc
|
|
88
|
+
|
|
89
|
+
2) Start using autocomplete:
|
|
90
|
+
|
|
91
|
+
${this.config.bin} <TAB>
|
|
92
|
+
`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base-command.js';
|
|
2
|
+
export default class BotsCreate extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static flags: {
|
|
5
|
+
channel: import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
|
|
6
|
+
name: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
type: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
message: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
response: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
color: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
tags: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
data: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
|
+
format: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
15
|
+
json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
16
|
+
quiet: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
17
|
+
'no-color': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
18
|
+
profile: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
19
|
+
'api-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
20
|
+
};
|
|
21
|
+
run(): Promise<void>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import { BaseCommand } from '../../base-command.js';
|
|
3
|
+
import { ApiError } from '../../errors/api-error.js';
|
|
4
|
+
import { mergeData, parseDataFlag } from '../../crud/data.js';
|
|
5
|
+
import { createResource } from '../../crud/request.js';
|
|
6
|
+
import { createCliApiClient } from '../../send/api.js';
|
|
7
|
+
export default class BotsCreate extends BaseCommand {
|
|
8
|
+
static description = 'Create a bot';
|
|
9
|
+
static flags = {
|
|
10
|
+
...BaseCommand.baseFlags,
|
|
11
|
+
channel: Flags.integer({ description: 'Channel ID', required: true }),
|
|
12
|
+
name: Flags.string({ description: 'Bot name', required: true }),
|
|
13
|
+
type: Flags.string({ description: 'Bot type', required: true, options: ['keyword', 'schedule', 'event', 'ai'] }),
|
|
14
|
+
message: Flags.string({ description: 'Bot message content' }),
|
|
15
|
+
response: Flags.string({ description: 'Alias for --message' }),
|
|
16
|
+
color: Flags.string({ description: 'Bot color as HEX' }),
|
|
17
|
+
tags: Flags.string({ description: 'Comma-separated tags' }),
|
|
18
|
+
data: Flags.string({ description: 'Additional JSON object payload' }),
|
|
19
|
+
};
|
|
20
|
+
async run() {
|
|
21
|
+
const { flags } = await this.parse(BotsCreate);
|
|
22
|
+
this.flags = flags;
|
|
23
|
+
const message = flags.message ?? flags.response;
|
|
24
|
+
if (!message)
|
|
25
|
+
throw new ApiError('user_error', 'Either --message or --response is required');
|
|
26
|
+
const payload = mergeData(parseDataFlag(flags.data), {
|
|
27
|
+
channelId: flags.channel,
|
|
28
|
+
name: flags.name,
|
|
29
|
+
type: flags.type,
|
|
30
|
+
message,
|
|
31
|
+
color: flags.color,
|
|
32
|
+
tags: flags.tags,
|
|
33
|
+
});
|
|
34
|
+
const client = await createCliApiClient(flags);
|
|
35
|
+
const bot = await createResource(client, '/v1/bots', payload);
|
|
36
|
+
if (!flags.quiet)
|
|
37
|
+
this.log(this.toFormatted(bot));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base-command.js';
|
|
2
|
+
export default class BotsDelete extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static args: {
|
|
5
|
+
id: import("@oclif/core/interfaces").Arg<number, {
|
|
6
|
+
max?: number;
|
|
7
|
+
min?: number;
|
|
8
|
+
}>;
|
|
9
|
+
};
|
|
10
|
+
static flags: {
|
|
11
|
+
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
format: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
14
|
+
quiet: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
15
|
+
'no-color': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
16
|
+
profile: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
17
|
+
'api-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
18
|
+
};
|
|
19
|
+
run(): Promise<void>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Args } from '@oclif/core';
|
|
2
|
+
import { BaseCommand } from '../../base-command.js';
|
|
3
|
+
import { deleteResource } from '../../crud/request.js';
|
|
4
|
+
import { createCliApiClient } from '../../send/api.js';
|
|
5
|
+
export default class BotsDelete extends BaseCommand {
|
|
6
|
+
static description = 'Delete a bot';
|
|
7
|
+
static args = {
|
|
8
|
+
id: Args.integer({ description: 'Bot ID', required: true }),
|
|
9
|
+
};
|
|
10
|
+
static flags = { ...BaseCommand.baseFlags };
|
|
11
|
+
async run() {
|
|
12
|
+
const { args, flags } = await this.parse(BotsDelete);
|
|
13
|
+
this.flags = flags;
|
|
14
|
+
const client = await createCliApiClient(flags);
|
|
15
|
+
await deleteResource(client, '/v1/bots', args.id);
|
|
16
|
+
if (!flags.quiet)
|
|
17
|
+
this.log(this.toFormatted({ deleted: true, id: args.id }));
|
|
18
|
+
}
|
|
19
|
+
}
|