Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

1.8 KB
Raw Blame
/**
 * Prints what the composer's thread helpers (`lib/threadReplies.ts`) answer for
 * each platform given as an argument (a reply that is a poll included), so `ThreadRepliesParityTest.php` can
 * compare them with `ThreadReplies` on the server.
 *
 * Node strips type annotations on import; the resolve hook maps the `@/` alias
 * and extension-less specifiers onto `resources/js/**.ts`.
 */
import { registerHooks } from 'node:module';
import path from 'node:path';
import { pathToFileURL } from 'node:url';

const [resourcesDir, ...platforms] = process.argv.slice(2);

registerHooks({
    resolve: (specifier, context, nextResolve) =>
        specifier.startsWith('@/')
            ? nextResolve(pathToFileURL(path.join(path.resolve(resourcesDir), `${specifier.slice(2)}.ts`)).href, context)
            : nextResolve(specifier, context),
});

const {
    replyEmptyKey,
    replyTooLongKey,
    startThreadKey,
    threadMaxReplies,
    threadReplyContentType,
} = await import(
    pathToFileURL(path.join(path.resolve(resourcesDir), 'lib/threadReplies.ts')).href
);
const { THREAD_REPLY_CONTENT_TYPES } = await import(
    pathToFileURL(path.join(path.resolve(resourcesDir), 'types/network-options.ts')).href
);

const pollReply = { text: 'Which one?', media: [], poll: { options: ['Yes', 'No'] } };

const results = Object.fromEntries(
    platforms.map((platform) => [
        platform,
        {
            reply_content_type: THREAD_REPLY_CONTENT_TYPES[platform] ?? null,
            reply_poll_content_type: threadReplyContentType(platform, pollReply) ?? null,
            max_replies: threadMaxReplies(platform),
            empty_key: replyEmptyKey(platform),
            too_long_key: replyTooLongKey(platform),
            start_key: startThreadKey(platform),
        },
    ]),
);

console.log(JSON.stringify(results));