link-stack/apps/bridge-worker/tasks/facebook/send-facebook-message.ts
Darren Clarke c1feaa4cb1 feat: Add centralized logging system with @link-stack/logger package
- Create new @link-stack/logger package wrapping Pino for structured logging
- Replace all console.log/error/warn statements across the monorepo
- Configure environment-aware logging (pretty-print in dev, JSON in prod)
- Add automatic redaction of sensitive fields (passwords, tokens, etc.)
- Remove dead commented-out logger file from bridge-worker
- Follow Pino's standard argument order (context object first, message second)
- Support log levels via LOG_LEVEL environment variable
- Export TypeScript types for better IDE support

This provides consistent, structured logging across all applications
and packages, making debugging easier and production logs more parseable.
2025-08-20 11:37:39 +02:00

43 lines
1.1 KiB
TypeScript

import { db } from "@link-stack/bridge-common";
import { createLogger } from "@link-stack/logger";
const logger = createLogger('bridge-worker-send-facebook-message');
interface SendFacebookMessageTaskOptions {
token: string;
to: string;
message: string;
}
const sendFacebookMessageTask = async (
options: SendFacebookMessageTaskOptions,
): Promise<void> => {
const { token, to, message } = options;
const { pageId, pageAccessToken } = await db
.selectFrom("FacebookBot")
.selectAll()
.where("token", "=", token)
.executeTakeFirstOrThrow();
const endpoint = `https://graph.facebook.com/v19.0/${pageId}/messages`;
const outgoingMessage = {
recipient: { id: to },
message: { text: message },
messaging_type: "RESPONSE",
access_token: pageAccessToken,
};
try {
const response = await fetch(endpoint, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(outgoingMessage),
});
} catch (error) {
logger.error({ error });
throw error;
}
};
export default sendFacebookMessageTask;