@hesed/gchat 0.3.0 → 0.3.1
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 +5 -5
- package/dist/commands/gchat/config/set-key.js +1 -1
- package/dist/commands/gchat/create-message.js +2 -3
- package/dist/commands/gchat/reply-message.js +2 -3
- package/dist/config.d.ts +4 -4
- package/dist/config.js +4 -4
- package/dist/gchat/gchat-api.d.ts +2 -3
- package/dist/gchat/gchat-api.js +4 -5
- package/dist/gchat/gchat-client.js +1 -3
- package/oclif.manifest.json +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ $ npm install -g @hesed/gchat
|
|
|
26
26
|
$ gchat COMMAND
|
|
27
27
|
running command...
|
|
28
28
|
$ gchat (--version)
|
|
29
|
-
@hesed/gchat/0.3.
|
|
29
|
+
@hesed/gchat/0.3.1 linux-x64 node-v24.19.0
|
|
30
30
|
$ gchat --help [COMMAND]
|
|
31
31
|
USAGE
|
|
32
32
|
$ gchat COMMAND
|
|
@@ -62,7 +62,7 @@ EXAMPLES
|
|
|
62
62
|
$ gchat gchat config add-token default AAQAKA6hsFw your-space-token
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
-
_See code: [src/commands/gchat/config/add-token.ts](https://github.com/hesedcasa/gchat/blob/v0.3.
|
|
65
|
+
_See code: [src/commands/gchat/config/add-token.ts](https://github.com/hesedcasa/gchat/blob/v0.3.1/src/commands/gchat/config/add-token.ts)_
|
|
66
66
|
|
|
67
67
|
## `gchat gchat config set-key PROFILE KEY`
|
|
68
68
|
|
|
@@ -85,7 +85,7 @@ EXAMPLES
|
|
|
85
85
|
$ gchat gchat config set-key work your-work-api-key
|
|
86
86
|
```
|
|
87
87
|
|
|
88
|
-
_See code: [src/commands/gchat/config/set-key.ts](https://github.com/hesedcasa/gchat/blob/v0.3.
|
|
88
|
+
_See code: [src/commands/gchat/config/set-key.ts](https://github.com/hesedcasa/gchat/blob/v0.3.1/src/commands/gchat/config/set-key.ts)_
|
|
89
89
|
|
|
90
90
|
## `gchat gchat create-message SPACEID MESSAGE`
|
|
91
91
|
|
|
@@ -117,7 +117,7 @@ EXAMPLES
|
|
|
117
117
|
$ gchat gchat create-message AAQAKA6hsFw "<https://example.com|Click here>" -f
|
|
118
118
|
```
|
|
119
119
|
|
|
120
|
-
_See code: [src/commands/gchat/create-message.ts](https://github.com/hesedcasa/gchat/blob/v0.3.
|
|
120
|
+
_See code: [src/commands/gchat/create-message.ts](https://github.com/hesedcasa/gchat/blob/v0.3.1/src/commands/gchat/create-message.ts)_
|
|
121
121
|
|
|
122
122
|
## `gchat gchat reply-message THREADNAME MESSAGE`
|
|
123
123
|
|
|
@@ -147,5 +147,5 @@ EXAMPLES
|
|
|
147
147
|
$ gchat gchat reply-message spaces/AAQAKA6hsFw/threads/D1NI3W2B6vA "*Bold reply*" --formatted
|
|
148
148
|
```
|
|
149
149
|
|
|
150
|
-
_See code: [src/commands/gchat/reply-message.ts](https://github.com/hesedcasa/gchat/blob/v0.3.
|
|
150
|
+
_See code: [src/commands/gchat/reply-message.ts](https://github.com/hesedcasa/gchat/blob/v0.3.1/src/commands/gchat/reply-message.ts)_
|
|
151
151
|
<!-- commandsstop -->
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Args, Command } from '@oclif/core';
|
|
2
2
|
import { readConfigOrEmpty, writeConfig } from '../../../config.js';
|
|
3
3
|
export default class ConfigSetKey extends Command {
|
|
4
|
-
/* eslint-disable perfectionist/sort-objects */
|
|
4
|
+
/* eslint-disable perfectionist/sort-objects -- profile must precede key in CLI arg order */
|
|
5
5
|
static args = {
|
|
6
6
|
profile: Args.string({ description: 'Config profile name', required: true }),
|
|
7
7
|
key: Args.string({ description: 'Google Chat API key', required: true }),
|
|
@@ -3,7 +3,7 @@ import { DEFAULT_PROFILE, readConfig, resolveProfile } from '../../config.js';
|
|
|
3
3
|
import { formatAsToon } from '../../format.js';
|
|
4
4
|
import { clearClients, newMessage } from '../../gchat/gchat-client.js';
|
|
5
5
|
export default class GChatCreateMessage extends Command {
|
|
6
|
-
/* eslint-disable perfectionist/sort-objects */
|
|
6
|
+
/* eslint-disable perfectionist/sort-objects -- spaceId must precede message in CLI arg order */
|
|
7
7
|
static args = {
|
|
8
8
|
spaceId: Args.string({ description: 'Google Chat space ID', required: true }),
|
|
9
9
|
message: Args.string({ description: 'Message text to send', required: true }),
|
|
@@ -34,8 +34,7 @@ export default class GChatCreateMessage extends Command {
|
|
|
34
34
|
const auth = resolveProfile(config, flags.profile, this.log.bind(this));
|
|
35
35
|
if (!auth)
|
|
36
36
|
return;
|
|
37
|
-
|
|
38
|
-
const result = await newMessage(auth, args.spaceId, args.message.replace(/\\n/g, '\n'), flags.formatted);
|
|
37
|
+
const result = await newMessage(auth, args.spaceId, args.message.replaceAll(String.raw `\n`, '\n'), flags.formatted);
|
|
39
38
|
clearClients();
|
|
40
39
|
if (flags.toon) {
|
|
41
40
|
this.log(formatAsToon(result));
|
|
@@ -3,7 +3,7 @@ import { DEFAULT_PROFILE, readConfig, resolveProfile } from '../../config.js';
|
|
|
3
3
|
import { formatAsToon } from '../../format.js';
|
|
4
4
|
import { clearClients, replyMessage } from '../../gchat/gchat-client.js';
|
|
5
5
|
export default class GChatReplyMessage extends Command {
|
|
6
|
-
/* eslint-disable perfectionist/sort-objects */
|
|
6
|
+
/* eslint-disable perfectionist/sort-objects -- threadName must precede message in CLI arg order */
|
|
7
7
|
static args = {
|
|
8
8
|
threadName: Args.string({
|
|
9
9
|
description: 'Thread name (e.g. spaces/SPACE_ID/threads/THREAD_ID)',
|
|
@@ -36,8 +36,7 @@ export default class GChatReplyMessage extends Command {
|
|
|
36
36
|
const auth = resolveProfile(config, flags.profile, this.log.bind(this));
|
|
37
37
|
if (!auth)
|
|
38
38
|
return;
|
|
39
|
-
|
|
40
|
-
const result = await replyMessage(auth, args.threadName, args.message.replace(/\\n/g, '\n'), flags.formatted);
|
|
39
|
+
const result = await replyMessage(auth, args.threadName, args.message.replaceAll(String.raw `\n`, '\n'), flags.formatted);
|
|
41
40
|
clearClients();
|
|
42
41
|
if (flags.toon) {
|
|
43
42
|
this.log(formatAsToon(result));
|
package/dist/config.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export declare const DEFAULT_PROFILE = "default";
|
|
2
|
-
export
|
|
2
|
+
export type GChatAuth = {
|
|
3
3
|
key: string;
|
|
4
4
|
tokens: Record<string, string>;
|
|
5
|
-
}
|
|
6
|
-
export
|
|
5
|
+
};
|
|
6
|
+
export type GChatConfig = {
|
|
7
7
|
profiles: Record<string, GChatAuth>;
|
|
8
|
-
}
|
|
8
|
+
};
|
|
9
9
|
export declare function readConfigOrEmpty(configDir: string): Promise<GChatConfig>;
|
|
10
10
|
export declare function writeConfig(configDir: string, config: GChatConfig): Promise<void>;
|
|
11
11
|
export declare function readConfig(configDir: string, log: (msg: string) => void): Promise<GChatConfig | null>;
|
package/dist/config.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
2
|
-
import
|
|
2
|
+
import path from 'node:path';
|
|
3
3
|
export const DEFAULT_PROFILE = 'default';
|
|
4
4
|
function parseProfiles(raw) {
|
|
5
5
|
if (raw.profiles && typeof raw.profiles === 'object') {
|
|
@@ -13,7 +13,7 @@ function parseProfiles(raw) {
|
|
|
13
13
|
return { [DEFAULT_PROFILE]: { key: raw.key ?? '', tokens: raw.tokens ?? {} } };
|
|
14
14
|
}
|
|
15
15
|
export async function readConfigOrEmpty(configDir) {
|
|
16
|
-
const configPath = join(configDir, 'gchat-config.json');
|
|
16
|
+
const configPath = path.join(configDir, 'gchat-config.json');
|
|
17
17
|
try {
|
|
18
18
|
const raw = JSON.parse(await readFile(configPath, 'utf8'));
|
|
19
19
|
return { profiles: parseProfiles(raw) };
|
|
@@ -23,12 +23,12 @@ export async function readConfigOrEmpty(configDir) {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
export async function writeConfig(configDir, config) {
|
|
26
|
-
const configPath = join(configDir, 'gchat-config.json');
|
|
26
|
+
const configPath = path.join(configDir, 'gchat-config.json');
|
|
27
27
|
await mkdir(configDir, { recursive: true });
|
|
28
28
|
await writeFile(configPath, JSON.stringify({ profiles: config.profiles }, null, 2));
|
|
29
29
|
}
|
|
30
30
|
export async function readConfig(configDir, log) {
|
|
31
|
-
const configPath = join(configDir, 'gchat-config.json');
|
|
31
|
+
const configPath = path.join(configDir, 'gchat-config.json');
|
|
32
32
|
try {
|
|
33
33
|
const raw = JSON.parse(await readFile(configPath, 'utf8'));
|
|
34
34
|
return { profiles: parseProfiles(raw) };
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type ApiResult = {
|
|
2
2
|
data?: unknown;
|
|
3
3
|
error?: unknown;
|
|
4
4
|
success: boolean;
|
|
5
|
-
}
|
|
5
|
+
};
|
|
6
6
|
export declare class GChatApi {
|
|
7
|
-
private static readonly BASE_URL;
|
|
8
7
|
private readonly apiKey;
|
|
9
8
|
constructor(apiKey: string);
|
|
10
9
|
newMessage(spaceId: string, apiToken: string, message: string, formatted?: boolean): Promise<ApiResult>;
|
package/dist/gchat/gchat-api.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
+
const BASE_URL = 'https://chat.googleapis.com/v1';
|
|
1
2
|
export class GChatApi {
|
|
2
|
-
static BASE_URL = 'https://chat.googleapis.com/v1';
|
|
3
3
|
apiKey;
|
|
4
4
|
constructor(apiKey) {
|
|
5
5
|
this.apiKey = apiKey;
|
|
6
6
|
}
|
|
7
7
|
async newMessage(spaceId, apiToken, message, formatted = false) {
|
|
8
|
-
const url = `${
|
|
8
|
+
const url = `${BASE_URL}/spaces/${spaceId}/messages?key=${this.apiKey}&token=${apiToken}`;
|
|
9
9
|
const payload = { text: message };
|
|
10
10
|
if (formatted)
|
|
11
11
|
payload.formattedText = message;
|
|
12
12
|
return this.post(url, payload);
|
|
13
13
|
}
|
|
14
|
-
// eslint-disable-next-line max-params
|
|
14
|
+
// eslint-disable-next-line max-params -- mirrors the Google Chat reply payload fields
|
|
15
15
|
async replyMessage(threadName, spaceId, apiToken, message, formatted = false) {
|
|
16
|
-
const url = `${
|
|
16
|
+
const url = `${BASE_URL}/spaces/${spaceId}/messages?key=${this.apiKey}&token=${apiToken}&messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD`;
|
|
17
17
|
const payload = { text: message, thread: { name: threadName } };
|
|
18
18
|
if (formatted)
|
|
19
19
|
payload.formattedText = message;
|
|
@@ -21,7 +21,6 @@ export class GChatApi {
|
|
|
21
21
|
}
|
|
22
22
|
async post(url, payload) {
|
|
23
23
|
try {
|
|
24
|
-
// eslint-disable-next-line n/no-unsupported-features/node-builtins -- fetch is available in Node 18+
|
|
25
24
|
const response = await fetch(url, {
|
|
26
25
|
body: JSON.stringify(payload),
|
|
27
26
|
headers: { 'Content-Type': 'application/json' },
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hesed/gchat",
|
|
3
3
|
"description": "CLI for Google Chat API interaction",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.1",
|
|
5
5
|
"author": "Hesed",
|
|
6
6
|
"bin": {
|
|
7
7
|
"gchat": "./bin/run.js"
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@inquirer/prompts": "^8.2.0",
|
|
12
12
|
"@oclif/core": "^4",
|
|
13
|
-
"@toon-format/toon": "^
|
|
13
|
+
"@toon-format/toon": "^4.1.0",
|
|
14
14
|
"fs-extra": "^11.3.3"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
"@types/fs-extra": "^11.0.4",
|
|
22
22
|
"@types/mocha": "^10",
|
|
23
23
|
"@types/node": "^26",
|
|
24
|
-
"@types/sinon": "^
|
|
24
|
+
"@types/sinon": "^22.0.0",
|
|
25
25
|
"c8": "^11.0.0",
|
|
26
26
|
"chai": "^6",
|
|
27
|
-
"eslint": "^
|
|
28
|
-
"eslint-config-oclif": "^
|
|
27
|
+
"eslint": "^10.8.1",
|
|
28
|
+
"eslint-config-oclif": "^7.1.5",
|
|
29
29
|
"eslint-config-prettier": "^10",
|
|
30
30
|
"esmock": "^2.7.3",
|
|
31
31
|
"mocha": "^11",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"typescript": "^5"
|
|
39
39
|
},
|
|
40
40
|
"engines": {
|
|
41
|
-
"node": ">=
|
|
41
|
+
"node": ">=22.0.0"
|
|
42
42
|
},
|
|
43
43
|
"files": [
|
|
44
44
|
"./bin",
|