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

conversations.ts

29 lines · 1.3 KB · TypeScript
import { native, object, integer, filters, text } from "./core.ts";
import type { ConversationPage } from "./types.ts";
/**
 * List local Messages conversations to find the exact chat ID and participants.
 * @param input - limit (1..50, default 20), beforeChatId cursor, and optional iMessage, SMS, or RCS service, and participant phone or email (exact address, phone formatting ignored, no country-code guessing).
 * @returns Conversations in descending creation ID order, participants, and the next cursor. No message content.
 * @example
 * import conversations from 'kody:@tannerlinsley/imessage/conversations';
 * const page = await conversations({limit:10,service:'iMessage'});
 */
export default async function conversations(
  input: {
    limit?: number;
    beforeChatId?: number;
    participant?: string;
    service?: "iMessage" | "SMS" | "RCS";
  } = {},
): Promise<ConversationPage> {
  const p = object(input, ["limit", "beforeChatId", "service", "participant"]);
  const options = filters(p);
  if (p.participant !== undefined)
    options.participant = text(p.participant, "participant", 254).trim();
  if (p.beforeChatId !== undefined) options.beforeChatId = integer(p.beforeChatId, "beforeChatId");
  return native<ConversationPage>({
    action: "conversations",
    ...options,
    limit: integer(p.limit, "limit", 20, 50),
  });
}