@hardlydifficult/chat 1.1.3 → 1.1.5
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 +112 -118
- package/dist/Channel.d.ts +34 -8
- package/dist/Channel.d.ts.map +1 -1
- package/dist/Channel.js +52 -22
- package/dist/Channel.js.map +1 -1
- package/dist/ChatClient.d.ts +2 -2
- package/dist/ChatClient.d.ts.map +1 -1
- package/dist/Message.d.ts +21 -14
- package/dist/Message.d.ts.map +1 -1
- package/dist/Message.js +33 -18
- package/dist/Message.js.map +1 -1
- package/dist/discord/DiscordChatClient.d.ts +62 -3
- package/dist/discord/DiscordChatClient.d.ts.map +1 -1
- package/dist/discord/DiscordChatClient.js +220 -22
- package/dist/discord/DiscordChatClient.js.map +1 -1
- package/dist/discord/index.d.ts +1 -1
- package/dist/index.d.ts +8 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -10
- package/dist/index.js.map +1 -1
- package/dist/outputters/discord.d.ts +1 -1
- package/dist/outputters/discord.d.ts.map +1 -1
- package/dist/outputters/discord.js +14 -11
- package/dist/outputters/discord.js.map +1 -1
- package/dist/outputters/index.d.ts +3 -3
- package/dist/outputters/slack.d.ts +2 -2
- package/dist/outputters/slack.d.ts.map +1 -1
- package/dist/outputters/slack.js +29 -29
- package/dist/outputters/slack.js.map +1 -1
- package/dist/slack/SlackChatClient.d.ts +36 -5
- package/dist/slack/SlackChatClient.d.ts.map +1 -1
- package/dist/slack/SlackChatClient.js +206 -13
- package/dist/slack/SlackChatClient.js.map +1 -1
- package/dist/slack/index.d.ts +1 -1
- package/dist/types.d.ts +67 -10
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +2 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -13,194 +13,188 @@ npm install @hardlydifficult/chat
|
|
|
13
13
|
```typescript
|
|
14
14
|
import { createChatClient } from "@hardlydifficult/chat";
|
|
15
15
|
|
|
16
|
-
// Uses DISCORD_TOKEN and DISCORD_GUILD_ID env vars
|
|
17
16
|
const client = createChatClient({ type: "discord" });
|
|
17
|
+
const channel = await client.connect(channelId);
|
|
18
18
|
|
|
19
|
-
//
|
|
20
|
-
|
|
19
|
+
// Post messages
|
|
20
|
+
await channel.postMessage("Hello!");
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
// Listen for incoming messages
|
|
23
|
+
channel.onMessage((event) => {
|
|
24
|
+
console.log(`${event.author.username}: ${event.content}`);
|
|
25
|
+
});
|
|
26
|
+
```
|
|
23
27
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
## Configuration
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
// Discord - env vars: DISCORD_TOKEN, DISCORD_GUILD_ID
|
|
32
|
+
createChatClient({ type: "discord" });
|
|
33
|
+
createChatClient({ type: "discord", token: "...", guildId: "..." });
|
|
34
|
+
|
|
35
|
+
// Slack - env vars: SLACK_BOT_TOKEN, SLACK_APP_TOKEN
|
|
36
|
+
createChatClient({ type: "slack" });
|
|
37
|
+
createChatClient({ type: "slack", token: "...", appToken: "..." });
|
|
30
38
|
```
|
|
31
39
|
|
|
32
|
-
##
|
|
40
|
+
## Incoming Messages
|
|
33
41
|
|
|
34
|
-
|
|
42
|
+
Subscribe to new messages in a channel. Returns an unsubscribe function.
|
|
35
43
|
|
|
36
44
|
```typescript
|
|
37
|
-
|
|
38
|
-
|
|
45
|
+
const unsubscribe = channel.onMessage((event) => {
|
|
46
|
+
// event.id, event.content, event.author, event.channelId, event.timestamp
|
|
47
|
+
console.log(`${event.author.username}: ${event.content}`);
|
|
48
|
+
});
|
|
39
49
|
|
|
40
|
-
|
|
41
|
-
|
|
50
|
+
// Later: stop listening
|
|
51
|
+
unsubscribe();
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Messages from the bot itself are automatically filtered out.
|
|
55
|
+
|
|
56
|
+
## Posting Messages
|
|
57
|
+
|
|
58
|
+
Content can be a string or a `Document` from `@hardlydifficult/document-generator`.
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
// Simple text
|
|
62
|
+
channel.postMessage("Hello!");
|
|
63
|
+
|
|
64
|
+
// Rich document (auto-converted to Discord Embed / Slack Block Kit)
|
|
65
|
+
import { Document } from "@hardlydifficult/document-generator";
|
|
42
66
|
|
|
43
67
|
const report = new Document()
|
|
44
68
|
.header("Daily Report")
|
|
45
69
|
.text("Here are today's **highlights**:")
|
|
46
|
-
.list(["Feature A completed", "Bug B fixed", "99.9% uptime"])
|
|
47
|
-
.divider()
|
|
48
|
-
.link("View dashboard", "https://example.com/dashboard")
|
|
49
|
-
.context("Generated automatically");
|
|
70
|
+
.list(["Feature A completed", "Bug B fixed", "99.9% uptime"]);
|
|
50
71
|
|
|
51
|
-
|
|
52
|
-
await channel.postMessage(report);
|
|
72
|
+
channel.postMessage(report);
|
|
53
73
|
```
|
|
54
74
|
|
|
55
|
-
|
|
75
|
+
### File Attachments
|
|
56
76
|
|
|
57
|
-
|
|
77
|
+
Send files as message attachments.
|
|
58
78
|
|
|
59
79
|
```typescript
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
80
|
+
channel.postMessage("Here's the scan report", {
|
|
81
|
+
files: [
|
|
82
|
+
{ content: Buffer.from(markdownContent), name: "report.md" },
|
|
83
|
+
{ content: "plain text content", name: "notes.txt" },
|
|
84
|
+
],
|
|
85
|
+
});
|
|
63
86
|
```
|
|
64
87
|
|
|
65
|
-
|
|
88
|
+
## Message Operations
|
|
66
89
|
|
|
67
90
|
```typescript
|
|
68
|
-
const msg = await channel.postMessage(
|
|
69
|
-
await msg.delete();
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
### Thread Replies
|
|
91
|
+
const msg = await channel.postMessage("Hello");
|
|
73
92
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
msg.postReply(
|
|
77
|
-
msg.postReply(new Document().text('Rich reply with **formatting**'));
|
|
93
|
+
await msg.update("Updated content");
|
|
94
|
+
await msg.delete();
|
|
95
|
+
msg.postReply("Thread reply");
|
|
78
96
|
```
|
|
79
97
|
|
|
80
98
|
### Reactions
|
|
81
99
|
|
|
82
100
|
```typescript
|
|
83
|
-
// Add reactions and listen for user votes (chainable)
|
|
84
101
|
await channel
|
|
85
102
|
.postMessage("Pick one")
|
|
86
|
-
.addReactions(["👍", "👎"
|
|
103
|
+
.addReactions(["👍", "👎"])
|
|
87
104
|
.onReaction((event) => {
|
|
88
105
|
console.log(`${event.user.username} reacted with ${event.emoji}`);
|
|
89
106
|
});
|
|
90
107
|
|
|
91
|
-
//
|
|
92
|
-
const msg = await channel.postMessage("Loading...").wait();
|
|
93
|
-
msg.addReactions(["✅"]);
|
|
94
|
-
await msg.waitForReactions();
|
|
108
|
+
msg.offReaction(); // stop listening
|
|
95
109
|
```
|
|
96
110
|
|
|
97
|
-
|
|
111
|
+
### Threads
|
|
98
112
|
|
|
99
|
-
|
|
113
|
+
Create a thread from an existing message.
|
|
100
114
|
|
|
101
115
|
```typescript
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
// Slack - env vars: SLACK_BOT_TOKEN, SLACK_APP_TOKEN
|
|
107
|
-
createChatClient({ type: 'slack' });
|
|
108
|
-
createChatClient({ type: 'slack', token: '...', appToken: '...' });
|
|
116
|
+
const msg = await channel.postMessage("Starting a discussion");
|
|
117
|
+
const thread = await msg.startThread("Discussion Thread", {
|
|
118
|
+
autoArchiveDuration: 1440, // minutes
|
|
119
|
+
});
|
|
109
120
|
```
|
|
110
121
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
Connect to a channel.
|
|
114
|
-
|
|
115
|
-
### `channel.postMessage(content): Message`
|
|
116
|
-
|
|
117
|
-
Post a message. Content can be a string or a Document.
|
|
122
|
+
> **Slack note:** Slack threads are implicit — calling `startThread()` returns the message's timestamp as the thread ID. Post replies with `msg.postReply()` to populate the thread.
|
|
118
123
|
|
|
119
|
-
|
|
124
|
+
## Typing Indicator
|
|
120
125
|
|
|
121
|
-
|
|
126
|
+
Show a "typing" indicator while processing.
|
|
122
127
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
+
```typescript
|
|
129
|
+
await channel.sendTyping();
|
|
130
|
+
// ... do work ...
|
|
131
|
+
await channel.postMessage("Done!");
|
|
132
|
+
```
|
|
128
133
|
|
|
129
|
-
|
|
134
|
+
> **Slack note:** Slack does not support bot typing indicators. `sendTyping()` is a no-op on Slack.
|
|
130
135
|
|
|
131
|
-
|
|
136
|
+
## Bulk Operations
|
|
132
137
|
|
|
133
|
-
Delete
|
|
138
|
+
Delete messages and manage threads in bulk.
|
|
134
139
|
|
|
135
|
-
|
|
140
|
+
```typescript
|
|
141
|
+
// Delete up to 100 recent messages
|
|
142
|
+
const deletedCount = await channel.bulkDelete(50);
|
|
143
|
+
|
|
144
|
+
// Get all threads (active and archived)
|
|
145
|
+
const threads = await channel.getThreads();
|
|
146
|
+
for (const thread of threads) {
|
|
147
|
+
console.log(thread.id);
|
|
148
|
+
}
|
|
149
|
+
```
|
|
136
150
|
|
|
137
|
-
|
|
151
|
+
> **Slack note:** Slack has no bulk delete API — messages are deleted one-by-one. Some may fail if the bot lacks permission to delete others' messages. `getThreads()` scans recent channel history for messages with replies.
|
|
138
152
|
|
|
139
|
-
|
|
153
|
+
## Connection Resilience
|
|
140
154
|
|
|
141
|
-
|
|
155
|
+
Both platforms auto-reconnect via their underlying libraries (discord.js and @slack/bolt). Register callbacks for observability.
|
|
142
156
|
|
|
143
157
|
```typescript
|
|
144
|
-
|
|
145
|
-
.postMessage("Vote!")
|
|
146
|
-
.addReactions(["👍", "👎"])
|
|
147
|
-
.onReaction((event) => {
|
|
148
|
-
// event.emoji, event.user.id, event.user.username,
|
|
149
|
-
// event.messageId, event.channelId, event.timestamp
|
|
150
|
-
});
|
|
151
|
-
```
|
|
158
|
+
const client = createChatClient({ type: "discord" });
|
|
152
159
|
|
|
153
|
-
|
|
160
|
+
client.onDisconnect((reason) => {
|
|
161
|
+
console.log("Disconnected:", reason);
|
|
162
|
+
});
|
|
154
163
|
|
|
155
|
-
|
|
164
|
+
client.onError((error) => {
|
|
165
|
+
console.error("Connection error:", error);
|
|
166
|
+
});
|
|
156
167
|
|
|
157
|
-
|
|
168
|
+
await client.disconnect(); // clean shutdown
|
|
169
|
+
```
|
|
158
170
|
|
|
159
|
-
|
|
171
|
+
Both callbacks return an unsubscribe function.
|
|
160
172
|
|
|
161
173
|
## Platform Setup
|
|
162
174
|
|
|
163
175
|
### Discord
|
|
164
176
|
|
|
165
177
|
1. Create bot at [Discord Developer Portal](https://discord.com/developers/applications)
|
|
166
|
-
2. Enable Gateway Intents: `GUILDS`, `GUILD_MESSAGES`, `GUILD_MESSAGE_REACTIONS`
|
|
167
|
-
3. Bot permissions: `Send Messages`, `Add Reactions`, `Read Message History`
|
|
178
|
+
2. Enable Gateway Intents: `GUILDS`, `GUILD_MESSAGES`, `GUILD_MESSAGE_REACTIONS`, `MESSAGE_CONTENT`
|
|
179
|
+
3. Bot permissions: `Send Messages`, `Add Reactions`, `Read Message History`, `Manage Messages` (for bulk delete), `Create Public Threads`, `Send Messages in Threads`
|
|
168
180
|
4. Set `DISCORD_TOKEN` and `DISCORD_GUILD_ID` env vars
|
|
169
181
|
|
|
170
182
|
### Slack
|
|
171
183
|
|
|
172
184
|
1. Create app at [Slack API](https://api.slack.com/apps)
|
|
173
185
|
2. Enable Socket Mode, generate App Token
|
|
174
|
-
3. Bot scopes: `chat:write`, `chat:write.public`, `reactions:write`, `reactions:read`
|
|
175
|
-
4. Subscribe to: `reaction_added`
|
|
186
|
+
3. Bot scopes: `chat:write`, `chat:write.public`, `reactions:write`, `reactions:read`, `channels:history`, `files:write`
|
|
187
|
+
4. Subscribe to events: `reaction_added`, `message.channels`
|
|
176
188
|
5. Set `SLACK_BOT_TOKEN` and `SLACK_APP_TOKEN` env vars
|
|
177
189
|
|
|
178
|
-
##
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
const votes: Record<string, string> = {};
|
|
190
|
-
|
|
191
|
-
const pollDoc = new Document()
|
|
192
|
-
.header("🗳️ Lunch Poll")
|
|
193
|
-
.text("What should we order?")
|
|
194
|
-
.list(options.map((o, i) => `${emojis[i]} ${o}`));
|
|
195
|
-
|
|
196
|
-
await channel
|
|
197
|
-
.postMessage(pollDoc)
|
|
198
|
-
.addReactions(emojis)
|
|
199
|
-
.onReaction((event) => {
|
|
200
|
-
const choice = options[emojis.indexOf(event.emoji)];
|
|
201
|
-
if (choice) {
|
|
202
|
-
votes[event.user.id] = choice;
|
|
203
|
-
console.log(`${event.user.username} voted for ${choice}`);
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
```
|
|
190
|
+
## Platform Differences
|
|
191
|
+
|
|
192
|
+
| Feature | Discord | Slack |
|
|
193
|
+
|---|---|---|
|
|
194
|
+
| Incoming messages | Full support | Full support |
|
|
195
|
+
| Typing indicator | Full support | No-op (unsupported by Slack bot API) |
|
|
196
|
+
| File attachments | `AttachmentBuilder` | `filesUploadV2` |
|
|
197
|
+
| Thread creation | Creates named thread on message | Returns message timestamp (threads are implicit) |
|
|
198
|
+
| Bulk delete | Native `bulkDelete` API (fast) | One-by-one deletion (slower, may partially fail) |
|
|
199
|
+
| Get threads | `fetchActive` + `fetchArchived` | Scans channel history for threaded messages |
|
|
200
|
+
| Auto-reconnect | Handled by discord.js | Handled by `@slack/bolt` Socket Mode |
|
package/dist/Channel.d.ts
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { Message } from "./Message";
|
|
2
|
+
import type { DisconnectCallback, ErrorCallback, FileAttachment, MessageCallback, MessageContent, MessageData, Platform, ReactionCallback, StartThreadOptions, ThreadData } from "./types";
|
|
3
3
|
/**
|
|
4
4
|
* Interface for platform-specific channel operations
|
|
5
5
|
*/
|
|
6
6
|
export interface ChannelOperations {
|
|
7
7
|
postMessage(channelId: string, content: MessageContent, options?: {
|
|
8
8
|
threadTs?: string;
|
|
9
|
-
|
|
10
|
-
unfurlMedia?: boolean;
|
|
9
|
+
files?: FileAttachment[];
|
|
11
10
|
}): Promise<MessageData>;
|
|
12
11
|
updateMessage(messageId: string, channelId: string, content: MessageContent): Promise<void>;
|
|
13
12
|
deleteMessage(messageId: string, channelId: string): Promise<void>;
|
|
14
13
|
addReaction(messageId: string, channelId: string, emoji: string): Promise<void>;
|
|
15
14
|
subscribeToReactions(channelId: string, callback: ReactionCallback): () => void;
|
|
15
|
+
subscribeToMessages(channelId: string, callback: MessageCallback): () => void;
|
|
16
|
+
sendTyping(channelId: string): Promise<void>;
|
|
17
|
+
startThread(messageId: string, channelId: string, name: string, options?: StartThreadOptions): Promise<ThreadData>;
|
|
18
|
+
bulkDelete(channelId: string, count: number): Promise<number>;
|
|
19
|
+
getThreads(channelId: string): Promise<ThreadData[]>;
|
|
20
|
+
onDisconnect(callback: DisconnectCallback): () => void;
|
|
21
|
+
onError(callback: ErrorCallback): () => void;
|
|
16
22
|
}
|
|
17
23
|
/**
|
|
18
24
|
* Represents a connected channel with messaging capabilities
|
|
@@ -27,14 +33,13 @@ export declare class Channel {
|
|
|
27
33
|
/**
|
|
28
34
|
* Post a message to this channel
|
|
29
35
|
* @param content - Message content (string or Document)
|
|
30
|
-
* @param options - Optional message options (e.g., threadTs for threading,
|
|
36
|
+
* @param options - Optional message options (e.g., threadTs for threading, files for attachments)
|
|
31
37
|
* @returns Message object with chainable reaction methods
|
|
32
38
|
*/
|
|
33
39
|
postMessage(content: MessageContent, options?: {
|
|
34
40
|
threadTs?: string;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}): Message;
|
|
41
|
+
files?: FileAttachment[];
|
|
42
|
+
}): Message & PromiseLike<Message>;
|
|
38
43
|
/**
|
|
39
44
|
* Emit a reaction event to registered message-specific callbacks
|
|
40
45
|
*/
|
|
@@ -48,6 +53,27 @@ export declare class Channel {
|
|
|
48
53
|
* Create MessageOperations from ChannelOperations
|
|
49
54
|
*/
|
|
50
55
|
private createMessageOperations;
|
|
56
|
+
/**
|
|
57
|
+
* Subscribe to incoming messages in this channel
|
|
58
|
+
* @param callback - Function called when a new message is received
|
|
59
|
+
* @returns Unsubscribe function
|
|
60
|
+
*/
|
|
61
|
+
onMessage(callback: MessageCallback): () => void;
|
|
62
|
+
/**
|
|
63
|
+
* Send a typing indicator in this channel
|
|
64
|
+
*/
|
|
65
|
+
sendTyping(): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Bulk delete messages in this channel
|
|
68
|
+
* @param count - Number of recent messages to delete
|
|
69
|
+
* @returns Number of messages actually deleted
|
|
70
|
+
*/
|
|
71
|
+
bulkDelete(count: number): Promise<number>;
|
|
72
|
+
/**
|
|
73
|
+
* Get all threads in this channel (active and archived)
|
|
74
|
+
* @returns Array of thread data
|
|
75
|
+
*/
|
|
76
|
+
getThreads(): Promise<ThreadData[]>;
|
|
51
77
|
/**
|
|
52
78
|
* Disconnect from this channel (cleanup)
|
|
53
79
|
*/
|
package/dist/Channel.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Channel.d.ts","sourceRoot":"","sources":["../src/Channel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"Channel.d.ts","sourceRoot":"","sources":["../src/Channel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAA0B,MAAM,WAAW,CAAC;AAC5D,OAAO,KAAK,EACV,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,eAAe,EACf,cAAc,EACd,WAAW,EACX,QAAQ,EAC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AAC,QAAQ,EAAE,kBAAkB,GAAG,MAAM,IAAI,CAAC;IACvD,OAAO,CAAC,QAAQ,EAAE,aAAa,GAAG,MAAM,IAAI,CAAC;CAC9C;AAED;;GAEG;AACH,qBAAa,OAAO;IAClB,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,SAAgB,QAAQ,EAAE,QAAQ,CAAC;IAEnC,OAAO,CAAC,UAAU,CAAoB;IACtC,OAAO,CAAC,wBAAwB,CAA4C;IAC5E,OAAO,CAAC,uBAAuB,CAA6B;gBAEhD,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,iBAAiB;IAYzE;;;;;OAKG;IACH,WAAW,CACT,OAAO,EAAE,cAAc,EACvB,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,cAAc,EAAE,CAAA;KAAE,GACxD,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC;IAejC;;OAEG;YACW,YAAY;IAe1B;;;OAGG;IACH,OAAO,CAAC,2BAA2B;IAmBnC;;OAEG;IACH,OAAO,CAAC,uBAAuB;IA2B/B;;;;OAIG;IACH,SAAS,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM,IAAI;IAIhD;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjC;;;;OAIG;IACG,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIhD;;;OAGG;IACG,UAAU,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;IAIzC;;OAEG;IACH,UAAU,IAAI,IAAI;CAOnB"}
|
package/dist/Channel.js
CHANGED
|
@@ -21,14 +21,13 @@ class Channel {
|
|
|
21
21
|
/**
|
|
22
22
|
* Post a message to this channel
|
|
23
23
|
* @param content - Message content (string or Document)
|
|
24
|
-
* @param options - Optional message options (e.g., threadTs for threading,
|
|
24
|
+
* @param options - Optional message options (e.g., threadTs for threading, files for attachments)
|
|
25
25
|
* @returns Message object with chainable reaction methods
|
|
26
26
|
*/
|
|
27
27
|
postMessage(content, options) {
|
|
28
28
|
const messagePromise = this.operations.postMessage(this.id, content, options);
|
|
29
29
|
// Create a Message that will resolve once the post completes
|
|
30
|
-
|
|
31
|
-
return pendingMessage;
|
|
30
|
+
return new PendingMessage(messagePromise, this.createMessageOperations(), this.platform);
|
|
32
31
|
}
|
|
33
32
|
/**
|
|
34
33
|
* Emit a reaction event to registered message-specific callbacks
|
|
@@ -39,7 +38,7 @@ class Channel {
|
|
|
39
38
|
return;
|
|
40
39
|
}
|
|
41
40
|
const promises = Array.from(callbacks).map((cb) => Promise.resolve(cb(event)).catch((err) => {
|
|
42
|
-
console.error(
|
|
41
|
+
console.error("Reaction callback error:", err);
|
|
43
42
|
}));
|
|
44
43
|
await Promise.all(promises);
|
|
45
44
|
}
|
|
@@ -71,8 +70,38 @@ class Channel {
|
|
|
71
70
|
deleteMessage: (messageId, channelId) => this.operations.deleteMessage(messageId, channelId),
|
|
72
71
|
postReply: async (channelId, threadTs, content) => this.operations.postMessage(channelId, content, { threadTs }),
|
|
73
72
|
subscribeToReactions: (messageId, callback) => this.subscribeToMessageReactions(messageId, callback),
|
|
73
|
+
startThread: (messageId, channelId, name, options) => this.operations.startThread(messageId, channelId, name, options),
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Subscribe to incoming messages in this channel
|
|
78
|
+
* @param callback - Function called when a new message is received
|
|
79
|
+
* @returns Unsubscribe function
|
|
80
|
+
*/
|
|
81
|
+
onMessage(callback) {
|
|
82
|
+
return this.operations.subscribeToMessages(this.id, callback);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Send a typing indicator in this channel
|
|
86
|
+
*/
|
|
87
|
+
async sendTyping() {
|
|
88
|
+
await this.operations.sendTyping(this.id);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Bulk delete messages in this channel
|
|
92
|
+
* @param count - Number of recent messages to delete
|
|
93
|
+
* @returns Number of messages actually deleted
|
|
94
|
+
*/
|
|
95
|
+
async bulkDelete(count) {
|
|
96
|
+
return this.operations.bulkDelete(this.id, count);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Get all threads in this channel (active and archived)
|
|
100
|
+
* @returns Array of thread data
|
|
101
|
+
*/
|
|
102
|
+
async getThreads() {
|
|
103
|
+
return this.operations.getThreads(this.id);
|
|
104
|
+
}
|
|
76
105
|
/**
|
|
77
106
|
* Disconnect from this channel (cleanup)
|
|
78
107
|
*/
|
|
@@ -87,22 +116,26 @@ class Channel {
|
|
|
87
116
|
exports.Channel = Channel;
|
|
88
117
|
/**
|
|
89
118
|
* A Message that is still being posted.
|
|
90
|
-
*
|
|
119
|
+
* Implements PromiseLike so it can be directly awaited:
|
|
120
|
+
* const msg = await channel.postMessage('Hello');
|
|
121
|
+
*
|
|
122
|
+
* Also supports synchronous chaining before awaiting:
|
|
123
|
+
* await channel.postMessage('Vote!').addReactions(['👍', '👎']).onReaction(cb);
|
|
91
124
|
*/
|
|
92
125
|
class PendingMessage extends Message_1.Message {
|
|
93
126
|
postPromise;
|
|
94
127
|
deferredReactionCallbacks = [];
|
|
95
128
|
constructor(postPromise, operations, platform) {
|
|
96
129
|
// Initialize with placeholder data using the correct platform
|
|
97
|
-
super({ id:
|
|
130
|
+
super({ id: "", channelId: "", platform }, operations);
|
|
98
131
|
this.postPromise = postPromise;
|
|
99
132
|
// Update our data when the post resolves and subscribe any deferred listeners
|
|
100
133
|
this.postPromise
|
|
101
134
|
.then((data) => {
|
|
102
135
|
// Update the readonly properties via Object.defineProperty
|
|
103
|
-
Object.defineProperty(this,
|
|
104
|
-
Object.defineProperty(this,
|
|
105
|
-
Object.defineProperty(this,
|
|
136
|
+
Object.defineProperty(this, "id", { value: data.id });
|
|
137
|
+
Object.defineProperty(this, "channelId", { value: data.channelId });
|
|
138
|
+
Object.defineProperty(this, "platform", { value: data.platform });
|
|
106
139
|
// Subscribe deferred reaction callbacks now that we have the message ID
|
|
107
140
|
for (const callback of this.deferredReactionCallbacks) {
|
|
108
141
|
const unsubscribe = this.operations.subscribeToReactions(data.id, callback);
|
|
@@ -110,7 +143,7 @@ class PendingMessage extends Message_1.Message {
|
|
|
110
143
|
}
|
|
111
144
|
})
|
|
112
145
|
.catch(() => {
|
|
113
|
-
// Errors
|
|
146
|
+
// Errors surfaced when awaited via then()
|
|
114
147
|
});
|
|
115
148
|
}
|
|
116
149
|
/**
|
|
@@ -133,19 +166,16 @@ class PendingMessage extends Message_1.Message {
|
|
|
133
166
|
return this;
|
|
134
167
|
}
|
|
135
168
|
/**
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
* @example
|
|
140
|
-
* ```typescript
|
|
141
|
-
* const msg = channel.postMessage('Hello');
|
|
142
|
-
* await msg.wait(); // throws if post fails
|
|
143
|
-
* console.log(msg.id); // now available
|
|
144
|
-
* ```
|
|
169
|
+
* Makes PendingMessage directly awaitable.
|
|
170
|
+
* Resolves to a plain Message (not thenable) to prevent infinite await loops.
|
|
145
171
|
*/
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
172
|
+
then(onfulfilled, onrejected) {
|
|
173
|
+
const resolved = this.postPromise.then(async () => {
|
|
174
|
+
await this.pendingReactions;
|
|
175
|
+
// Return a plain Message (no then()) to stop await from recursing
|
|
176
|
+
return this.toSnapshot();
|
|
177
|
+
});
|
|
178
|
+
return resolved.then(onfulfilled, onrejected);
|
|
149
179
|
}
|
|
150
180
|
/**
|
|
151
181
|
* Wait for post and all pending reactions to complete.
|
package/dist/Channel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Channel.js","sourceRoot":"","sources":["../src/Channel.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"Channel.js","sourceRoot":"","sources":["../src/Channel.ts"],"names":[],"mappings":";;;AAAA,uCAA4D;AAoD5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AAC,WAAW,CAAC,IAAI,CAC3C,GAAG,EAAE,CAAC,uBAAuB,CAC9B,CAAC;QACF,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,GAAG,EAAE,CACtD,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAC5D,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACM,UAAU,CAAC,QAA0B;QAC5C,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC9C,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACH,IAAI,CACF,WAA2E,EAC3E,UAA2E;QAE3E,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE;YAChD,MAAM,IAAI,CAAC,gBAAgB,CAAC;YAC5B,kEAAkE;YAClE,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC;QAC3B,CAAC,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IAChD,CAAC;IAED;;OAEG;IACM,KAAK,CAAC,gBAAgB;QAC7B,MAAM,IAAI,CAAC,WAAW,CAAC;QACvB,MAAM,IAAI,CAAC,gBAAgB,CAAC;IAC9B,CAAC;CACF"}
|
package/dist/ChatClient.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { Channel } from "./Channel";
|
|
2
|
+
import type { ChatConfig } from "./types";
|
|
3
3
|
/**
|
|
4
4
|
* Abstract base class for chat platform clients
|
|
5
5
|
* Provides a unified API for Discord and Slack
|
package/dist/ChatClient.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatClient.d.ts","sourceRoot":"","sources":["../src/ChatClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"ChatClient.d.ts","sourceRoot":"","sources":["../src/ChatClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C;;;GAGG;AACH,8BAAsB,UAAU;IAClB,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,UAAU;gBAAlB,MAAM,EAAE,UAAU;IAEjD;;;;OAIG;IACH,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAErD;;OAEG;IACH,QAAQ,CAAC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CACrC"}
|
package/dist/Message.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { MessageContent, MessageData, Platform, ReactionCallback, StartThreadOptions, ThreadData } from "./types";
|
|
2
2
|
/**
|
|
3
3
|
* Interface for the platform-specific reaction adder
|
|
4
4
|
*/
|
|
@@ -13,6 +13,7 @@ export interface MessageOperations extends ReactionAdder {
|
|
|
13
13
|
deleteMessage(messageId: string, channelId: string): Promise<void>;
|
|
14
14
|
postReply(channelId: string, threadTs: string, content: MessageContent): Promise<MessageData>;
|
|
15
15
|
subscribeToReactions(messageId: string, callback: ReactionCallback): () => void;
|
|
16
|
+
startThread(messageId: string, channelId: string, name: string, options?: StartThreadOptions): Promise<ThreadData>;
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
19
|
* Represents a posted message with chainable reaction methods
|
|
@@ -25,6 +26,11 @@ export declare class Message {
|
|
|
25
26
|
protected operations: MessageOperations;
|
|
26
27
|
protected reactionUnsubscribers: (() => void)[];
|
|
27
28
|
constructor(data: MessageData, operations: MessageOperations);
|
|
29
|
+
/**
|
|
30
|
+
* Create a plain Message snapshot, transferring reaction unsubscribers.
|
|
31
|
+
* Used by PendingMessage/ReplyMessage to resolve to a non-thenable Message.
|
|
32
|
+
*/
|
|
33
|
+
protected toSnapshot(): Message;
|
|
28
34
|
/**
|
|
29
35
|
* Add multiple emoji reactions to this message
|
|
30
36
|
* @param emojis - Array of emojis to add
|
|
@@ -56,7 +62,14 @@ export declare class Message {
|
|
|
56
62
|
* @param content - Reply content (string or Document)
|
|
57
63
|
* @returns ReplyMessage that can be awaited to handle success/failure
|
|
58
64
|
*/
|
|
59
|
-
postReply(content: MessageContent):
|
|
65
|
+
postReply(content: MessageContent): Message & PromiseLike<Message>;
|
|
66
|
+
/**
|
|
67
|
+
* Create a thread from this message
|
|
68
|
+
* @param name - Thread name
|
|
69
|
+
* @param options - Optional thread options
|
|
70
|
+
* @returns Channel-like object for posting into the thread
|
|
71
|
+
*/
|
|
72
|
+
startThread(name: string, options?: StartThreadOptions): Promise<ThreadData>;
|
|
60
73
|
/**
|
|
61
74
|
* Update this message's content
|
|
62
75
|
* @param content - New content (string or Document)
|
|
@@ -80,9 +93,10 @@ export declare class Message {
|
|
|
80
93
|
}
|
|
81
94
|
/**
|
|
82
95
|
* A reply message that is still being posted.
|
|
83
|
-
*
|
|
96
|
+
* Implements PromiseLike so it can be directly awaited:
|
|
97
|
+
* const reply = await msg.postReply('text');
|
|
84
98
|
*/
|
|
85
|
-
export declare class ReplyMessage extends Message {
|
|
99
|
+
export declare class ReplyMessage extends Message implements PromiseLike<Message> {
|
|
86
100
|
private replyPromise;
|
|
87
101
|
private deferredReactionCallbacks;
|
|
88
102
|
constructor(replyPromise: Promise<MessageData>, operations: MessageOperations, platform: Platform);
|
|
@@ -95,17 +109,10 @@ export declare class ReplyMessage extends Message {
|
|
|
95
109
|
*/
|
|
96
110
|
onReaction(callback: ReactionCallback): this;
|
|
97
111
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* ```typescript
|
|
103
|
-
* const reply = msg.postReply('text');
|
|
104
|
-
* await reply.wait(); // throws if reply fails
|
|
105
|
-
* console.log(reply.id); // now available
|
|
106
|
-
* ```
|
|
112
|
+
* Makes ReplyMessage directly awaitable.
|
|
113
|
+
* Resolves to a plain Message (not thenable) to prevent infinite await loops.
|
|
107
114
|
*/
|
|
108
|
-
|
|
115
|
+
then<TResult1 = Message, TResult2 = never>(onfulfilled?: ((value: Message) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
109
116
|
/**
|
|
110
117
|
* Wait for reply and all pending reactions to complete.
|
|
111
118
|
*/
|