メインコンテンツまでスキップ

Google カレンダー

Google カレンダーを Squid に接続して、予定(イベント)の読み取りと管理を行う

Google カレンダーコネクタの機能

Google カレンダーコネクタを使用すると、Squid AI エージェントが自然言語でカレンダーの予定(イベント)を読み取り、管理できるようになります。これらの機能を AI エージェントに提供することで、ユーザーは AI エージェントに対して、スケジュールの確認、イベントの作成、会議の更新などを代理で実行するよう依頼できます。

このコネクタは次をサポートします。

  • 指定した期間内のカレンダーイベントの読み取り
  • リッチなメタデータ(attendees, reminders, recurrence, Google Meet links)を含むイベントの作成と更新
  • 安全な OAuth2 認証と自動トークンリフレッシュによるマルチユーザー対応
  • カレンダーデータに対する AI による自然言語クエリ

Google カレンダーコネクタの設定

Squid は OAuth2 認証を使用して Google カレンダーに接続します。Google Cloud プロジェクトを作成し、OAuth2 credentials を設定する必要があります。

Google Cloud プロジェクトの作成

  1. Google Cloud Console に移動します
  2. 新しいプロジェクトを作成するか、既存のプロジェクトを選択します
  3. Google Calendar API を有効化します:
    • APIs & Services > Library に移動します
    • 「Google Calendar API」を検索します
    • Enable をクリックします
  4. OAuth2 credentials を作成します:
    • APIs & Services > Credentials に移動します
    • Create Credentials > OAuth Client ID をクリックします
    • 指示に従って OAuth consent screen を設定します
    • Application type: Web application を選択します
    • authorized redirect URIs を追加します(例: https://your-app.com/oauth/callback
    • Client IDClient Secret を控えます

Squid アプリケーションに Google カレンダーコネクタを追加する

  1. Squid ConsoleConnectors タブに移動します。

  2. Available Connectors をクリックします。

  3. Google Calendar コネクタを見つけ、Add Connector を選択します。

  4. 次の設定詳細を入力します。

Connector ID: コード内でコネクタを一意に識別する文字列。

Client ID: Google Cloud Console の OAuth2 client ID。

Client Secret: Google Cloud Console の OAuth2 client secret。

Redirect URI: OAuth2 redirect URI(Google Cloud で設定したものと一致している必要があります)。

アプリケーションで Google カレンダーコネクタを使用する

Google カレンダーコネクタを作成したら、Studio または SDK のいずれかで利用できます。

No-code Studio

No-code ソリューションは Squid Agent Studio から作成できます。

  1. Squid ConsoleStudio タブに移動します。

  2. Create AI Agent をクリックします。

  3. Agent IDdescription を入力します。例:「calendar-agent」および「This agent helps the user manage their Google Calendar」。

  4. Add Abilities をクリックし、SaaS セクションまでスクロールして、先ほど作成した Google Calendar コネクタを選択します。

  5. エージェントがこの接続をどのように使うべきかの説明を追加します。例:「Call this when a user wants to check their calendar or create events.」。

  6. Test をクリックし、「What meetings do I have next week?」とエージェントに質問してみてください。

コードでの基本的なビルディングブロック

Squid アプリケーションで Google カレンダーコネクタを使用するには、@squidcloud/google-calendar-client npm パッケージをインストールします。

npm install @squidcloud/google-calendar-client

Client のセットアップ

import { SquidGoogleCalendarClient } from '@squidcloud/google-calendar-client';
import { Squid } from '@squidcloud/client';

const squid = new Squid({
appId: 'your-app-id',
region: 'us-east-1.aws',
environmentId: 'dev',
});

const calendarClient = new SquidGoogleCalendarClient(
squid,
'google_calendar' // your connector ID
);

Authentication

Google Calendar client は、OAuth2 トークン管理のために Squid の External Authentication API を使用します。詳細はドキュメントを参照してください。

authorization code を取得したら、それを Squid に保存します。

await calendarClient.saveAuthCode(authCode, userId);

Google 固有の OAuth2 要件については、Google OAuth2 documentation を参照してください。

OAuth2 Scopes

Google カレンダーコネクタには次の OAuth2 scopes が必要です。

const scopes = SquidGoogleCalendarClient.SCOPES;

['openid', 'email', 'https://www.googleapis.com/auth/calendar.events'];

利便性のため、定数 SquidGoogleCalendarClient.SCOPES@squidcloud/google-calendar-client パッケージから export されています。

カレンダーイベントの読み取り

// Get events from primary calendar for the next 7 days
const events = await calendarClient.getCalendarEvents({
identifier: userId,
});

// Get events with custom date range
const eventsWithDate = await calendarClient.getCalendarEvents({
identifier: userId,
startDate: new Date('2024-01-01'),
endDate: new Date('2024-01-31'),
maxResults: 100,
});

カレンダーイベントの作成

// Create a simple timed event
const event = await calendarClient.upsertCalendarEvent({
identifier: userId,
summary: 'Team Meeting',
description: 'Weekly team sync',
start: new Date('2024-01-15T10:00:00'),
end: new Date('2024-01-15T11:00:00'),
location: 'Conference Room A',
});

// Create event with attendees and Google Meet
const eventWithMeet = await calendarClient.upsertCalendarEvent({
identifier: userId,
summary: 'Product Review',
start: new Date('2024-01-20T14:00:00'),
end: new Date('2024-01-20T15:00:00'),
attendees: [{ email: 'colleague@company.com', displayName: 'John Doe' }, { email: 'manager@company.com' }],
addMeetLink: true,
reminders: [
{ method: 'email', minutes: 60 },
{ method: 'popup', minutes: 10 },
],
});

AI functions の使用

Google カレンダーコネクタは、AI エージェントに接続できる AI functions を提供します。user identifier は、エージェント側で設定するか、agent context で渡すように構成できます。

// Configure on the agent (persists across all calls)
const agent = this.squid.ai().agent('calendar_agent');
await agent.setAgentOptionInPath('connectedIntegrations', [
{
integrationId: 'google_calendar',
integrationType: 'google_calendar',
options: {
identifier: userId,
},
},
]);

const result = await agent.ask('What meetings do I have next week?');

Dynamic user context

リクエストごとにデフォルトの identifier を上書きすることもできます。

// Or pass in the agent context (per-call override)
const result = await agent.ask('What meetings do I have next week?', {
functions: ['listCalendarEvents'],
agentContext: { identifier: userId },
});

おめでとうございます!これで AI エージェントを通じて Google カレンダーのイベントを管理できるようになりました。