mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-17 10:02:23 +00:00
fix(mom): private channel messages not being logged
- Add message.groups to required bot events in README - Add groups:history and groups:read to required scopes in README - app_mention handler now logs messages directly instead of relying on message event - Add deduplication in ChannelStore.logMessage() to prevent double-logging - Remove redundant current message append in agent.ts (already in log)
This commit is contained in:
parent
db6d655ee9
commit
706554a5d3
6 changed files with 67 additions and 11 deletions
|
|
@ -35,6 +35,9 @@ export class ChannelStore {
|
|||
private botToken: string;
|
||||
private pendingDownloads: PendingDownload[] = [];
|
||||
private isDownloading = false;
|
||||
// Track recently logged message timestamps to prevent duplicates
|
||||
// Key: "channelId:ts", automatically cleaned up after 60 seconds
|
||||
private recentlyLogged = new Map<string, number>();
|
||||
|
||||
constructor(config: ChannelStoreConfig) {
|
||||
this.workingDir = config.workingDir;
|
||||
|
|
@ -107,8 +110,19 @@ export class ChannelStore {
|
|||
|
||||
/**
|
||||
* Log a message to the channel's log.jsonl
|
||||
* Returns false if message was already logged (duplicate)
|
||||
*/
|
||||
async logMessage(channelId: string, message: LoggedMessage): Promise<void> {
|
||||
async logMessage(channelId: string, message: LoggedMessage): Promise<boolean> {
|
||||
// Check for duplicate (same channel + timestamp)
|
||||
const dedupeKey = `${channelId}:${message.ts}`;
|
||||
if (this.recentlyLogged.has(dedupeKey)) {
|
||||
return false; // Already logged
|
||||
}
|
||||
|
||||
// Mark as logged and schedule cleanup after 60 seconds
|
||||
this.recentlyLogged.set(dedupeKey, Date.now());
|
||||
setTimeout(() => this.recentlyLogged.delete(dedupeKey), 60000);
|
||||
|
||||
const logPath = join(this.getChannelDir(channelId), "log.jsonl");
|
||||
|
||||
// Ensure message has a date field
|
||||
|
|
@ -127,6 +141,7 @@ export class ChannelStore {
|
|||
|
||||
const line = JSON.stringify(message) + "\n";
|
||||
await appendFile(logPath, line, "utf-8");
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue