- Rename bot to Alex with friendly/professional persona (Bedrock Agent instruction rewrite) - Replace HTTP webhook Lambda with ECS Fargate Socket Mode service (persistent WebSocket) - Add payment/invoice lookup via PaymentsDashboard table (vendor, invoice, check search) - Switch from manual SiteAssignments to auto-populated verified-sites table - Add channel support via app_mention events (threaded replies) - Add App Home tab with Block Kit capabilities view - Add unanswered questions logging to seahaven-unanswered-questions DynamoDB table - Fix pre-existing compliance: add arm64 + 60-day log retention to all Lambdas - Remove webhook Lambda and seed-sites script (both obsolete)
109 lines
5 KiB
TypeScript
109 lines
5 KiB
TypeScript
import * as cdk from 'aws-cdk-lib';
|
|
import * as ec2 from 'aws-cdk-lib/aws-ec2';
|
|
import { Construct } from 'constructs';
|
|
import { ConversationLogConstruct } from './constructs/conversation-log';
|
|
import { KnowledgeBaseConstruct } from './constructs/knowledge-base';
|
|
import { BedrockAgentConstruct } from './constructs/bedrock-agent';
|
|
import { SlackHandlerConstruct } from './constructs/slack-handler';
|
|
import { SocketModeConstruct } from './constructs/socket-mode';
|
|
import { NotionSyncConstruct } from './constructs/notion-sync';
|
|
import { PoSyncConstruct } from './constructs/po-sync';
|
|
import { WorkorderSyncConstruct } from './constructs/workorder-sync';
|
|
|
|
export class SeahavenSlackBotStack extends cdk.Stack {
|
|
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
|
|
super(scope, id, props);
|
|
|
|
const wildcardCertArn = this.node.tryGetContext('wildcardCertArn') as string | undefined;
|
|
if (!wildcardCertArn || wildcardCertArn.includes('CHANGE-ME')) {
|
|
throw new Error(
|
|
'Set wildcardCertArn in cdk.json or pass --context wildcardCertArn=arn:aws:acm:...\n' +
|
|
'Run: aws acm list-certificates --region us-east-1 to find your cert ARN.',
|
|
);
|
|
}
|
|
|
|
// ── VPC (existing) — QBO Lambdas + Socket Mode run here ──────────────────
|
|
const vpc = ec2.Vpc.fromLookup(this, 'SeahavenVpc', { vpcId: 'vpc-0d3d4b67bd0cf8a68' });
|
|
|
|
const lambdaSecurityGroup = new ec2.SecurityGroup(this, 'QBOLambdaSG', {
|
|
vpc,
|
|
securityGroupName: 'seahaven-qbo-lambda',
|
|
description: 'QBO Lambdas - outbound HTTPS only',
|
|
allowAllOutbound: true,
|
|
});
|
|
|
|
// ── Conversation history + unanswered questions (DynamoDB) ────────────────
|
|
const conversationLog = new ConversationLogConstruct(this, 'ConversationLog');
|
|
|
|
// ── Bedrock Knowledge Base (OpenSearch Serverless + S3) ───────────────────
|
|
const knowledgeBase = new KnowledgeBaseConstruct(this, 'KnowledgeBase', {
|
|
accountId: this.account,
|
|
region: this.region,
|
|
});
|
|
|
|
// ── Bedrock Agent (Alex — Claude Sonnet + action groups) ─────────────────
|
|
const bedrockAgent = new BedrockAgentConstruct(this, 'BedrockAgent', {
|
|
accountId: this.account,
|
|
region: this.region,
|
|
knowledgeBaseId: knowledgeBase.knowledgeBase.knowledgeBaseId,
|
|
knowledgeBaseArn: knowledgeBase.knowledgeBase.knowledgeBaseArn,
|
|
vpc,
|
|
lambdaSecurityGroup,
|
|
});
|
|
|
|
// ── Notion → KB daily sync (EventBridge + Lambda) ────────────────────────
|
|
new NotionSyncConstruct(this, 'NotionSync', {
|
|
region: this.region,
|
|
kbDocsBucket: knowledgeBase.docsBucket,
|
|
knowledgeBaseId: knowledgeBase.knowledgeBase.knowledgeBaseId,
|
|
dataSourceId: knowledgeBase.dataSource.dataSourceId,
|
|
});
|
|
|
|
// ── Purchase Orders → KB daily sync (EventBridge + Lambda) ────────────────
|
|
new PoSyncConstruct(this, 'PoSync', {
|
|
region: this.region,
|
|
kbDocsBucket: knowledgeBase.docsBucket,
|
|
knowledgeBaseId: knowledgeBase.knowledgeBase.knowledgeBaseId,
|
|
dataSourceId: knowledgeBase.dataSource.dataSourceId,
|
|
});
|
|
|
|
// ── Work Orders → KB daily sync (EventBridge + Lambda) ────────────────────
|
|
new WorkorderSyncConstruct(this, 'WorkorderSync', {
|
|
region: this.region,
|
|
kbDocsBucket: knowledgeBase.docsBucket,
|
|
knowledgeBaseId: knowledgeBase.knowledgeBase.knowledgeBaseId,
|
|
dataSourceId: knowledgeBase.dataSource.dataSourceId,
|
|
});
|
|
|
|
// ── Slack handler (processor + app home + QBO OAuth + API Gateway) ────────
|
|
const slackHandler = new SlackHandlerConstruct(this, 'SlackHandler', {
|
|
accountId: this.account,
|
|
region: this.region,
|
|
agentId: bedrockAgent.agent.attrAgentId,
|
|
agentAliasId: bedrockAgent.agentAlias.attrAgentAliasId,
|
|
conversationTable: conversationLog.table,
|
|
unansweredTable: conversationLog.unansweredTable,
|
|
wildcardCertArn,
|
|
vpc,
|
|
lambdaSecurityGroup,
|
|
});
|
|
|
|
// ── Socket Mode (ECS Fargate — replaces webhook Lambda) ──────────────────
|
|
new SocketModeConstruct(this, 'SocketMode', {
|
|
vpc,
|
|
processorLambda: slackHandler.processorLambda,
|
|
appHomeLambda: slackHandler.appHomeLambda,
|
|
});
|
|
|
|
// ── Stack outputs ─────────────────────────────────────────────────────────
|
|
new cdk.CfnOutput(this, 'KBDocsBucketName', {
|
|
value: knowledgeBase.docsBucket.bucketName,
|
|
description: 'Upload SA8000 docs, SOPs, and employee handbook here to populate the KB',
|
|
});
|
|
|
|
new cdk.CfnOutput(this, 'AgentId', {
|
|
value: bedrockAgent.agent.attrAgentId,
|
|
description: 'Bedrock Agent ID (Alex)',
|
|
});
|
|
}
|
|
}
|