import { JarvisController } from '../jarvis-controller.js'; import axios from 'axios'; export interface EmailMessage { id: string; from: string; subject: string; snippet: string; date: string; unread: boolean; labels?: string[]; } export interface SlackMessage { user: string; text: string; timestamp: string; channel: string; } export interface CalendarEvent { id: string; summary: string; start: Date; end: Date; location?: string; attendees?: string[]; } export interface IntegrationSummary { emails: { unreadCount: number; importantCount: number; messages: EmailMessage[]; summary: string; }; slack: { unreadCount: number; mentions: number; messages: SlackMessage[]; summary: string; }; calendar?: { todayCount: number; upcomingEvents: CalendarEvent[]; summary: string; }; overall: string; } export class JarvisIntegrationHub { private jarvis: JarvisController; private claudeApiUrl?: string; // For using Claude to summarize constructor(jarvis: JarvisController) { this.jarvis = jarvis; } /** * Get a comprehensive daily briefing from all integrated services */ async getDailyBriefing(): Promise { console.log('📊 JARVIS gathering daily briefing...'); const briefing: string[] = []; briefing.push('Good morning, sir. Here is your daily briefing:'); briefing.push(''); // Get email summary try { const emailSummary = await this.getEmailSummary(); if (emailSummary) { briefing.push('📧 **Email Summary:**'); briefing.push(emailSummary); briefing.push(''); } } catch (error) { console.error('Failed to get email summary:', error); } // Get Slack summary try { const slackSummary = await this.getSlackSummary(); if (slackSummary) { briefing.push('💬 **Slack Activity:**'); briefing.push(slackSummary); briefing.push(''); } } catch (error) { console.error('Failed to get Slack summary:', error); } // Get calendar summary try { const calendarSummary = await this.getCalendarSummary(); if (calendarSummary) { briefing.push('📅 **Today\'s Schedule:**'); briefing.push(calendarSummary); briefing.push(''); } } catch (error) { console.error('Failed to get calendar summary:', error); } // Get news/weather if available try { const newsSummary = await this.getNewsSummary(); if (newsSummary) { briefing.push('📰 **News Headlines:**'); briefing.push(newsSummary); briefing.push(''); } } catch (error) { console.error('Failed to get news summary:', error); } briefing.push('That concludes your briefing. How may I assist you today?'); const fullBriefing = briefing.join('\n'); // Have JARVIS read the briefing await this.jarvis.speakText(fullBriefing, { voice: 'george', speed: 1.0, chunking: { maxSentencesPerChunk: 2, respectParagraphs: true } }); return fullBriefing; } /** * Get and summarize unread emails */ async getEmailSummary(limit: number = 10): Promise { // This would integrate with Gmail MCP tool // For now, returning a template structure const summary = [ `You have 7 unread emails.`, `3 are marked as important.`, `Key senders include: John from Marketing, Sarah from Development, and your calendar notifications.`, `The most urgent appears to be the budget approval request from John.` ]; return summary.join(' '); } /** * Get and summarize Slack messages */ async getSlackSummary(channels?: string[]): Promise { // This would integrate with Slack MCP tool const summary = [ `You have 12 unread messages across 3 channels.`, `You were mentioned 4 times in #general and #development.`, `The development team is discussing the API redesign.`, `There's a request for your review on the authentication PR.` ]; return summary.join(' '); } /** * Get today's calendar events */ async getCalendarSummary(): Promise { // This would integrate with Google Calendar if available const summary = [ `You have 5 meetings scheduled today.`, `Your first meeting is at 9 AM - Sprint Planning.`, `You have a lunch meeting at 12:30 PM with the CEO.`, `Your afternoon is blocked for deep work from 2 PM to 4 PM.`, `Last meeting is the team standup at 4:30 PM.` ]; return summary.join(' '); } /** * Get news headlines */ async getNewsSummary(): Promise { // This would integrate with a news API const summary = [ `In technology news, OpenAI announced new improvements to GPT models.`, `The stock market opened higher this morning, with tech stocks leading gains.`, `Weather today: Partly cloudy with a high of 72 degrees.` ]; return summary.join(' '); } /** * Read and summarize specific emails */ async readEmails(query: string = 'is:unread', speakResult: boolean = true): Promise { console.log(`📧 JARVIS reading emails with query: ${query}`); // This would call Gmail MCP to get emails // Then summarize them const emailSummary = ` Based on your unread emails: 1. **Budget Approval Request** - From John in Marketing Requesting approval for Q4 marketing budget of $50,000. Includes detailed breakdown and ROI projections. Action needed by end of day. 2. **API Documentation Update** - From Sarah in Development The REST API documentation has been updated. New endpoints for user authentication added. Review requested before deployment. 3. **Team Lunch Tomorrow** - From HR Reminder about team lunch at 12:30 PM tomorrow. Location: The Italian Place on 5th Street. RSVP requested. `; if (speakResult) { await this.jarvis.speakText(emailSummary, { voice: 'george', speed: 1.0 }); } return emailSummary; } /** * Read Slack messages from specific channels */ async readSlackChannel(channel: string, limit: number = 20, speakResult: boolean = true): Promise { console.log(`💬 JARVIS reading Slack channel: ${channel}`); // This would call Slack MCP to get messages const slackSummary = ` Latest messages from ${channel}: 1. **Alice** (10 minutes ago): "Has anyone reviewed the authentication PR yet?" 2. **Bob** (15 minutes ago): "I'm seeing some issues with the staging deployment. Looking into it." 3. **Charlie** (20 minutes ago): "Great work on the new feature everyone! The client loves it." 4. **You were mentioned** by Alice: "Hey @ricardo, could you take a look at the auth changes?" `; if (speakResult) { await this.jarvis.speakText(slackSummary, { voice: 'george', speed: 1.0 }); } return slackSummary; } /** * Monitor for important messages and alert */ async startMonitoring(config: { emailKeywords?: string[]; slackKeywords?: string[]; checkInterval?: number; // minutes }): Promise { const interval = (config.checkInterval || 15) * 60 * 1000; // Convert to milliseconds console.log(`🔍 JARVIS monitoring started. Checking every ${config.checkInterval || 15} minutes.`); setInterval(async () => { // Check for important emails if (config.emailKeywords) { const importantEmails = await this.checkImportantEmails(config.emailKeywords); if (importantEmails.length > 0) { const alert = `Sir, you have ${importantEmails.length} important emails matching your keywords.`; await this.jarvis.speakText(alert, { voice: 'george' }); } } // Check for important Slack messages if (config.slackKeywords) { const importantSlack = await this.checkImportantSlack(config.slackKeywords); if (importantSlack.length > 0) { const alert = `Sir, you have ${importantSlack.length} important Slack messages.`; await this.jarvis.speakText(alert, { voice: 'george' }); } } }, interval); } /** * Check for emails matching keywords */ private async checkImportantEmails(keywords: string[]): Promise { // Would integrate with Gmail MCP // For now, return mock data return []; } /** * Check for Slack messages matching keywords */ private async checkImportantSlack(keywords: string[]): Promise { // Would integrate with Slack MCP return []; } /** * Get a smart summary of all activity */ async getIntelligentSummary(timeframe: 'today' | 'week' | 'month' = 'today'): Promise { console.log(`🧠 JARVIS generating intelligent summary for ${timeframe}...`); const summary = ` Sir, here's your ${timeframe} summary: **Communication Overview:** - 47 emails received, 12 requiring action - 156 Slack messages across 8 channels - You were mentioned 23 times **Key Topics:** 1. API Redesign - Most discussed topic with 18 related conversations 2. Budget Planning - 3 emails and 2 meetings scheduled 3. Client Feedback - Positive responses on the latest deployment **Action Items:** 1. Review and approve Q4 marketing budget (Due: Today) 2. Code review for authentication PR (Requested by: Alice) 3. Respond to CEO's meeting request for next week **Insights:** - Team productivity is up 15% based on PR merge rates - Client satisfaction improved after latest feature release - Consider scheduling fewer meetings on Wednesdays for focus time Would you like me to elaborate on any of these points? `; await this.jarvis.speakText(summary, { voice: 'george', speed: 0.95, chunking: { maxSentencesPerChunk: 3, respectParagraphs: true } }); return summary; } /** * Respond to messages using JARVIS */ async composeResponse(context: { type: 'email' | 'slack'; originalMessage: string; tone?: 'formal' | 'casual' | 'brief'; }): Promise { // This would use AI to compose appropriate responses const response = context.type === 'email' ? `Dear [Recipient],\n\nThank you for your message. I'll review this and get back to you shortly.\n\nBest regards,\nRicardo` : `Thanks for the message! I'll take a look and get back to you soon.`; return response; } }