@@ -698,7 +698,7 @@ export { Supervisor } from "@/ai/agents/Supervisor";
698698export { DeepReasoningAgent } from "@/ai/agents/DeepReasoning" ;
699699// export { DataProcessor } from "@/do/DataProcessor";
700700export { GeminiAgent } from "@/ai/agents/Gemini" ;
701- export { GithubSearchWorkflow , DeepResearchWorkflow , TopicResearchWorkflow } from "@/workflows" ;
701+ export { GithubSearchWorkflow , DeepResearchWorkflow , TopicResearchWorkflow , DiscordResearchWorkflow } from "@/workflows" ;
702702
703703// Research Agents (Topic Research)
704704export { TopicOrchestratorAgent } from "./ai/agents/TopicOrchestrator" ;
@@ -724,6 +724,83 @@ export { Sandbox } from '@cloudflare/sandbox'
724724async function handleScheduled ( event : ScheduledController , env : Env , ctx : ExecutionContext ) {
725725 console . log ( '[Scheduled] Cron trigger fired:' , event . cron ) ;
726726
727+ // Daily Discord scan at 9 AM UTC (runs alongside GitHub research)
728+ if ( event . cron === '0 9 * * *' ) {
729+ ctx . waitUntil (
730+ ( async ( ) => {
731+ try {
732+ console . log ( '[Scheduled] Starting daily Discord scan...' ) ;
733+ const { runDiscordResearch } = await import ( '@/workflows/discord' ) ;
734+ const discordResult = await runDiscordResearch ( env , { } ) ;
735+
736+ if ( discordResult . digest . length > 0 && env . SEND_EMAIL_NEWSLETTER ) {
737+ // Group digest items by category for a structured email section
738+ const byCategory : Record < string , typeof discordResult . digest > = { } ;
739+ for ( const item of discordResult . digest ) {
740+ if ( ! byCategory [ item . category ] ) byCategory [ item . category ] = [ ] ;
741+ byCategory [ item . category ] . push ( item ) ;
742+ }
743+
744+ const categoryLabels : Record < string , string > = {
745+ 'what-i-built' : '🏗️ What People Are Building' ,
746+ 'announcement' : '📢 Cloudflare Announcements' ,
747+ 'binding' : '🔧 Tips & Tricks from Product Channels' ,
748+ 'general' : '💬 Notable Discussions' ,
749+ } ;
750+
751+ const sections = Object . entries ( byCategory )
752+ . map ( ( [ cat , items ] ) => {
753+ const label = categoryLabels [ cat ] ?? cat ;
754+ const bullets = items
755+ . sort ( ( a , b ) => b . aiScore - a . aiScore )
756+ . slice ( 0 , 5 )
757+ . map (
758+ ( i ) =>
759+ `<li><strong>@${ i . author } </strong> in #${ i . channelName } : ${ i . aiSummary } <em>(score: ${ i . aiScore } /100)</em></li>`
760+ )
761+ . join ( '' ) ;
762+ return `<h3>${ label } </h3><ul>${ bullets } </ul>` ;
763+ } )
764+ . join ( '' ) ;
765+
766+ const contentHtml = `
767+ <h2>Discord Highlights — ${ new Date ( ) . toLocaleDateString ( ) } </h2>
768+ <p>Scanned ${ discordResult . ingested } new message(s) across Cloudflare Developers Discord channels. Found <strong>${ discordResult . highlighted } </strong> noteworthy item(s).</p>
769+ ${ sections }
770+ ` ;
771+
772+ await sendRepoDiscoveryEmail ( env , {
773+ subject : `Discord Digest — ${ discordResult . highlighted } highlights — ${ new Date ( ) . toLocaleDateString ( ) } ` ,
774+ title : 'Cloudflare Discord Daily Digest' ,
775+ contentHtml,
776+ dailyTrendsData : {
777+ date : new Date ( ) . toLocaleDateString ( ) ,
778+ trend_summary : `${ discordResult . highlighted } Discord highlights from ${ discordResult . ingested } new messages scanned across the Cloudflare Developers server.` ,
779+ top_picks : discordResult . digest
780+ . sort ( ( a , b ) => b . aiScore - a . aiScore )
781+ . slice ( 0 , 10 )
782+ . map ( ( item ) => ( {
783+ name : `#${ item . channelName } — @${ item . author } ` ,
784+ url : `https://discord.com/channels/@me/${ item . messageId } ` ,
785+ category : item . category ,
786+ why_its_interesting : item . aiSummary ,
787+ innovation_score : Math . round ( item . aiScore / 10 ) ,
788+ } ) ) ,
789+ } ,
790+ plainTextFallback : `Discord Digest: ${ discordResult . highlighted } highlights found from ${ discordResult . ingested } new messages.` ,
791+ } ) ;
792+
793+ console . log ( '[Scheduled] Discord digest email sent.' ) ;
794+ } else {
795+ console . log ( `[Scheduled] Discord scan complete — no highlights to email (ingested: ${ discordResult . ingested } ).` ) ;
796+ }
797+ } catch ( err ) {
798+ console . error ( '[Scheduled] Discord scan failed:' , err ) ;
799+ }
800+ } ) ( )
801+ ) ;
802+ }
803+
727804 // Daily research scan at 9 AM UTC
728805 if ( event . cron === '0 9 * * *' ) {
729806 console . log ( '[Scheduled] Starting daily research scan...' ) ;
0 commit comments