Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/bot/core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["src/**/*.ts"]
}
}
4 changes: 2 additions & 2 deletions packages/bot/discord/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["src/**/*.ts"]
}
}
4 changes: 2 additions & 2 deletions packages/bot/signal/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["src/**/*.ts"]
}
}
4 changes: 2 additions & 2 deletions packages/bot/telegram/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["src/**/*.ts"]
}
}
21 changes: 18 additions & 3 deletions packages/bot/whatsapp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ export interface IncomingMessage {
}

type MessageHandler = (msg: IncomingMessage) => void | Promise<void>;
type WhatsAppTimestamp = number | string | { toNumber?: () => number };

function toUnixMs(timestamp: WhatsAppTimestamp | null | undefined): number {
if (typeof timestamp === "number") return timestamp * 1000;
if (typeof timestamp === "string") {
const numeric = Number(timestamp);
return Number.isFinite(numeric) ? numeric * 1000 : Date.now();
}

const numeric = timestamp?.toNumber?.();
if (typeof numeric === "number" && Number.isFinite(numeric)) return numeric * 1000;

return Date.now();
}

export class WhatsAppBot {
private sock: WASocket | null = null;
Expand Down Expand Up @@ -54,7 +68,8 @@ export class WhatsAppBot {
for (const msg of messages) {
if (!msg.message || msg.key.fromMe) continue;

const chatId = msg.key.remoteJid!;
const chatId = msg.key.remoteJid;
if (!chatId) continue;
const isGroup = chatId.endsWith("@g.us");
const text =
msg.message.conversation ||
Expand All @@ -65,7 +80,7 @@ export class WhatsAppBot {
source: chatId,
sourceName: msg.pushName || "User",
text,
timestamp: msg.messageTimestamp * 1000,
timestamp: toUnixMs(msg.messageTimestamp),
chatId,
isGroup,
attachments: [],
Expand Down Expand Up @@ -125,4 +140,4 @@ export function loadConfig(env: Record<string, string | undefined>): Config {
allowedUsers: env.ALLOWED_USERS?.split(",").map((u) => u.trim()).filter(Boolean) || [],
adminUsers: env.ADMIN_USERS?.split(",").map((u) => u.trim()).filter(Boolean) || [],
});
}
}
4 changes: 2 additions & 2 deletions packages/bot/whatsapp/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["src/**/*.ts"]
}
}