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

Google Calendar

Google Calendar を Squid に接続し、calendar event を read・管理します​

Google Calendar Connector の Functionality​

Google Calendar connector を使用すると、Squid AI agent は自然言語を使用して calendar event を read・管理できます。AI agent にこれらの capability を提供することで、user は AI agent に schedule の確認、event の作成、meeting の update を依頼できます。

connector は以下をサポートします。

  • 指定 time range 内の calendar event の read
  • rich metadata(attendee、reminder、recurrence、Google Meet link)を含む event の作成・update
  • 安全な OAuth2 authentication と automatic token refresh を使用する multi-user support
  • calendar data に対する AI-powered natural language query

Google Calendar Connector の構成​

Squid は OAuth2 authentication を使用して Google Calendar に接続します。Google Cloud project を作成し、OAuth2 credential を構成する必要があります。

Google Cloud Project の作成​

  1. Google Cloud Console に移動します
  2. 新しい project を作成するか、既存 project を選択します
  3. Google Calendar API を有効にします。
    • APIs & Services > Library に移動します
    • "Google Calendar API" を検索します
    • Enable をクリックします
  4. OAuth2 credential を作成します。
    • APIs & Services > Credentials に移動します
    • Create Credentials > OAuth Client ID をクリックします
    • prompt に従って OAuth consent screen を構成します
    • Application type: Web application を選択します
    • authorized redirect URI(例: https://your-app.com/oauth/callback)を追加します
    • Client ID と Client Secret を控えます

Squid Application への Google Calendar Connector の追加​

  1. Squid Console の Connectors tab に移動します。

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

  3. Google Calendar connector を見つけ、Add Connector を選択します。

  4. 次の configuration detail を指定します。

Connector ID: code 内で connector を一意に識別する string。

Client ID: Google Cloud Console の OAuth2 client ID。

Client Secret: Google Cloud Console の OAuth2 client secret。

Redirect URI: OAuth2 redirect URI(Google Cloud で構成した URI と一致する必要があります)。

Application で Google Calendar Connector を使用する​

Google Calendar connector を作成したら、studio または SDK で使用できます。

No-code Studio​

no-code solution は Squid Agent Studio を通じて作成できます。

  1. Squid Console の Studio tab に移動します。

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

  3. "calendar-agent" や "This agent helps the user manage their Google Calendar" などの Agent ID と description を指定します。

  4. Add Abilities をクリックし、SaaS section まで scroll して、先ほど作成した Google Calendar connector を選択します。

  5. 「user が calendar の確認や event の作成を希望する場合にこれを call する」など、agent がこの connection を使用する方法の description を指定します。

  6. Test をクリックし、「来週はどの meeting がありますか?」と agent に質問してみます。

Code の基本 Building Block​

Squid application で Google Calendar connector を使用するには、@squidcloud/google-calendar-client npm package を install します。

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 token management に Squid の External Authentication API を使用します。詳細については documentation を参照してください。

authorization code の取得後、Squid に保存します。

await calendarClient.saveAuthCode(authCode, userId);

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

OAuth2 Scope​

Google Calendar connector には、次の OAuth2 scope が必要です。

const scopes = SquidGoogleCalendarClient.SCOPES;

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

利便性のため、SquidGoogleCalendarClient.SCOPES constant は @squidcloud/google-calendar-client package から export されています。

Calendar Event の読み取り​

// 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,
});

Calendar Event の作成​

// 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 Function の使用​

Google Calendar connector は、AI agent に接続できる AI function を提供します。user identifier は agent 上で構成するか、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​

request ごとに default identifier を override することもできます。

// 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 agent を通じて Google Calendar event を管理できます!