@doist/comms-sdk

中文文档
4.0.1发布于 2026/11/11MITTypeScriptES Module构建来源已验证近 30 天下载 4515

A TypeScript wrapper for the Comms REST API.

此软件包已被标记为弃用

Moved to @todoist/comms-sdk. Replace @doist/comms-sdk with @todoist/comms-sdk in your dependencies and imports.

原始使用文档
文档目录10 节
  1. Installation
  2. Usage
  3. Creating entities
  4. Broadcast group markers
  5. OAuth 2.0
  6. REST hooks
  7. Short-lived processes (CLIs, scripts)
  8. Development
  9. Releases
  10. Feedback

Comms SDK TypeScript

The official TypeScript SDK for the Comms REST API.

Installation

npm install @doist/comms-sdk

Usage

import { CommsApi } from '@doist/comms-sdk'

const api = new CommsApi('YOUR_API_TOKEN')

api.users
    .getSessionUser()
    .then((user) => console.log(user))
    .catch((error) => console.log(error))

By default the SDK targets production at https://comms.todoist.com. Pass a baseUrl option to point at a different deployment — staging lives at https://comms.staging.todoist.com:

const api = new CommsApi('YOUR_API_TOKEN', {
    baseUrl: 'https://comms.staging.todoist.com',
})

Creating entities

Channel / thread / comment / conversation / message / group IDs are opaque base58-encoded UUIDv7 strings; workspaceId and userId are numeric.

Creation endpoints (createChannel, createThread, createComment, getOrCreateConversation, createMessage, createGroup) accept an optional id. A caller-supplied id must be a base58-encoded UUIDv7 — anything else fails fast with a UuidV7Error before the request leaves the SDK. Either mint your own with generateId() (handy for optimistic UI — the ID survives the round-trip unchanged) or omit id and let the SDK mint one:

import { CommsApi, generateId } from '@doist/comms-sdk'

const api = new CommsApi('YOUR_API_TOKEN')

// Option 1: let the SDK mint an ID
const channel = await api.channels.createChannel({
    workspaceId: 1,
    name: 'Engineering',
})

// Option 2: mint the ID yourself (must be a base58 UUIDv7 from generateId)
const id = generateId()
const sameChannel = await api.channels.createChannel({
    workspaceId: 1,
    name: 'Engineering',
    id,
})

Broadcast group markers

Use the string constants EVERYONE / EVERYONE_IN_THREAD when populating groups[] / directGroupMentions[] directly, or pass notifyAudience to createComment / closeThread / reopenThread and let the SDK encode it for you:

await api.comments.createComment({
    threadId,
    content: 'Heads up everyone',
    notifyAudience: 'channel', // encoded as EVERYONE
})

OAuth 2.0

import { getAuthorizationUrl, getAuthToken, CommsApi } from '@doist/comms-sdk'

const authUrl = getAuthorizationUrl(
    'your-client-id',
    ['user:read', 'channels:read'],
    'state-parameter',
    'https://yourapp.com/callback',
)

const tokenResponse = await getAuthToken({
    clientId: 'your-client-id',
    clientSecret: 'your-client-secret',
    code: 'authorization-code',
    redirectUri: 'https://yourapp.com/callback',
})

const api = new CommsApi(tokenResponse.accessToken)
const user = await api.users.getSessionUser()

Access tokens expire (see tokenResponse.expiresIn). When they do, use the refreshToken from the original exchange to obtain a new one without sending the user back through the authorization flow:

import { refreshAuthToken } from '@doist/comms-sdk'

const refreshed = await refreshAuthToken({
    clientId: 'your-client-id',
    clientSecret: 'your-client-secret',
    refreshToken: tokenResponse.refreshToken,
})

// The server may rotate the refresh token — persist refreshed.refreshToken
// when present, otherwise keep using the previous one.
const api = new CommsApi(refreshed.accessToken)

REST hooks

REST hooks require a Todoist OAuth access token with Todoist Comms audience. Subscribe with an HTTPS target URL up to 150 characters and one of the exported HOOK_EVENTS; the backend will POST webhook payloads to that URL when matching events happen:

import { CommsApi, HOOK_EVENTS } from '@doist/comms-sdk'

const api = new CommsApi('TODOIST_OAUTH_ACCESS_TOKEN')

const subscription = await api.hooks.subscribe({
    targetUrl: 'https://example.com/comms-hook',
    event: 'thread_added',
    workspaceId: 1,
})

console.log(subscription.id, HOOK_EVENTS)

await api.hooks.unsubscribe({
    targetUrl: 'https://example.com/comms-hook',
})

Short-lived processes (CLIs, scripts)

On Node, the SDK keeps a connection pool alive across requests so HTTP/2 multiplexing and TLS reuse actually work. Long-running processes don't need to think about it. Short-lived processes should await api.close() before exit, otherwise Node's event loop waits ~4 seconds for idle sockets to time out:

const api = new CommsApi('YOUR_API_TOKEN')
try {
    await api.users.getSessionUser()
} finally {
    await api.close()
}

api.close() drains the process-global pool, so it also covers code paths that only use the standalone OAuth helpers (getAuthToken, refreshAuthToken, revokeAuthToken, registerClient). Those flows can also import closeDefaultDispatcher directly.

Development

  • npm install
  • npm test — Vitest
  • npm run type-check — TypeScript
  • npm run check — oxlint + oxfmt
  • npm run build — emit CJS + ESM + d.ts

Releases

The package follows semantic versioning; releases publish to npm via the GitHub workflow.

Feedback

Open issues at https://github.com/todoist/comms-sdk-typescript.

版本与发布记录

@doist/comms-sdk 共发布 49 个版本,首次发布于 2026/05/21;过去 12 个月发布了 49 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
4.0.1latest2026/11/112 天前
4.0.02026/11/112 天前
3.12.02026/11/058 天前
3.11.02026/11/0211 天前
3.10.02026/10/3014 天前
3.9.12026/10/2915 天前

关于 @doist/comms-sdk 的常见问题

@doist/comms-sdk 是什么?

A TypeScript wrapper for the Comms REST API.注意:该包已被作者标记为弃用——Moved to @todoist/comms-sdk. Replace @doist/comms-sdk with @todoist/comms-sdk in your dependencies and imports.

如何安装 @doist/comms-sdk?

在项目目录运行 npm install @doist/comms-sdk,或使用 pnpm add / yarn add / bun add。

@doist/comms-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@doist/comms-sdk 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@doist/comms-sdk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@doist/comms-sdk 可以商用吗?

@doist/comms-sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@doist/comms-sdk 的下载量有多少?

根据 npm 官方下载统计,@doist/comms-sdk 在 2026/10/13 – 2026/11/11 这 30 天内被下载 4,515 次,日均约 151 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@doist/comms-sdk 还在维护吗?

最新版本 4.0.1 发布于 2026/11/11(2 天前);至今共发布 49 个版本,其中过去 12 个月发布了 49 个;首次发布于 2026/05/21。作者已将其标记为弃用,新项目建议寻找替代方案。