Initial commit
This commit is contained in:
163
skills/google-workspace/calendar/create_event.js
Normal file
163
skills/google-workspace/calendar/create_event.js
Normal file
@@ -0,0 +1,163 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Create Calendar Event
|
||||
*
|
||||
* Usage: node create_event.js <account> --summary <title> --start <datetime> [options]
|
||||
*
|
||||
* Options:
|
||||
* --summary Event title (required)
|
||||
* --start Start datetime (required, ISO 8601 or natural)
|
||||
* --end End datetime (default: 1 hour after start)
|
||||
* --description Event description
|
||||
* --location Event location
|
||||
* --attendees Comma-separated email addresses
|
||||
* --all-day Create all-day event (use date format for start/end)
|
||||
*
|
||||
* Examples:
|
||||
* node create_event.js psd --summary "Team Meeting" --start "2024-01-15T14:00:00"
|
||||
* node create_event.js personal --summary "Dinner" --start "2024-01-15T18:00:00" --end "2024-01-15T20:00:00" --location "Restaurant"
|
||||
* node create_event.js consulting --summary "Client Call" --start "2024-01-15T10:00:00" --attendees "client@example.com"
|
||||
*/
|
||||
|
||||
const { google } = require('googleapis');
|
||||
const path = require('path');
|
||||
const { getAuthClient } = require(path.join(__dirname, '..', 'auth', 'token_manager'));
|
||||
|
||||
async function createEvent(account, options) {
|
||||
const auth = await getAuthClient(account);
|
||||
const calendar = google.calendar({ version: 'v3', auth });
|
||||
|
||||
// Parse start time
|
||||
const startDate = new Date(options.start);
|
||||
if (isNaN(startDate.getTime())) {
|
||||
throw new Error(`Invalid start date: ${options.start}`);
|
||||
}
|
||||
|
||||
// Calculate end time (default: 1 hour after start)
|
||||
let endDate;
|
||||
if (options.end) {
|
||||
endDate = new Date(options.end);
|
||||
if (isNaN(endDate.getTime())) {
|
||||
throw new Error(`Invalid end date: ${options.end}`);
|
||||
}
|
||||
} else {
|
||||
endDate = new Date(startDate);
|
||||
endDate.setHours(endDate.getHours() + 1);
|
||||
}
|
||||
|
||||
// Build event
|
||||
const event = {
|
||||
summary: options.summary,
|
||||
description: options.description,
|
||||
location: options.location,
|
||||
};
|
||||
|
||||
// Handle all-day vs timed events
|
||||
if (options.allDay) {
|
||||
event.start = { date: startDate.toISOString().split('T')[0] };
|
||||
event.end = { date: endDate.toISOString().split('T')[0] };
|
||||
} else {
|
||||
event.start = {
|
||||
dateTime: startDate.toISOString(),
|
||||
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
||||
};
|
||||
event.end = {
|
||||
dateTime: endDate.toISOString(),
|
||||
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
||||
};
|
||||
}
|
||||
|
||||
// Add attendees
|
||||
if (options.attendees) {
|
||||
event.attendees = options.attendees.split(',').map(email => ({
|
||||
email: email.trim(),
|
||||
}));
|
||||
}
|
||||
|
||||
const response = await calendar.events.insert({
|
||||
calendarId: 'primary',
|
||||
requestBody: event,
|
||||
sendUpdates: options.attendees ? 'all' : 'none',
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
account,
|
||||
event: {
|
||||
id: response.data.id,
|
||||
summary: response.data.summary,
|
||||
start: response.data.start.dateTime || response.data.start.date,
|
||||
end: response.data.end.dateTime || response.data.end.date,
|
||||
htmlLink: response.data.htmlLink,
|
||||
},
|
||||
metadata: {
|
||||
timestamp: new Date().toISOString(),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// CLI interface
|
||||
async function main() {
|
||||
const args = process.argv.slice(2);
|
||||
const account = args[0];
|
||||
|
||||
if (!account) {
|
||||
console.error(JSON.stringify({
|
||||
error: 'Missing account',
|
||||
usage: 'node create_event.js <account> --summary <title> --start <datetime> [options]'
|
||||
}));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Parse options
|
||||
const options = {};
|
||||
for (let i = 1; i < args.length; i++) {
|
||||
switch (args[i]) {
|
||||
case '--summary':
|
||||
options.summary = args[++i];
|
||||
break;
|
||||
case '--start':
|
||||
options.start = args[++i];
|
||||
break;
|
||||
case '--end':
|
||||
options.end = args[++i];
|
||||
break;
|
||||
case '--description':
|
||||
options.description = args[++i];
|
||||
break;
|
||||
case '--location':
|
||||
options.location = args[++i];
|
||||
break;
|
||||
case '--attendees':
|
||||
options.attendees = args[++i];
|
||||
break;
|
||||
case '--all-day':
|
||||
options.allDay = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!options.summary || !options.start) {
|
||||
console.error(JSON.stringify({
|
||||
error: 'Missing required options: --summary, --start',
|
||||
usage: 'node create_event.js <account> --summary <title> --start <datetime>'
|
||||
}));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await createEvent(account, options);
|
||||
console.log(JSON.stringify(result, null, 2));
|
||||
} catch (error) {
|
||||
console.error(JSON.stringify({
|
||||
error: error.message,
|
||||
account,
|
||||
}));
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
module.exports = { createEvent };
|
||||
124
skills/google-workspace/calendar/list_events.js
Normal file
124
skills/google-workspace/calendar/list_events.js
Normal file
@@ -0,0 +1,124 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* List Calendar Events
|
||||
*
|
||||
* Usage: node list_events.js <account> [options]
|
||||
*
|
||||
* Options:
|
||||
* --days Number of days to look ahead (default: 7)
|
||||
* --today Show only today's events
|
||||
* --max Maximum events to return (default: 50)
|
||||
*
|
||||
* Examples:
|
||||
* node list_events.js psd
|
||||
* node list_events.js psd --today
|
||||
* node list_events.js personal --days 30
|
||||
*/
|
||||
|
||||
const { google } = require('googleapis');
|
||||
const path = require('path');
|
||||
const { getAuthClient } = require(path.join(__dirname, '..', 'auth', 'token_manager'));
|
||||
|
||||
async function listEvents(account, options = {}) {
|
||||
const auth = await getAuthClient(account);
|
||||
const calendar = google.calendar({ version: 'v3', auth });
|
||||
|
||||
// Calculate time range
|
||||
const now = new Date();
|
||||
const timeMin = new Date(now);
|
||||
timeMin.setHours(0, 0, 0, 0);
|
||||
|
||||
let timeMax;
|
||||
if (options.today) {
|
||||
timeMax = new Date(timeMin);
|
||||
timeMax.setDate(timeMax.getDate() + 1);
|
||||
} else {
|
||||
timeMax = new Date(timeMin);
|
||||
timeMax.setDate(timeMax.getDate() + (options.days || 7));
|
||||
}
|
||||
|
||||
const response = await calendar.events.list({
|
||||
calendarId: 'primary',
|
||||
timeMin: timeMin.toISOString(),
|
||||
timeMax: timeMax.toISOString(),
|
||||
maxResults: options.max || 50,
|
||||
singleEvents: true,
|
||||
orderBy: 'startTime',
|
||||
});
|
||||
|
||||
const events = (response.data.items || []).map(event => ({
|
||||
id: event.id,
|
||||
summary: event.summary,
|
||||
description: event.description,
|
||||
location: event.location,
|
||||
start: event.start.dateTime || event.start.date,
|
||||
end: event.end.dateTime || event.end.date,
|
||||
isAllDay: !event.start.dateTime,
|
||||
status: event.status,
|
||||
attendees: (event.attendees || []).map(a => ({
|
||||
email: a.email,
|
||||
name: a.displayName,
|
||||
responseStatus: a.responseStatus,
|
||||
})),
|
||||
hangoutLink: event.hangoutLink,
|
||||
htmlLink: event.htmlLink,
|
||||
}));
|
||||
|
||||
return {
|
||||
success: true,
|
||||
account,
|
||||
events,
|
||||
metadata: {
|
||||
timestamp: new Date().toISOString(),
|
||||
count: events.length,
|
||||
timeMin: timeMin.toISOString(),
|
||||
timeMax: timeMax.toISOString(),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// CLI interface
|
||||
async function main() {
|
||||
const args = process.argv.slice(2);
|
||||
const account = args[0];
|
||||
|
||||
if (!account) {
|
||||
console.error(JSON.stringify({
|
||||
error: 'Missing account',
|
||||
usage: 'node list_events.js <account> [--today] [--days N] [--max N]'
|
||||
}));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Parse options
|
||||
const options = {};
|
||||
for (let i = 1; i < args.length; i++) {
|
||||
switch (args[i]) {
|
||||
case '--today':
|
||||
options.today = true;
|
||||
break;
|
||||
case '--days':
|
||||
options.days = parseInt(args[++i], 10);
|
||||
break;
|
||||
case '--max':
|
||||
options.max = parseInt(args[++i], 10);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await listEvents(account, options);
|
||||
console.log(JSON.stringify(result, null, 2));
|
||||
} catch (error) {
|
||||
console.error(JSON.stringify({
|
||||
error: error.message,
|
||||
account,
|
||||
}));
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
module.exports = { listEvents };
|
||||
124
skills/google-workspace/calendar/search_events.js
Normal file
124
skills/google-workspace/calendar/search_events.js
Normal file
@@ -0,0 +1,124 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Search Calendar Events
|
||||
*
|
||||
* Usage: node search_events.js <account> <query> [options]
|
||||
*
|
||||
* Options:
|
||||
* --days Number of days to search (default: 30)
|
||||
* --max Maximum events to return (default: 50)
|
||||
*
|
||||
* Examples:
|
||||
* node search_events.js psd "team meeting"
|
||||
* node search_events.js personal "dinner" --days 60
|
||||
* node search_events.js consulting "client"
|
||||
*/
|
||||
|
||||
const { google } = require('googleapis');
|
||||
const path = require('path');
|
||||
const { getAuthClient } = require(path.join(__dirname, '..', 'auth', 'token_manager'));
|
||||
|
||||
async function searchEvents(account, query, options = {}) {
|
||||
const auth = await getAuthClient(account);
|
||||
const calendar = google.calendar({ version: 'v3', auth });
|
||||
|
||||
// Calculate time range
|
||||
const now = new Date();
|
||||
const timeMin = new Date(now);
|
||||
timeMin.setDate(timeMin.getDate() - (options.days || 30)); // Look back too
|
||||
|
||||
const timeMax = new Date(now);
|
||||
timeMax.setDate(timeMax.getDate() + (options.days || 30));
|
||||
|
||||
const response = await calendar.events.list({
|
||||
calendarId: 'primary',
|
||||
q: query,
|
||||
timeMin: timeMin.toISOString(),
|
||||
timeMax: timeMax.toISOString(),
|
||||
maxResults: options.max || 50,
|
||||
singleEvents: true,
|
||||
orderBy: 'startTime',
|
||||
});
|
||||
|
||||
const events = (response.data.items || []).map(event => ({
|
||||
id: event.id,
|
||||
summary: event.summary,
|
||||
description: event.description,
|
||||
location: event.location,
|
||||
start: event.start.dateTime || event.start.date,
|
||||
end: event.end.dateTime || event.end.date,
|
||||
isAllDay: !event.start.dateTime,
|
||||
attendees: (event.attendees || []).map(a => ({
|
||||
email: a.email,
|
||||
name: a.displayName,
|
||||
responseStatus: a.responseStatus,
|
||||
})),
|
||||
htmlLink: event.htmlLink,
|
||||
}));
|
||||
|
||||
return {
|
||||
success: true,
|
||||
account,
|
||||
query,
|
||||
events,
|
||||
metadata: {
|
||||
timestamp: new Date().toISOString(),
|
||||
count: events.length,
|
||||
timeMin: timeMin.toISOString(),
|
||||
timeMax: timeMax.toISOString(),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// CLI interface
|
||||
async function main() {
|
||||
const args = process.argv.slice(2);
|
||||
const account = args[0];
|
||||
|
||||
if (!account) {
|
||||
console.error(JSON.stringify({
|
||||
error: 'Missing account',
|
||||
usage: 'node search_events.js <account> <query> [--days N] [--max N]'
|
||||
}));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Find query (first non-flag argument after account)
|
||||
let query = '';
|
||||
const options = {};
|
||||
|
||||
for (let i = 1; i < args.length; i++) {
|
||||
if (args[i] === '--days') {
|
||||
options.days = parseInt(args[++i], 10);
|
||||
} else if (args[i] === '--max') {
|
||||
options.max = parseInt(args[++i], 10);
|
||||
} else if (!args[i].startsWith('--')) {
|
||||
query = args[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (!query) {
|
||||
console.error(JSON.stringify({
|
||||
error: 'Missing query',
|
||||
usage: 'node search_events.js <account> <query>'
|
||||
}));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await searchEvents(account, query, options);
|
||||
console.log(JSON.stringify(result, null, 2));
|
||||
} catch (error) {
|
||||
console.error(JSON.stringify({
|
||||
error: error.message,
|
||||
account,
|
||||
query,
|
||||
}));
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
module.exports = { searchEvents };
|
||||
137
skills/google-workspace/calendar/update_event.js
Normal file
137
skills/google-workspace/calendar/update_event.js
Normal file
@@ -0,0 +1,137 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Update Calendar Event
|
||||
*
|
||||
* Usage: node update_event.js <account> <event-id> [options]
|
||||
*
|
||||
* Options:
|
||||
* --summary New event title
|
||||
* --start New start datetime
|
||||
* --end New end datetime
|
||||
* --description New description
|
||||
* --location New location
|
||||
*
|
||||
* Examples:
|
||||
* node update_event.js psd abc123 --start "2024-01-15T15:00:00"
|
||||
* node update_event.js personal def456 --summary "Updated Meeting" --location "New Room"
|
||||
*/
|
||||
|
||||
const { google } = require('googleapis');
|
||||
const path = require('path');
|
||||
const { getAuthClient } = require(path.join(__dirname, '..', 'auth', 'token_manager'));
|
||||
|
||||
async function updateEvent(account, eventId, options) {
|
||||
const auth = await getAuthClient(account);
|
||||
const calendar = google.calendar({ version: 'v3', auth });
|
||||
|
||||
// Get existing event
|
||||
const existing = await calendar.events.get({
|
||||
calendarId: 'primary',
|
||||
eventId,
|
||||
});
|
||||
|
||||
const event = existing.data;
|
||||
|
||||
// Update fields
|
||||
if (options.summary) event.summary = options.summary;
|
||||
if (options.description) event.description = options.description;
|
||||
if (options.location) event.location = options.location;
|
||||
|
||||
if (options.start) {
|
||||
const startDate = new Date(options.start);
|
||||
if (isNaN(startDate.getTime())) {
|
||||
throw new Error(`Invalid start date: ${options.start}`);
|
||||
}
|
||||
event.start = {
|
||||
dateTime: startDate.toISOString(),
|
||||
timeZone: event.start.timeZone || Intl.DateTimeFormat().resolvedOptions().timeZone,
|
||||
};
|
||||
}
|
||||
|
||||
if (options.end) {
|
||||
const endDate = new Date(options.end);
|
||||
if (isNaN(endDate.getTime())) {
|
||||
throw new Error(`Invalid end date: ${options.end}`);
|
||||
}
|
||||
event.end = {
|
||||
dateTime: endDate.toISOString(),
|
||||
timeZone: event.end.timeZone || Intl.DateTimeFormat().resolvedOptions().timeZone,
|
||||
};
|
||||
}
|
||||
|
||||
const response = await calendar.events.update({
|
||||
calendarId: 'primary',
|
||||
eventId,
|
||||
requestBody: event,
|
||||
sendUpdates: event.attendees ? 'all' : 'none',
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
account,
|
||||
event: {
|
||||
id: response.data.id,
|
||||
summary: response.data.summary,
|
||||
start: response.data.start.dateTime || response.data.start.date,
|
||||
end: response.data.end.dateTime || response.data.end.date,
|
||||
htmlLink: response.data.htmlLink,
|
||||
},
|
||||
metadata: {
|
||||
timestamp: new Date().toISOString(),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// CLI interface
|
||||
async function main() {
|
||||
const args = process.argv.slice(2);
|
||||
const account = args[0];
|
||||
const eventId = args[1];
|
||||
|
||||
if (!account || !eventId) {
|
||||
console.error(JSON.stringify({
|
||||
error: 'Missing arguments',
|
||||
usage: 'node update_event.js <account> <event-id> [options]'
|
||||
}));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Parse options
|
||||
const options = {};
|
||||
for (let i = 2; i < args.length; i++) {
|
||||
switch (args[i]) {
|
||||
case '--summary':
|
||||
options.summary = args[++i];
|
||||
break;
|
||||
case '--start':
|
||||
options.start = args[++i];
|
||||
break;
|
||||
case '--end':
|
||||
options.end = args[++i];
|
||||
break;
|
||||
case '--description':
|
||||
options.description = args[++i];
|
||||
break;
|
||||
case '--location':
|
||||
options.location = args[++i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await updateEvent(account, eventId, options);
|
||||
console.log(JSON.stringify(result, null, 2));
|
||||
} catch (error) {
|
||||
console.error(JSON.stringify({
|
||||
error: error.message,
|
||||
account,
|
||||
eventId,
|
||||
}));
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
module.exports = { updateEvent };
|
||||
Reference in New Issue
Block a user