Skip to content

Built for people who want to own their automations. Join the waitlist for an invite.

Package listing

@kody/intercom

src/scheduled-workspace-health.ts

27 lines · 1.0 KB · TypeScript
import { getMe } from './me.ts'
import { listArticles } from './articles.ts'
import { listContacts } from './contacts.ts'
import { listConversations } from './conversations.ts'

/**
 * No-argument scheduled wrapper. Reads `/me` plus first-page counts only —
 * no writes. The `workspace-health` job is **disabled** by default.
 * @example
 * import scheduledWorkspaceHealth from 'kody:@kody/intercom/scheduled-workspace-health'
 * const snapshot = await scheduledWorkspaceHealth()
 */
export default async function scheduledWorkspaceHealth() {
	const [me, contacts, conversations, articles] = await Promise.all([
		getMe(),
		listContacts({ perPage: 5 }),
		listConversations({ perPage: 5 }),
		listArticles({ perPage: 5 }),
	])
	return {
		hasAdminId: Boolean(me.id),
		region: me.app.region,
		contactCount: contacts.pageInfo.totalCount ?? contacts.items.length,
		conversationCount: conversations.pageInfo.totalCount ?? conversations.items.length,
		articleCount: articles.pageInfo.totalCount ?? articles.items.length,
	}
}