@@ -3,35 +3,44 @@ import { SlackInteractionsEnv } from '@functions/slack-interaction-handler';
3
3
import { makeLogger } from '@src/logging' ;
4
4
import { v4 as uuid } from 'uuid' ;
5
5
import {
6
- QBusinessClient ,
6
+ AttachmentInput ,
7
7
ChatSyncCommand ,
8
+ ChatSyncCommandOutput ,
9
+ MessageUsefulness ,
10
+ MessageUsefulnessReason ,
8
11
PutFeedbackCommand ,
9
12
PutFeedbackCommandInput ,
10
- MessageUsefulnessReason ,
11
- MessageUsefulness ,
12
13
PutFeedbackCommandOutput ,
13
- ChatSyncCommandOutput ,
14
- AttachmentInput
14
+ QBusinessClient
15
15
} from '@aws-sdk/client-qbusiness' ;
16
16
import { Credentials } from 'aws-sdk' ;
17
17
18
18
const logger = makeLogger ( 'amazon-q-client' ) ;
19
19
20
- let amazonQClient : QBusinessClient | null = null ;
20
+ const amazonQClientBySlackUserId : { [ key : string ] : QBusinessClient } = { } ;
21
21
22
- export const getClient = ( env : SlackEventsEnv , iamSessionCreds : Credentials ) => {
23
- if ( amazonQClient === null ) {
24
- logger . debug ( `Initiating AmazonQ client with region ${ env . AMAZON_Q_REGION } ` ) ;
25
- amazonQClient = new QBusinessClient ( {
26
- credentials : iamSessionCreds ,
27
- region : env . AMAZON_Q_REGION
28
- } ) ;
22
+ export const getClient = (
23
+ env : SlackEventsEnv ,
24
+ slackUserId : string ,
25
+ iamSessionCreds : Credentials
26
+ ) => {
27
+ logger . debug ( `Initiating AmazonQ client with region ${ env . AMAZON_Q_REGION } ` ) ;
28
+ if ( amazonQClientBySlackUserId [ slackUserId ] ) {
29
+ return amazonQClientBySlackUserId [ slackUserId ] ;
29
30
}
30
31
31
- return amazonQClient ;
32
+ const newClient = new QBusinessClient ( {
33
+ credentials : iamSessionCreds ,
34
+ region : env . AMAZON_Q_REGION
35
+ } ) ;
36
+
37
+ amazonQClientBySlackUserId [ slackUserId ] = newClient ;
38
+
39
+ return newClient ;
32
40
} ;
33
41
34
42
export const callClient = async (
43
+ slackUserId : string ,
35
44
message : string ,
36
45
attachments : AttachmentInput [ ] ,
37
46
env : SlackEventsEnv ,
@@ -50,10 +59,11 @@ export const callClient = async (
50
59
} ;
51
60
52
61
logger . debug ( `callClient input ${ JSON . stringify ( input ) } ` ) ;
53
- return await getClient ( env , iamSessionCreds ) . send ( new ChatSyncCommand ( input ) ) ;
62
+ return await getClient ( env , slackUserId , iamSessionCreds ) . send ( new ChatSyncCommand ( input ) ) ;
54
63
} ;
55
64
56
65
export const submitFeedbackRequest = async (
66
+ slackUserId : string ,
57
67
env : SlackInteractionsEnv ,
58
68
iamSessionCreds : Credentials ,
59
69
context : {
@@ -76,7 +86,9 @@ export const submitFeedbackRequest = async (
76
86
} ;
77
87
78
88
logger . debug ( `putFeedbackRequest input ${ JSON . stringify ( input ) } ` ) ;
79
- const response = await getClient ( env , iamSessionCreds ) . send ( new PutFeedbackCommand ( input ) ) ;
89
+ const response = await getClient ( env , slackUserId , iamSessionCreds ) . send (
90
+ new PutFeedbackCommand ( input )
91
+ ) ;
80
92
logger . debug ( `putFeedbackRequest output ${ JSON . stringify ( response ) } ` ) ;
81
93
82
94
return response ;
0 commit comments