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

search.ts

31 lines · 1.3 KB · TypeScript
import { native, object, integer, filters, text } from "./core.ts";
import type { SearchInput } from "./core.ts";
import type { MessagePage } from "./types.ts";
/**
 * Search local message text with a literal, case-insensitive substring, including archived text.
 * @param input - Required query (1..500 characters), optional chatId, limit (1..50, default 20), scanLimit (1..200, default 100), beforeMessageId, ISO after/before, service, and fromMe. Follow the cursor until hasMore is false for a complete search.
 * @returns Matching messages and scan counts. Text or archives over 64 KiB may be truncated or unavailable, never silently claimed as a complete search.
 * @example
 * import search from 'kody:@tannerlinsley/imessage/search';
 * const page = await search({query:'dinner',limit:10,scanLimit:100});
 */
export default async function search(input: SearchInput): Promise<MessagePage> {
  const p = object(input, [
    "query",
    "chatId",
    "limit",
    "scanLimit",
    "beforeMessageId",
    "after",
    "before",
    "service",
    "fromMe",
  ]);
  return native<MessagePage>({
    action: "search",
    ...filters(p),
    query: text(p.query, "query", 500),
    limit: integer(p.limit, "limit", 20, 50),
    scanLimit: integer(p.scanLimit, "scanLimit", 100, 200),
  });
}