iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🔄

Automating Task Scheduling by Integrating TickTick with Reclaim.ai

に公開

Introduction

I use TickTick for task management, but I found it tedious to decide when to perform each task. Reclaim.ai is a useful service that automatically schedules tasks on your calendar, but unfortunately, it lacks native integration with TickTick.

"If it doesn't exist, build it yourself." So, I developed a bridge to connect TickTick and Reclaim.ai.

In this article, I will introduce the development process and the implementation method.

Goals

Conditions:

  • Must be free to operate (No paid SaaS plans)
  • Real-time is not required (Allowing a delay of about 5 minutes)
  • Low-priority tasks should not be synced

Investigation: Is it feasible?

Services supported by Reclaim.ai

First, I checked the official integrations for Reclaim.ai.

Service Status
Todoist Supported
Asana Supported
ClickUp Supported
Linear Supported
Jira Supported
Google Tasks Supported
TickTick Not Supported

As expected, TickTick is not covered. Custom development is required.

API Investigation

TickTick Open API:

Reclaim.ai API:

Since I confirmed access to both APIs, I decided to proceed with development.

Technology Stack

Why Cloudflare Workers?

Since I wanted to execute tasks periodically for free, I considered several options.

Service Free Tier Suitability
Cloudflare Workers 100,000 requests/day Optimal
Vercel 100GB bandwidth/month OK
GitHub Actions 2,000 minutes/month OK

Cloudflare Workers has a generous free tier and allows periodic execution via Cron Triggers. It is perfect for this use case.

Architecture

It executes via Cron every 5 minutes and syncs new tasks to Reclaim.ai.

Implementation

TickTick API Client

The TickTick API uses OAuth 2.0 authentication.

const BASE_URL = "https://api.ticktick.com/open/v1";

export class TickTickClient {
  private accessToken: string;

  async getProjects(): Promise<Project[]> {
    const response = await fetch(`${BASE_URL}/project`, {
      headers: {
        Authorization: `Bearer ${this.accessToken}`,
      },
    });
    return response.json();
  }

  async getProjectTasks(projectId: string): Promise<Task[]> {
    const response = await fetch(`${BASE_URL}/project/${projectId}/data`, {
      headers: {
        Authorization: `Bearer ${this.accessToken}`,
      },
    });
    const data = await response.json();
    return data.tasks || [];
  }
}

Reclaim.ai API Client

The Reclaim.ai API uses Bearer Token authentication.

const BASE_URL = "https://api.app.reclaim.ai/api";

export class ReclaimClient {
  private accessToken: string;

  async createTask(task: ReclaimTaskCreate): Promise<ReclaimTask> {
    const response = await fetch(`${BASE_URL}/tasks`, {
      method: "POST",
      headers: {
        Authorization: `Bearer ${this.accessToken}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify(task),
    });
    return response.json();
  }

  async getTimeSchemes(): Promise<TimeScheme[]> {
    const response = await fetch(`${BASE_URL}/timeschemes`, {
      headers: {
        Authorization: `Bearer ${this.accessToken}`,
      },
    });
    return response.json();
  }
}

Pitfall: Tasks being scheduled outside working hours

For some reason, the synced tasks were being placed outside of working hours.

After investigation, I found that Reclaim.ai has a concept called "Time Schemes," which must be specified when creating a task.

// Fetch Time Schemes to check the ID for Working Hours
const schemes = await client.getTimeSchemes();
// → Working Hours: "3f6beef9-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
// Specify timeSchemeId when creating a task
const task = {
  title: "Task Name",
  timeSchemeId: "3f6beef9-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Working Hours
};

With this, tasks are now scheduled within working hours (Focus Time).

Sync Logic

This logic filters by priority and prevents duplicates.

function shouldSync(task: TickTickTask): boolean {
  // Skip completed
  if (task.status !== 0) return false;
  // Skip no priority (0)
  if (task.priority < 1) return false;
  return true;
}

async function sync() {
  const ticktickTasks = await ticktick.getIncompleteTasks();
  
  for (const task of ticktickTasks) {
    if (!shouldSync(task)) continue;
    if (alreadySynced(task.id)) continue;
    
    await reclaim.createTask(convertTask(task));
    markAsSynced(task.id);
  }
}

Deployment

wrangler.jsonc

{
  "$schema": "node_modules/wrangler/config-schema.json",
  "name": "ticktick-reclaim-bridge",
  "main": "src/worker.ts",
  "compatibility_date": "2024-01-01",
  "triggers": {
    "crons": ["*/5 * * * *"]  // Every 5 minutes
  },
  "kv_namespaces": [
    {
      "binding": "SYNC_STATE",
      "id": "your-kv-namespace-id"
    }
  ]
}

Secrets Setup

npx wrangler secret put TICKTICK_CLIENT_ID
npx wrangler secret put TICKTICK_CLIENT_SECRET
npx wrangler secret put TICKTICK_ACCESS_TOKEN
npx wrangler secret put RECLAIM_ACCESS_TOKEN
npx wrangler secret put RECLAIM_TIME_SCHEME_ID

Deployment

npm run deploy

Automatic synchronization now runs every 5 minutes.

Completion

After adding a task in TickTick, it now syncs to Reclaim.ai within a few minutes and is automatically placed on the calendar.

Operation Image

Operating Cost

¥0

The Cloudflare Workers free tier is sufficient.

Summary

  • TickTick and Reclaim.ai lack official integration, but they can be connected via API
  • Periodic execution is possible for free using Cloudflare Workers
  • Scheduling policies can be controlled using Reclaim.ai's Time Schemes

The source code is available on GitHub.

https://github.com/kyo-ogawa/ticktick-reclaim-bridge

Discussion