Skip to content

Commit

Permalink
Merge pull request #2 from Dylan-Dipasupil/feature/q-slack-chat-stream
Browse files Browse the repository at this point in the history
Add Lambda Handler for Slack-Gateway streaming & update helper functions for Chat API.
  • Loading branch information
Dylan-Dipasupil authored Aug 28, 2024
2 parents f489d3d + 9e504d9 commit d5bf838
Show file tree
Hide file tree
Showing 16 changed files with 10,576 additions and 2,309 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.3.0] - 2024-08-29
### Added
Add optional streaming response feature.
- New Lambda function queries the Amazon Q Business Chat API and updates the Slack channel in real-time as LLM generates response.
- Can easily switch between ChatSync and Chat response modes by modifying the Slack app's event subscription endpoint.

## [0.2.0] - 2024-05-28
### Added
Add support for Q Business Apps integrated with IdC
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,19 @@ Let's now add your app into your workspace, this is required to generate the `Bo
4. Choose `Edit`
5. Replace the value of `OidcClientSecret`, you will find the value in the Okta app client settings (step 1.1).

#### 4.4 (Optional) Configure Slack app to use chat stream feature

To enable the streaming response feature, we need to modify the Slack app.

1. Login to your AWS console
2. In your AWS account go to Cloudformation
3. Copy the URL of the stack output ending with name : `SlackStreamEventHandlerApiEndpoint`.
4. Open the Slack app settings (api.slack.com) and go to the Event Subscriptions section.
5. In the Request URL block, select "change" and paste the copied URL into the "New Request URL" field.
6. Save the changes.

To revert to using the ChatSync feature, follow the same steps, but in step 3, copy the stack output with the name `SlackEventHandlerApiEndpoint` instead.

### Say hello
> Time to say Hi!
Expand Down
13 changes: 13 additions & 0 deletions README_DEVELOPERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,19 @@ Let's now add your app into your workspace, this is required to generate the `Bo
4. Choose `Edit`
5. Replace the value of `OidcClientSecret`, you will find those values in the IdP app client configuration.

#### 4.4 (Optional) Configure Slack app to use chat stream feature

To enable the streaming response feature, we need to modify the Slack app.

1. Login to your AWS console
2. In your AWS account go to Cloudformation
3. Copy the URL of the stack output ending with name : `SlackStreamEventHandlerApiEndpoint`.
4. Open the Slack app settings (api.slack.com) and go to the Event Subscriptions section.
5. In the Request URL block, select "change" and paste the copied URL into the "New Request URL" field.
6. Save the changes.

To revert to using the ChatSync feature, follow the same steps, but in step 3, copy the stack output with the name `SlackEventHandlerApiEndpoint` instead.

### Say hello
> Time to say Hi!
Expand Down
9 changes: 7 additions & 2 deletions lib/my-amazon-q-slack-bot-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export class MyAmazonQSlackBotStack extends cdk.Stack {
ChatPolicy: new PolicyDocument({
statements: [
new PolicyStatement({
actions: ['qbusiness:ChatSync', 'qbusiness:PutFeedback'],
actions: ['qbusiness:ChatSync', 'qbusiness:Chat', 'qbusiness:PutFeedback'],
// parametrized
resources: [`arn:aws:qbusiness:*:*:application/${env.AmazonQAppId}`]
})
Expand Down Expand Up @@ -249,7 +249,7 @@ export class MyAmazonQSlackBotStack extends cdk.Stack {
ChatPolicy: new PolicyDocument({
statements: [
new PolicyStatement({
actions: ['qbusiness:ChatSync', 'qbusiness:PutFeedback'],
actions: ['qbusiness:ChatSync', 'qbusiness:Chat', 'qbusiness:PutFeedback'],
resources: ['arn:aws:qbusiness:*:*:application/*']
})
]
Expand Down Expand Up @@ -316,6 +316,11 @@ export class MyAmazonQSlackBotStack extends cdk.Stack {
handler: 'slack-command-handler',
id: 'SlackCommandHandler',
description: 'Handler for Slack commands'
},
{
handler: 'slack-stream-event-handler',
id: 'SlackStreamEventHandler',
description: 'Handler for Slack events - Streams response'
}
].map((p) => {
const prefix = `${props.stackName}-${p.id}`;
Expand Down
Loading

0 comments on commit d5bf838

Please sign in to comment.