From a85a754a9c30d0afb70a2fa6c1bcda3f80ecfedc Mon Sep 17 00:00:00 2001 From: Dylan-Dipasupil <96040584+Dylan-Dipasupil@users.noreply.github.com> Date: Thu, 29 Aug 2024 16:30:09 -0700 Subject: [PATCH 1/3] Add chatStream bufferSize config variable --- bin/convert-cfn-template.js | 6 ++++++ bin/environment.sh | 5 ++++- bin/my-amazon-q-slack-bot.ts | 4 ++++ lib/my-amazon-q-slack-bot-stack.ts | 3 ++- src/functions/slack-stream-event-handler.ts | 5 +++-- tst/mocks/mocks.ts | 3 ++- 6 files changed, 21 insertions(+), 5 deletions(-) diff --git a/bin/convert-cfn-template.js b/bin/convert-cfn-template.js index ecb9cfe..e2b1472 100644 --- a/bin/convert-cfn-template.js +++ b/bin/convert-cfn-template.js @@ -226,6 +226,12 @@ function parameterizeTemplate(template, lambdas) { Type: 'String', AllowedPattern: '^arn:aws[a-zA-Z-]*:[a-zA-Z0-9-]*:[a-z0-9-]*:[0-9]{12}:[a-zA-Z0-9:/._-]+$', Description: 'Q Business Slack Gateway IdC App Arn' + }, + ChatStreamBufferSize: { + Type: 'Number', + Default: 25, + MinValue: 1, + Description: 'Length of buffer size updates for ChatStream feature' } }; for (let lambda of lambdas) { diff --git a/bin/environment.sh b/bin/environment.sh index acd900b..4a6e340 100755 --- a/bin/environment.sh +++ b/bin/environment.sh @@ -61,6 +61,7 @@ oidc_idp_name=$(prompt_for_value "OIDCIdPName" "Name of Identity Provider (Okta, oidc_client_id=$(prompt_for_value "OIDCClientId" "OIDC Client ID" "none" "^[a-zA-Z0-9_-]{1,255}$") oidc_issuer_url=$(prompt_for_value "OIDCIssuerURL" "OIDC Issuer URL" "none" "^https://[a-zA-Z0-9.-]+(:[0-9]+)?(/.*)?$") gateway_idc_app_arn=$(prompt_for_value "GatewayIdCAppARN" "Q Gateway IdC App Arn" "none" "^arn:aws[a-zA-Z-]*:[a-zA-Z0-9-]*:[a-z0-9-]*:[0-9]{12}:[a-zA-Z0-9:/._-]+$") +chatstream_buffer_size=$(prompt_for_value "ChatStreamBufferSize" "ChatStream Buffer Size" "25" "^[1-9][0-9]{0,2}$") # Create or update the JSON file cp $json_file $json_file.bak 2> /dev/null @@ -74,6 +75,7 @@ jq -n \ --arg oidc_client_id "$oidc_client_id" \ --arg oidc_issuer_url "$oidc_issuer_url" \ --arg gateway_idc_app_arn "$gateway_idc_app_arn" \ + --arg chatstream_buffer_size "$chatstream_buffer_size" \ '{ StackName: $stack_name, AmazonQAppId: $app_id, @@ -82,7 +84,8 @@ jq -n \ OIDCIdPName: $oidc_idp_name, OIDCClientId: $oidc_client_id, OIDCIssuerURL: $oidc_issuer_url, - GatewayIdCAppARN: $gateway_idc_app_arn + GatewayIdCAppARN: $gateway_idc_app_arn, + ChatStreamBufferSize: $chatstream_buffer_size }' > "$json_file" echo "Configuration saved to $json_file" diff --git a/bin/my-amazon-q-slack-bot.ts b/bin/my-amazon-q-slack-bot.ts index 7c93bb5..2583054 100644 --- a/bin/my-amazon-q-slack-bot.ts +++ b/bin/my-amazon-q-slack-bot.ts @@ -13,6 +13,7 @@ export interface StackEnvironment { OIDCClientId: string; OIDCIssuerURL: string; GatewayIdCAppARN: string; + ChatStreamBufferSize: string; } const app = new cdk.App(); @@ -46,6 +47,9 @@ if (environment.OIDCIssuerURL === undefined) { if (environment.GatewayIdCAppARN === undefined) { throw new Error('GatewayIdCAppARN is required'); } +if (environment.ChatStreamBufferSize === undefined) { + throw new Error('ChatStreamBufferSize is required'); +} new MyAmazonQSlackBotStack( app, diff --git a/lib/my-amazon-q-slack-bot-stack.ts b/lib/my-amazon-q-slack-bot-stack.ts index e7ebaf0..b57f930 100644 --- a/lib/my-amazon-q-slack-bot-stack.ts +++ b/lib/my-amazon-q-slack-bot-stack.ts @@ -350,7 +350,8 @@ export class MyAmazonQSlackBotStack extends cdk.Stack { OIDC_REDIRECT_URL: oidcCallbackApi.url, KEY_ARN: kmsKey.keyArn, Q_USER_API_ROLE_ARN: qUserAPIRole.roleArn, - GATEWAY_IDC_APP_ARN: env.GatewayIdCAppARN + GATEWAY_IDC_APP_ARN: env.GatewayIdCAppARN, + CHATSTREAM_BUFFER_SIZE: env.ChatStreamBufferSize }, role: slackLambdaExecutionRole, vpc diff --git a/src/functions/slack-stream-event-handler.ts b/src/functions/slack-stream-event-handler.ts index 9175dc0..ff970a3 100644 --- a/src/functions/slack-stream-event-handler.ts +++ b/src/functions/slack-stream-event-handler.ts @@ -35,7 +35,8 @@ const processSlackEventsEnv = (env: NodeJS.ProcessEnv) => ({ OIDC_REDIRECT_URL: getOrThrowIfEmpty(env.OIDC_REDIRECT_URL), KMS_KEY_ARN: getOrThrowIfEmpty(env.KEY_ARN), Q_USER_API_ROLE_ARN: getOrThrowIfEmpty(env.Q_USER_API_ROLE_ARN), - GATEWAY_IDC_APP_ARN: getOrThrowIfEmpty(env.GATEWAY_IDC_APP_ARN) + GATEWAY_IDC_APP_ARN: getOrThrowIfEmpty(env.GATEWAY_IDC_APP_ARN), + CHATSTREAM_BUFFER_SIZE: getOrThrowIfEmpty(env.CHATSTREAM_BUFFER_SIZE) }); export type SlackEventsEnv = ReturnType; @@ -368,7 +369,7 @@ export const handler = async ( } let buffer = ''; - const bufferSize = 50; + const bufferSize = Number(slackEventsEnv.CHATSTREAM_BUFFER_SIZE) let failedAttachmentEvents: FailedAttachmentEvent[] = []; let latestMetadataEvent: MetadataEvent = {} diff --git a/tst/mocks/mocks.ts b/tst/mocks/mocks.ts index eacff27..2b4b90c 100644 --- a/tst/mocks/mocks.ts +++ b/tst/mocks/mocks.ts @@ -23,7 +23,8 @@ export const MOCK_ENV = { KMS_KEY_ARN: 'KMS_KEY_ARN', OIDC_CLIENT_SECRET_NAME: 'OIDC_CLIENT_SECRET_NAME', Q_USER_API_ROLE_ARN: 'Q_USER_API_ROLE_ARN', - GATEWAY_IDC_APP_ARN: 'GATEWAY_IDC_APP_ARN' + GATEWAY_IDC_APP_ARN: 'GATEWAY_IDC_APP_ARN', + CHATSTREAM_BUFFER_SIZE: 'CHATSTREAM_BUFFER_SIZE' }; /* eslint @typescript-eslint/no-explicit-any: "off" */ From 50c8640e201e047df1389e06a00810a97bf6f310 Mon Sep 17 00:00:00 2001 From: Dylan-Dipasupil <96040584+Dylan-Dipasupil@users.noreply.github.com> Date: Thu, 29 Aug 2024 16:33:39 -0700 Subject: [PATCH 2/3] Revert "Merge pull request #3 from Dylan-Dipasupil/feature/q-slack-chat-stream" This reverts commit 98d6f635198a1e3f4c1a20ca986c95a067308a15, reversing changes made to d5bf838689e6116ffab3655645fc6b3c99381235. --- bin/convert-cfn-template.js | 6 ------ bin/environment.sh | 5 +---- bin/my-amazon-q-slack-bot.ts | 4 ---- lib/my-amazon-q-slack-bot-stack.ts | 3 +-- src/functions/slack-stream-event-handler.ts | 5 ++--- tst/mocks/mocks.ts | 3 +-- 6 files changed, 5 insertions(+), 21 deletions(-) diff --git a/bin/convert-cfn-template.js b/bin/convert-cfn-template.js index e2b1472..ecb9cfe 100644 --- a/bin/convert-cfn-template.js +++ b/bin/convert-cfn-template.js @@ -226,12 +226,6 @@ function parameterizeTemplate(template, lambdas) { Type: 'String', AllowedPattern: '^arn:aws[a-zA-Z-]*:[a-zA-Z0-9-]*:[a-z0-9-]*:[0-9]{12}:[a-zA-Z0-9:/._-]+$', Description: 'Q Business Slack Gateway IdC App Arn' - }, - ChatStreamBufferSize: { - Type: 'Number', - Default: 25, - MinValue: 1, - Description: 'Length of buffer size updates for ChatStream feature' } }; for (let lambda of lambdas) { diff --git a/bin/environment.sh b/bin/environment.sh index 4a6e340..acd900b 100755 --- a/bin/environment.sh +++ b/bin/environment.sh @@ -61,7 +61,6 @@ oidc_idp_name=$(prompt_for_value "OIDCIdPName" "Name of Identity Provider (Okta, oidc_client_id=$(prompt_for_value "OIDCClientId" "OIDC Client ID" "none" "^[a-zA-Z0-9_-]{1,255}$") oidc_issuer_url=$(prompt_for_value "OIDCIssuerURL" "OIDC Issuer URL" "none" "^https://[a-zA-Z0-9.-]+(:[0-9]+)?(/.*)?$") gateway_idc_app_arn=$(prompt_for_value "GatewayIdCAppARN" "Q Gateway IdC App Arn" "none" "^arn:aws[a-zA-Z-]*:[a-zA-Z0-9-]*:[a-z0-9-]*:[0-9]{12}:[a-zA-Z0-9:/._-]+$") -chatstream_buffer_size=$(prompt_for_value "ChatStreamBufferSize" "ChatStream Buffer Size" "25" "^[1-9][0-9]{0,2}$") # Create or update the JSON file cp $json_file $json_file.bak 2> /dev/null @@ -75,7 +74,6 @@ jq -n \ --arg oidc_client_id "$oidc_client_id" \ --arg oidc_issuer_url "$oidc_issuer_url" \ --arg gateway_idc_app_arn "$gateway_idc_app_arn" \ - --arg chatstream_buffer_size "$chatstream_buffer_size" \ '{ StackName: $stack_name, AmazonQAppId: $app_id, @@ -84,8 +82,7 @@ jq -n \ OIDCIdPName: $oidc_idp_name, OIDCClientId: $oidc_client_id, OIDCIssuerURL: $oidc_issuer_url, - GatewayIdCAppARN: $gateway_idc_app_arn, - ChatStreamBufferSize: $chatstream_buffer_size + GatewayIdCAppARN: $gateway_idc_app_arn }' > "$json_file" echo "Configuration saved to $json_file" diff --git a/bin/my-amazon-q-slack-bot.ts b/bin/my-amazon-q-slack-bot.ts index 2583054..7c93bb5 100644 --- a/bin/my-amazon-q-slack-bot.ts +++ b/bin/my-amazon-q-slack-bot.ts @@ -13,7 +13,6 @@ export interface StackEnvironment { OIDCClientId: string; OIDCIssuerURL: string; GatewayIdCAppARN: string; - ChatStreamBufferSize: string; } const app = new cdk.App(); @@ -47,9 +46,6 @@ if (environment.OIDCIssuerURL === undefined) { if (environment.GatewayIdCAppARN === undefined) { throw new Error('GatewayIdCAppARN is required'); } -if (environment.ChatStreamBufferSize === undefined) { - throw new Error('ChatStreamBufferSize is required'); -} new MyAmazonQSlackBotStack( app, diff --git a/lib/my-amazon-q-slack-bot-stack.ts b/lib/my-amazon-q-slack-bot-stack.ts index b57f930..e7ebaf0 100644 --- a/lib/my-amazon-q-slack-bot-stack.ts +++ b/lib/my-amazon-q-slack-bot-stack.ts @@ -350,8 +350,7 @@ export class MyAmazonQSlackBotStack extends cdk.Stack { OIDC_REDIRECT_URL: oidcCallbackApi.url, KEY_ARN: kmsKey.keyArn, Q_USER_API_ROLE_ARN: qUserAPIRole.roleArn, - GATEWAY_IDC_APP_ARN: env.GatewayIdCAppARN, - CHATSTREAM_BUFFER_SIZE: env.ChatStreamBufferSize + GATEWAY_IDC_APP_ARN: env.GatewayIdCAppARN }, role: slackLambdaExecutionRole, vpc diff --git a/src/functions/slack-stream-event-handler.ts b/src/functions/slack-stream-event-handler.ts index ff970a3..9175dc0 100644 --- a/src/functions/slack-stream-event-handler.ts +++ b/src/functions/slack-stream-event-handler.ts @@ -35,8 +35,7 @@ const processSlackEventsEnv = (env: NodeJS.ProcessEnv) => ({ OIDC_REDIRECT_URL: getOrThrowIfEmpty(env.OIDC_REDIRECT_URL), KMS_KEY_ARN: getOrThrowIfEmpty(env.KEY_ARN), Q_USER_API_ROLE_ARN: getOrThrowIfEmpty(env.Q_USER_API_ROLE_ARN), - GATEWAY_IDC_APP_ARN: getOrThrowIfEmpty(env.GATEWAY_IDC_APP_ARN), - CHATSTREAM_BUFFER_SIZE: getOrThrowIfEmpty(env.CHATSTREAM_BUFFER_SIZE) + GATEWAY_IDC_APP_ARN: getOrThrowIfEmpty(env.GATEWAY_IDC_APP_ARN) }); export type SlackEventsEnv = ReturnType; @@ -369,7 +368,7 @@ export const handler = async ( } let buffer = ''; - const bufferSize = Number(slackEventsEnv.CHATSTREAM_BUFFER_SIZE) + const bufferSize = 50; let failedAttachmentEvents: FailedAttachmentEvent[] = []; let latestMetadataEvent: MetadataEvent = {} diff --git a/tst/mocks/mocks.ts b/tst/mocks/mocks.ts index 2b4b90c..eacff27 100644 --- a/tst/mocks/mocks.ts +++ b/tst/mocks/mocks.ts @@ -23,8 +23,7 @@ export const MOCK_ENV = { KMS_KEY_ARN: 'KMS_KEY_ARN', OIDC_CLIENT_SECRET_NAME: 'OIDC_CLIENT_SECRET_NAME', Q_USER_API_ROLE_ARN: 'Q_USER_API_ROLE_ARN', - GATEWAY_IDC_APP_ARN: 'GATEWAY_IDC_APP_ARN', - CHATSTREAM_BUFFER_SIZE: 'CHATSTREAM_BUFFER_SIZE' + GATEWAY_IDC_APP_ARN: 'GATEWAY_IDC_APP_ARN' }; /* eslint @typescript-eslint/no-explicit-any: "off" */ From 8cc9b7460a76882ed8a3a06aef8c44c9c059d52c Mon Sep 17 00:00:00 2001 From: Dylan-Dipasupil <96040584+Dylan-Dipasupil@users.noreply.github.com> Date: Thu, 29 Aug 2024 16:46:02 -0700 Subject: [PATCH 3/3] Add chatStream bufferSize config variable --- bin/convert-cfn-template.js | 6 ++++++ bin/environment.sh | 5 ++++- bin/my-amazon-q-slack-bot.ts | 4 ++++ lib/my-amazon-q-slack-bot-stack.ts | 3 ++- src/functions/slack-stream-event-handler.ts | 3 ++- tst/mocks/mocks.ts | 3 ++- 6 files changed, 20 insertions(+), 4 deletions(-) diff --git a/bin/convert-cfn-template.js b/bin/convert-cfn-template.js index ecb9cfe..e2b1472 100644 --- a/bin/convert-cfn-template.js +++ b/bin/convert-cfn-template.js @@ -226,6 +226,12 @@ function parameterizeTemplate(template, lambdas) { Type: 'String', AllowedPattern: '^arn:aws[a-zA-Z-]*:[a-zA-Z0-9-]*:[a-z0-9-]*:[0-9]{12}:[a-zA-Z0-9:/._-]+$', Description: 'Q Business Slack Gateway IdC App Arn' + }, + ChatStreamBufferSize: { + Type: 'Number', + Default: 25, + MinValue: 1, + Description: 'Length of buffer size updates for ChatStream feature' } }; for (let lambda of lambdas) { diff --git a/bin/environment.sh b/bin/environment.sh index acd900b..173b1d0 100755 --- a/bin/environment.sh +++ b/bin/environment.sh @@ -60,7 +60,8 @@ ttl_days=$(prompt_for_value "ContextDaysToLive" "Number of days to keep conversa oidc_idp_name=$(prompt_for_value "OIDCIdPName" "Name of Identity Provider (Okta, Cognito, Other)" "Okta" "^[a-zA-Z]{1,255}$") oidc_client_id=$(prompt_for_value "OIDCClientId" "OIDC Client ID" "none" "^[a-zA-Z0-9_-]{1,255}$") oidc_issuer_url=$(prompt_for_value "OIDCIssuerURL" "OIDC Issuer URL" "none" "^https://[a-zA-Z0-9.-]+(:[0-9]+)?(/.*)?$") -gateway_idc_app_arn=$(prompt_for_value "GatewayIdCAppARN" "Q Gateway IdC App Arn" "none" "^arn:aws[a-zA-Z-]*:[a-zA-Z0-9-]*:[a-z0-9-]*:[0-9]{12}:[a-zA-Z0-9:/._-]+$") +gateway_idc_app_arn=$(prompt_for_value "GatewayIdCAppARN" "Q Gateway IdC App Arn" "none" "^arn:aws[a-zA-Z-]*:[a-zA-Z0-9-]*:[a-z0-9-]*:[0-9]{12}:[a-zA-Z0-9:/._-]+$"), +chatstream_buffer_size=$(prompt_for_value "ChatStreamBufferSize" "ChatStream Buffer Size" "25" "^[1-9][0-9]{0,2}$") # Create or update the JSON file cp $json_file $json_file.bak 2> /dev/null @@ -74,6 +75,7 @@ jq -n \ --arg oidc_client_id "$oidc_client_id" \ --arg oidc_issuer_url "$oidc_issuer_url" \ --arg gateway_idc_app_arn "$gateway_idc_app_arn" \ + --arg chatstream_buffer_size "$chatstream_buffer_size" \ '{ StackName: $stack_name, AmazonQAppId: $app_id, @@ -83,6 +85,7 @@ jq -n \ OIDCClientId: $oidc_client_id, OIDCIssuerURL: $oidc_issuer_url, GatewayIdCAppARN: $gateway_idc_app_arn + ChatStreamBufferSize: $chatstream_buffer_size }' > "$json_file" echo "Configuration saved to $json_file" diff --git a/bin/my-amazon-q-slack-bot.ts b/bin/my-amazon-q-slack-bot.ts index 7c93bb5..2583054 100644 --- a/bin/my-amazon-q-slack-bot.ts +++ b/bin/my-amazon-q-slack-bot.ts @@ -13,6 +13,7 @@ export interface StackEnvironment { OIDCClientId: string; OIDCIssuerURL: string; GatewayIdCAppARN: string; + ChatStreamBufferSize: string; } const app = new cdk.App(); @@ -46,6 +47,9 @@ if (environment.OIDCIssuerURL === undefined) { if (environment.GatewayIdCAppARN === undefined) { throw new Error('GatewayIdCAppARN is required'); } +if (environment.ChatStreamBufferSize === undefined) { + throw new Error('ChatStreamBufferSize is required'); +} new MyAmazonQSlackBotStack( app, diff --git a/lib/my-amazon-q-slack-bot-stack.ts b/lib/my-amazon-q-slack-bot-stack.ts index e7ebaf0..b57f930 100644 --- a/lib/my-amazon-q-slack-bot-stack.ts +++ b/lib/my-amazon-q-slack-bot-stack.ts @@ -350,7 +350,8 @@ export class MyAmazonQSlackBotStack extends cdk.Stack { OIDC_REDIRECT_URL: oidcCallbackApi.url, KEY_ARN: kmsKey.keyArn, Q_USER_API_ROLE_ARN: qUserAPIRole.roleArn, - GATEWAY_IDC_APP_ARN: env.GatewayIdCAppARN + GATEWAY_IDC_APP_ARN: env.GatewayIdCAppARN, + CHATSTREAM_BUFFER_SIZE: env.ChatStreamBufferSize }, role: slackLambdaExecutionRole, vpc diff --git a/src/functions/slack-stream-event-handler.ts b/src/functions/slack-stream-event-handler.ts index 9175dc0..1a6bcf7 100644 --- a/src/functions/slack-stream-event-handler.ts +++ b/src/functions/slack-stream-event-handler.ts @@ -35,7 +35,8 @@ const processSlackEventsEnv = (env: NodeJS.ProcessEnv) => ({ OIDC_REDIRECT_URL: getOrThrowIfEmpty(env.OIDC_REDIRECT_URL), KMS_KEY_ARN: getOrThrowIfEmpty(env.KEY_ARN), Q_USER_API_ROLE_ARN: getOrThrowIfEmpty(env.Q_USER_API_ROLE_ARN), - GATEWAY_IDC_APP_ARN: getOrThrowIfEmpty(env.GATEWAY_IDC_APP_ARN) + GATEWAY_IDC_APP_ARN: getOrThrowIfEmpty(env.GATEWAY_IDC_APP_ARN), + CHATSTREAM_BUFFER_SIZE: getOrThrowIfEmpty(env.CHATSTREAM_BUFFER_SIZE) }); export type SlackEventsEnv = ReturnType; diff --git a/tst/mocks/mocks.ts b/tst/mocks/mocks.ts index eacff27..2b4b90c 100644 --- a/tst/mocks/mocks.ts +++ b/tst/mocks/mocks.ts @@ -23,7 +23,8 @@ export const MOCK_ENV = { KMS_KEY_ARN: 'KMS_KEY_ARN', OIDC_CLIENT_SECRET_NAME: 'OIDC_CLIENT_SECRET_NAME', Q_USER_API_ROLE_ARN: 'Q_USER_API_ROLE_ARN', - GATEWAY_IDC_APP_ARN: 'GATEWAY_IDC_APP_ARN' + GATEWAY_IDC_APP_ARN: 'GATEWAY_IDC_APP_ARN', + CHATSTREAM_BUFFER_SIZE: 'CHATSTREAM_BUFFER_SIZE' }; /* eslint @typescript-eslint/no-explicit-any: "off" */