Skip to content

Black Friday

Annual Pro is $90 for the first year, normally $120. Or start monthly at $6 for two months, then $12.

Ends Dec 4, 11:59 PM PT.

Create an account
← Public packages

@tannerlinsley/imessage

Read, search, draft, and explicitly send iMessages on a Mac, using only built-in macOS tools.

FollowFork

Files

messages.ts

22 lines · 1001 B · TypeScript
import { native, object, integer, filters } from "./core.ts";
import type { ReadInput } from "./core.ts";
import type { MessagePage } from "./types.ts";
/**
 * Read a bounded page of history from one local Messages conversation.
 * @param input - Required chatId, limit (1..50, default 20), beforeMessageId cursor, and ISO after/before timestamps with timezone.
 * @returns Newest stored messages first, decoded text up to 8000 characters, unavailable-text count, and a continuation cursor.
 * @example
 * import messages from 'kody:@tannerlinsley/imessage/messages';
 * const page = await messages({chatId:123,limit:10});
 */
export default async function messages(input: ReadInput): Promise<MessagePage> {
  const p = object(input, ["chatId", "limit", "beforeMessageId", "after", "before"]);
  const limit = integer(p.limit, "limit", 20, 50);
  return native<MessagePage>({
    action: "messages",
    ...filters(p),
    chatId: integer(p.chatId, "chatId"),
    limit,
    scanLimit: limit,
  });
}