Google Calendar
Google Calendar を Squid に接続して、カレンダーイベントを読み取り・管理する
Google Calendar コネクターの機能
Google Calendar コネクターを使用すると、Squid AI エージェントは自然言語でカレンダーイベントを読み取り、管理できます。AI エージェントにこれらの機能を提供することで、ユーザーは AI エージェントに対して予定の確認、イベントの作成、会議の更新を代行してもらうことができます。
このコネクターは以下をサポートします:
- 指定した期間内のカレンダーイベントの読み取り
- リッチなメタデータ(参加者、リマインダー、繰り返し、Google Meet リンク)付きのイベント作成・更新
- 安全な OAuth2 認証と自動トークン更新によるマルチユーザーサポート
- カレンダーデータに対する AI による自然言語クエリ
Google Calendar コネクターの設定
Squid は OAuth2 認証を使用して Google Calendar に接続します。Google Cloud project を作成し、OAuth2 資格情報を設定する必要があります。
Google Cloud project の作成
- Google Cloud Console に移動します
- 新しい project を作成するか、既存のものを選択します
- Google Calendar API を有効化します:
- APIs & Services > Library に移動します
- 「Google Calendar API」を検索します
- Enable をクリックします
- 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 ID と Client Secret を控えます
Squid application に Google Calendar コネクターを追加する
-
Squid Console の Connectors タブに移動します。
-
Available Connectors をクリックします。
-
Google Calendar コネクターを見つけ、Add Connector を選択します。
-
次の設定詳細を入力します:
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 で設定したものと一致する必要があります)。
application で Google Calendar コネクターを使用する
Google Calendar コネクターを作成したら、studio または SDK のいずれかで使用できます。
No-code Studio
No-code ソリューションは Squid Agent Studio から作成できます。
-
Squid Console の Studio タブに移動します。
-
Create AI Agent をクリックします。
-
Agent ID と description を入力します。例: 「calendar-agent」および「This agent helps the user manage their Google Calendar」。
-
Add Abilities をクリックし、SaaS セクションまでスクロールして、先ほど作成した Google Calendar コネクターを選択します。
-
エージェントがこの接続をどのように使うべきかの description を入力します。例: 「Call this when a user wants to check their calendar or create events.」。
-
Test をクリックし、エージェントに「What meetings do I have next week?」と尋ねてみてください。
コードでの基本ビルディングブロック
Squid application で Google Calendar コネクターを使用するには、@squidcloud/google-calendar-client npm package をインストールします。
npm install @squidcloud/google-calendar-client
Client setup
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 Calendar コネクターには、次の OAuth2 scopes が必要です:
const scopes = SquidGoogleCalendarClient.SCOPES;
[
'openid',
'email',
'https://www.googleapis.com/auth/calendar.events'
];
利便性のため、定数 SquidGoogleCalendarClient.SCOPES が @squidcloud/google-calendar-client package から 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 Calendar コネクターは、AI エージェントに接続できる AI functions を提供します。ユーザー識別子はエージェント上で設定するか、agent context として渡すことができます:
// Configure on the agent (persists across all calls)
const agent = this.squid.ai().agent('calendar_agent');
await agent.upsert({
options: {
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 Calendar イベントを管理できるようになりました!