cdk-amazon-connect-constructs 0.1.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jsii +10995 -0
- package/LICENSE +21 -0
- package/README.md +133 -0
- package/connect-constructs.test.ts +797 -0
- package/lib/connect-instance.d.ts +125 -0
- package/lib/connect-instance.d.ts.map +1 -0
- package/lib/connect-instance.js +88 -0
- package/lib/contact-flow.d.ts +81 -0
- package/lib/contact-flow.d.ts.map +1 -0
- package/lib/contact-flow.js +80 -0
- package/lib/hours-of-operation.d.ts +102 -0
- package/lib/hours-of-operation.d.ts.map +1 -0
- package/lib/hours-of-operation.js +94 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +23 -0
- package/lib/lambda-integration.d.ts +27 -0
- package/lib/lambda-integration.d.ts.map +1 -0
- package/lib/lambda-integration.js +37 -0
- package/lib/private/arn.d.ts +3 -0
- package/lib/private/arn.d.ts.map +1 -0
- package/lib/private/arn.js +8 -0
- package/lib/queue.d.ts +103 -0
- package/lib/queue.d.ts.map +1 -0
- package/lib/queue.js +64 -0
- package/lib/routing-profile.d.ts +110 -0
- package/lib/routing-profile.d.ts.map +1 -0
- package/lib/routing-profile.js +89 -0
- package/package.json +73 -0
- package/scripts/patch-java-pom.js +45 -0
- package/src/connect-instance.ts +190 -0
- package/src/contact-flow.ts +123 -0
- package/src/hours-of-operation.ts +184 -0
- package/src/index.ts +6 -0
- package/src/lambda-integration.ts +51 -0
- package/src/private/arn.ts +6 -0
- package/src/queue.ts +152 -0
- package/src/routing-profile.ts +196 -0
- package/tsconfig.jsii.json +40 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { aws_connect as connect } from 'aws-cdk-lib';
|
|
2
|
+
import { Construct } from 'constructs';
|
|
3
|
+
import { resourceNameFromSlashArn } from './private/arn';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Common identity-management modes supported by Amazon Connect.
|
|
7
|
+
*/
|
|
8
|
+
export enum IdentityManagementType {
|
|
9
|
+
/**
|
|
10
|
+
* Amazon Connect stores user identities.
|
|
11
|
+
*/
|
|
12
|
+
CONNECT_MANAGED = 'CONNECT_MANAGED',
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Users are managed by an existing SAML identity provider.
|
|
16
|
+
*/
|
|
17
|
+
SAML = 'SAML',
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Users are managed by AWS Directory Service.
|
|
21
|
+
*/
|
|
22
|
+
EXISTING_DIRECTORY = 'EXISTING_DIRECTORY',
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Capabilities enabled for an Amazon Connect instance.
|
|
27
|
+
*/
|
|
28
|
+
export interface ConnectInstanceAttributes {
|
|
29
|
+
/**
|
|
30
|
+
* Allow inbound calls.
|
|
31
|
+
*
|
|
32
|
+
* @default true
|
|
33
|
+
*/
|
|
34
|
+
readonly inboundCalls?: boolean;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Allow outbound calls.
|
|
38
|
+
*
|
|
39
|
+
* @default true
|
|
40
|
+
*/
|
|
41
|
+
readonly outboundCalls?: boolean;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Enable contact flow logs.
|
|
45
|
+
*
|
|
46
|
+
* @default false
|
|
47
|
+
*/
|
|
48
|
+
readonly contactflowLogs?: boolean;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Enable contact lens.
|
|
52
|
+
*
|
|
53
|
+
* @default false
|
|
54
|
+
*/
|
|
55
|
+
readonly contactLens?: boolean;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Enable early media.
|
|
59
|
+
*
|
|
60
|
+
* @default false
|
|
61
|
+
*/
|
|
62
|
+
readonly earlyMedia?: boolean;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Enable use of custom chatbots.
|
|
66
|
+
*
|
|
67
|
+
* @default false
|
|
68
|
+
*/
|
|
69
|
+
readonly useCustomTtsVoices?: boolean;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* An Amazon Connect instance reference.
|
|
74
|
+
*/
|
|
75
|
+
export interface IConnectInstance {
|
|
76
|
+
/**
|
|
77
|
+
* The Amazon Connect instance ARN.
|
|
78
|
+
*/
|
|
79
|
+
readonly instanceArn: string;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The Amazon Connect instance ID.
|
|
83
|
+
*/
|
|
84
|
+
readonly instanceId: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Properties for a new Amazon Connect instance.
|
|
89
|
+
*/
|
|
90
|
+
export interface ConnectInstanceProps {
|
|
91
|
+
/**
|
|
92
|
+
* The instance alias shown in the Amazon Connect console.
|
|
93
|
+
*/
|
|
94
|
+
readonly instanceAlias: string;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* How identities are managed for this instance.
|
|
98
|
+
*
|
|
99
|
+
* @default IdentityManagementType.CONNECT_MANAGED
|
|
100
|
+
*/
|
|
101
|
+
readonly identityManagementType?: IdentityManagementType;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Existing AWS Directory Service directory ID.
|
|
105
|
+
*
|
|
106
|
+
* Required when identityManagementType is EXISTING_DIRECTORY.
|
|
107
|
+
*
|
|
108
|
+
* @default - no directory ID
|
|
109
|
+
*/
|
|
110
|
+
readonly directoryId?: string;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Instance capabilities.
|
|
114
|
+
*
|
|
115
|
+
* @default - inbound and outbound calls enabled
|
|
116
|
+
*/
|
|
117
|
+
readonly attributes?: ConnectInstanceAttributes;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* L2-style wrapper for AWS::Connect::Instance.
|
|
122
|
+
*/
|
|
123
|
+
export class ConnectInstance extends Construct implements IConnectInstance {
|
|
124
|
+
/**
|
|
125
|
+
* Import an existing Amazon Connect instance by ARN.
|
|
126
|
+
*/
|
|
127
|
+
public static fromInstanceArn(scope: Construct, id: string, instanceArn: string): IConnectInstance {
|
|
128
|
+
return new ImportedConnectInstance(scope, id, instanceArn);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* The underlying CloudFormation resource.
|
|
133
|
+
*/
|
|
134
|
+
public readonly resource: connect.CfnInstance;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The Amazon Connect instance ARN.
|
|
138
|
+
*/
|
|
139
|
+
public readonly instanceArn: string;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* The Amazon Connect instance ID.
|
|
143
|
+
*/
|
|
144
|
+
public readonly instanceId: string;
|
|
145
|
+
|
|
146
|
+
public constructor(scope: Construct, id: string, props: ConnectInstanceProps) {
|
|
147
|
+
super(scope, id);
|
|
148
|
+
|
|
149
|
+
if (!props.instanceAlias.trim()) {
|
|
150
|
+
throw new Error('instanceAlias must not be empty.');
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const identityManagementType = props.identityManagementType ?? IdentityManagementType.CONNECT_MANAGED;
|
|
154
|
+
if (identityManagementType === IdentityManagementType.EXISTING_DIRECTORY && !props.directoryId) {
|
|
155
|
+
throw new Error('directoryId is required when identityManagementType is EXISTING_DIRECTORY.');
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
this.resource = new connect.CfnInstance(this, 'Resource', {
|
|
159
|
+
attributes: toCfnAttributes(props.attributes),
|
|
160
|
+
directoryId: props.directoryId,
|
|
161
|
+
identityManagementType,
|
|
162
|
+
instanceAlias: props.instanceAlias,
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
this.instanceArn = this.resource.getAtt('Arn').toString();
|
|
166
|
+
this.instanceId = this.resource.getAtt('Id').toString();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
class ImportedConnectInstance extends Construct implements IConnectInstance {
|
|
171
|
+
public readonly instanceArn: string;
|
|
172
|
+
public readonly instanceId: string;
|
|
173
|
+
|
|
174
|
+
public constructor(scope: Construct, id: string, instanceArn: string) {
|
|
175
|
+
super(scope, id);
|
|
176
|
+
this.instanceArn = instanceArn;
|
|
177
|
+
this.instanceId = resourceNameFromSlashArn(this, instanceArn);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function toCfnAttributes(attributes?: ConnectInstanceAttributes): connect.CfnInstance.AttributesProperty {
|
|
182
|
+
return {
|
|
183
|
+
inboundCalls: attributes?.inboundCalls ?? true,
|
|
184
|
+
outboundCalls: attributes?.outboundCalls ?? true,
|
|
185
|
+
contactflowLogs: attributes?.contactflowLogs ?? false,
|
|
186
|
+
contactLens: attributes?.contactLens ?? false,
|
|
187
|
+
earlyMedia: attributes?.earlyMedia ?? false,
|
|
188
|
+
useCustomTtsVoices: attributes?.useCustomTtsVoices ?? false,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { aws_connect as connect } from 'aws-cdk-lib';
|
|
2
|
+
import { Construct } from 'constructs';
|
|
3
|
+
import { IConnectInstance } from './connect-instance';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Amazon Connect contact flow type.
|
|
7
|
+
*/
|
|
8
|
+
export enum ContactFlowType {
|
|
9
|
+
CONTACT_FLOW = 'CONTACT_FLOW',
|
|
10
|
+
CUSTOMER_QUEUE = 'CUSTOMER_QUEUE',
|
|
11
|
+
CUSTOMER_HOLD = 'CUSTOMER_HOLD',
|
|
12
|
+
CUSTOMER_WHISPER = 'CUSTOMER_WHISPER',
|
|
13
|
+
AGENT_HOLD = 'AGENT_HOLD',
|
|
14
|
+
AGENT_WHISPER = 'AGENT_WHISPER',
|
|
15
|
+
OUTBOUND_WHISPER = 'OUTBOUND_WHISPER',
|
|
16
|
+
AGENT_TRANSFER = 'AGENT_TRANSFER',
|
|
17
|
+
QUEUE_TRANSFER = 'QUEUE_TRANSFER',
|
|
18
|
+
CAMPAIGN = 'CAMPAIGN',
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Contact flow lifecycle state.
|
|
23
|
+
*/
|
|
24
|
+
export enum ContactFlowState {
|
|
25
|
+
ACTIVE = 'ACTIVE',
|
|
26
|
+
ARCHIVED = 'ARCHIVED',
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Properties for a JSON-backed contact flow.
|
|
31
|
+
*/
|
|
32
|
+
export interface ContactFlowProps {
|
|
33
|
+
/**
|
|
34
|
+
* The Amazon Connect instance that owns this contact flow.
|
|
35
|
+
*/
|
|
36
|
+
readonly instance: IConnectInstance;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Contact flow name.
|
|
40
|
+
*/
|
|
41
|
+
readonly name: string;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Serialized Amazon Connect contact flow JSON.
|
|
45
|
+
*/
|
|
46
|
+
readonly content: string;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Contact flow type.
|
|
50
|
+
*
|
|
51
|
+
* @default ContactFlowType.CONTACT_FLOW
|
|
52
|
+
*/
|
|
53
|
+
readonly contactFlowType?: ContactFlowType;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Optional description.
|
|
57
|
+
*
|
|
58
|
+
* @default - no description
|
|
59
|
+
*/
|
|
60
|
+
readonly description?: string;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Flow state.
|
|
64
|
+
*
|
|
65
|
+
* @default ContactFlowState.ACTIVE
|
|
66
|
+
*/
|
|
67
|
+
readonly state?: ContactFlowState;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* L2-style wrapper for AWS::Connect::ContactFlow.
|
|
72
|
+
*/
|
|
73
|
+
export class ContactFlow extends Construct {
|
|
74
|
+
/**
|
|
75
|
+
* Create a serialized contact flow body from an object.
|
|
76
|
+
*/
|
|
77
|
+
public static stringify(definition: { [key: string]: unknown }): string {
|
|
78
|
+
return JSON.stringify(definition, undefined, 2);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The underlying CloudFormation resource.
|
|
83
|
+
*/
|
|
84
|
+
public readonly resource: connect.CfnContactFlow;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The contact flow ARN.
|
|
88
|
+
*/
|
|
89
|
+
public readonly contactFlowArn: string;
|
|
90
|
+
|
|
91
|
+
public constructor(scope: Construct, id: string, props: ContactFlowProps) {
|
|
92
|
+
super(scope, id);
|
|
93
|
+
|
|
94
|
+
if (!props.name.trim()) {
|
|
95
|
+
throw new Error('name must not be empty.');
|
|
96
|
+
}
|
|
97
|
+
validateJson(props.content);
|
|
98
|
+
|
|
99
|
+
this.resource = new connect.CfnContactFlow(this, 'Resource', {
|
|
100
|
+
content: props.content,
|
|
101
|
+
description: props.description,
|
|
102
|
+
instanceArn: props.instance.instanceArn,
|
|
103
|
+
name: props.name,
|
|
104
|
+
state: props.state ?? ContactFlowState.ACTIVE,
|
|
105
|
+
type: props.contactFlowType ?? ContactFlowType.CONTACT_FLOW,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
this.contactFlowArn = this.resource.getAtt('ContactFlowArn').toString();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function validateJson(content: string): void {
|
|
113
|
+
if (!content.trim()) {
|
|
114
|
+
throw new Error('content must not be empty.');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
JSON.parse(content);
|
|
119
|
+
} catch (error) {
|
|
120
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
121
|
+
throw new Error(`content must be valid JSON: ${message}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { aws_connect as connect } from 'aws-cdk-lib';
|
|
2
|
+
import { Construct } from 'constructs';
|
|
3
|
+
import { IConnectInstance } from './connect-instance';
|
|
4
|
+
import { resourceNameFromSlashArn } from './private/arn';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Days supported by Amazon Connect hours of operation.
|
|
8
|
+
*/
|
|
9
|
+
export enum DayOfWeek {
|
|
10
|
+
SUNDAY = 'SUNDAY',
|
|
11
|
+
MONDAY = 'MONDAY',
|
|
12
|
+
TUESDAY = 'TUESDAY',
|
|
13
|
+
WEDNESDAY = 'WEDNESDAY',
|
|
14
|
+
THURSDAY = 'THURSDAY',
|
|
15
|
+
FRIDAY = 'FRIDAY',
|
|
16
|
+
SATURDAY = 'SATURDAY',
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A time of day in 24-hour format.
|
|
21
|
+
*/
|
|
22
|
+
export interface TimeOfDay {
|
|
23
|
+
/**
|
|
24
|
+
* Hour in local time, from 0 through 23.
|
|
25
|
+
*/
|
|
26
|
+
readonly hours: number;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Minute in local time, from 0 through 59.
|
|
30
|
+
*
|
|
31
|
+
* @default 0
|
|
32
|
+
*/
|
|
33
|
+
readonly minutes?: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A weekly open interval for an Amazon Connect queue.
|
|
38
|
+
*/
|
|
39
|
+
export interface WeeklyTimeRange {
|
|
40
|
+
/**
|
|
41
|
+
* Day of week for this interval.
|
|
42
|
+
*/
|
|
43
|
+
readonly day: DayOfWeek;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Interval start time.
|
|
47
|
+
*/
|
|
48
|
+
readonly startTime: TimeOfDay;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Interval end time.
|
|
52
|
+
*/
|
|
53
|
+
readonly endTime: TimeOfDay;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* An Amazon Connect hours-of-operation reference.
|
|
58
|
+
*/
|
|
59
|
+
export interface IHoursOfOperation {
|
|
60
|
+
/**
|
|
61
|
+
* The hours of operation ARN.
|
|
62
|
+
*/
|
|
63
|
+
readonly hoursOfOperationArn: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Properties for HoursOfOperation.
|
|
68
|
+
*/
|
|
69
|
+
export interface HoursOfOperationProps {
|
|
70
|
+
/**
|
|
71
|
+
* The Amazon Connect instance that owns these hours.
|
|
72
|
+
*/
|
|
73
|
+
readonly instance: IConnectInstance;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Display name.
|
|
77
|
+
*/
|
|
78
|
+
readonly name: string;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* IANA time zone, for example America/New_York.
|
|
82
|
+
*/
|
|
83
|
+
readonly timeZone: string;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Weekly open intervals.
|
|
87
|
+
*/
|
|
88
|
+
readonly config: WeeklyTimeRange[];
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Optional description.
|
|
92
|
+
*
|
|
93
|
+
* @default - no description
|
|
94
|
+
*/
|
|
95
|
+
readonly description?: string;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* L2-style wrapper for AWS::Connect::HoursOfOperation.
|
|
100
|
+
*/
|
|
101
|
+
export class HoursOfOperation extends Construct implements IHoursOfOperation {
|
|
102
|
+
/**
|
|
103
|
+
* Import existing hours of operation by ARN.
|
|
104
|
+
*/
|
|
105
|
+
public static fromHoursOfOperationArn(
|
|
106
|
+
scope: Construct,
|
|
107
|
+
id: string,
|
|
108
|
+
hoursOfOperationArn: string,
|
|
109
|
+
): IHoursOfOperation {
|
|
110
|
+
return new ImportedHoursOfOperation(scope, id, hoursOfOperationArn);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* The underlying CloudFormation resource.
|
|
115
|
+
*/
|
|
116
|
+
public readonly resource: connect.CfnHoursOfOperation;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The hours of operation ARN.
|
|
120
|
+
*/
|
|
121
|
+
public readonly hoursOfOperationArn: string;
|
|
122
|
+
|
|
123
|
+
public constructor(scope: Construct, id: string, props: HoursOfOperationProps) {
|
|
124
|
+
super(scope, id);
|
|
125
|
+
|
|
126
|
+
if (!props.name.trim()) {
|
|
127
|
+
throw new Error('name must not be empty.');
|
|
128
|
+
}
|
|
129
|
+
if (!props.timeZone.trim()) {
|
|
130
|
+
throw new Error('timeZone must not be empty.');
|
|
131
|
+
}
|
|
132
|
+
if (props.config.length === 0) {
|
|
133
|
+
throw new Error('config must include at least one weekly time range.');
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
this.resource = new connect.CfnHoursOfOperation(this, 'Resource', {
|
|
137
|
+
config: props.config.map(toCfnRange),
|
|
138
|
+
description: props.description,
|
|
139
|
+
instanceArn: props.instance.instanceArn,
|
|
140
|
+
name: props.name,
|
|
141
|
+
timeZone: props.timeZone,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
this.hoursOfOperationArn = this.resource.getAtt('HoursOfOperationArn').toString();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
class ImportedHoursOfOperation extends Construct implements IHoursOfOperation {
|
|
149
|
+
public readonly hoursOfOperationArn: string;
|
|
150
|
+
|
|
151
|
+
public constructor(scope: Construct, id: string, hoursOfOperationArn: string) {
|
|
152
|
+
super(scope, id);
|
|
153
|
+
this.hoursOfOperationArn = hoursOfOperationArn;
|
|
154
|
+
resourceNameFromSlashArn(this, hoursOfOperationArn);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function toCfnRange(range: WeeklyTimeRange): connect.CfnHoursOfOperation.HoursOfOperationConfigProperty {
|
|
159
|
+
validateTime(range.startTime, 'startTime');
|
|
160
|
+
validateTime(range.endTime, 'endTime');
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
day: range.day,
|
|
164
|
+
startTime: toCfnTime(range.startTime),
|
|
165
|
+
endTime: toCfnTime(range.endTime),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function toCfnTime(time: TimeOfDay): connect.CfnHoursOfOperation.HoursOfOperationTimeSliceProperty {
|
|
170
|
+
return {
|
|
171
|
+
hours: time.hours,
|
|
172
|
+
minutes: time.minutes ?? 0,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function validateTime(time: TimeOfDay, name: string): void {
|
|
177
|
+
if (time.hours < 0 || time.hours > 23 || !Number.isInteger(time.hours)) {
|
|
178
|
+
throw new Error(`${name}.hours must be an integer from 0 through 23.`);
|
|
179
|
+
}
|
|
180
|
+
const minutes = time.minutes ?? 0;
|
|
181
|
+
if (minutes < 0 || minutes > 59 || !Number.isInteger(minutes)) {
|
|
182
|
+
throw new Error(`${name}.minutes must be an integer from 0 through 59.`);
|
|
183
|
+
}
|
|
184
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { aws_connect as connect, aws_iam as iam, aws_lambda as lambda } from 'aws-cdk-lib';
|
|
2
|
+
import { Construct } from 'constructs';
|
|
3
|
+
import { IConnectInstance } from './connect-instance';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Properties for LambdaIntegration.
|
|
7
|
+
*/
|
|
8
|
+
export interface LambdaIntegrationProps {
|
|
9
|
+
/**
|
|
10
|
+
* Amazon Connect instance to associate with the function.
|
|
11
|
+
*/
|
|
12
|
+
readonly instance: IConnectInstance;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Lambda function that Amazon Connect can invoke.
|
|
16
|
+
*/
|
|
17
|
+
readonly function: lambda.IFunction;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Associates a Lambda function with an Amazon Connect instance and grants invoke access.
|
|
22
|
+
*/
|
|
23
|
+
export class LambdaIntegration extends Construct {
|
|
24
|
+
/**
|
|
25
|
+
* The underlying AWS::Connect::IntegrationAssociation resource.
|
|
26
|
+
*/
|
|
27
|
+
public readonly association: connect.CfnIntegrationAssociation;
|
|
28
|
+
|
|
29
|
+
public constructor(scope: Construct, id: string, props: LambdaIntegrationProps) {
|
|
30
|
+
super(scope, id);
|
|
31
|
+
|
|
32
|
+
if (!props.instance) {
|
|
33
|
+
throw new Error('instance is required.');
|
|
34
|
+
}
|
|
35
|
+
if (!props.function) {
|
|
36
|
+
throw new Error('function is required.');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
this.association = new connect.CfnIntegrationAssociation(this, 'Resource', {
|
|
40
|
+
instanceId: props.instance.instanceId,
|
|
41
|
+
integrationArn: props.function.functionArn,
|
|
42
|
+
integrationType: 'LAMBDA_FUNCTION',
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
props.function.addPermission('AllowAmazonConnectInvoke', {
|
|
46
|
+
action: 'lambda:InvokeFunction',
|
|
47
|
+
principal: new iam.ServicePrincipal('connect.amazonaws.com'),
|
|
48
|
+
sourceArn: props.instance.instanceArn,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ArnFormat, Stack } from 'aws-cdk-lib';
|
|
2
|
+
import { Construct } from 'constructs';
|
|
3
|
+
|
|
4
|
+
export function resourceNameFromSlashArn(scope: Construct, arn: string): string {
|
|
5
|
+
return Stack.of(scope).splitArn(arn, ArnFormat.SLASH_RESOURCE_NAME).resourceName ?? arn;
|
|
6
|
+
}
|
package/src/queue.ts
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { aws_connect as connect } from 'aws-cdk-lib';
|
|
2
|
+
import { Construct } from 'constructs';
|
|
3
|
+
import { IConnectInstance } from './connect-instance';
|
|
4
|
+
import { IHoursOfOperation } from './hours-of-operation';
|
|
5
|
+
import { resourceNameFromSlashArn } from './private/arn';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Queue availability.
|
|
9
|
+
*/
|
|
10
|
+
export enum QueueStatus {
|
|
11
|
+
ENABLED = 'ENABLED',
|
|
12
|
+
DISABLED = 'DISABLED',
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A phone-number-like outbound caller identity.
|
|
17
|
+
*/
|
|
18
|
+
export interface OutboundCallerConfig {
|
|
19
|
+
/**
|
|
20
|
+
* Outbound caller ID name.
|
|
21
|
+
*
|
|
22
|
+
* @default - Amazon Connect default
|
|
23
|
+
*/
|
|
24
|
+
readonly outboundCallerIdName?: string;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Outbound caller ID phone number ARN.
|
|
28
|
+
*
|
|
29
|
+
* @default - Amazon Connect default
|
|
30
|
+
*/
|
|
31
|
+
readonly outboundCallerIdNumberArn?: string;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Outbound flow ARN.
|
|
35
|
+
*
|
|
36
|
+
* @default - Amazon Connect default
|
|
37
|
+
*/
|
|
38
|
+
readonly outboundFlowArn?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* An Amazon Connect queue reference.
|
|
43
|
+
*/
|
|
44
|
+
export interface IQueue {
|
|
45
|
+
/**
|
|
46
|
+
* The queue ARN.
|
|
47
|
+
*/
|
|
48
|
+
readonly queueArn: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Properties for Queue.
|
|
53
|
+
*/
|
|
54
|
+
export interface QueueProps {
|
|
55
|
+
/**
|
|
56
|
+
* The Amazon Connect instance that owns this queue.
|
|
57
|
+
*/
|
|
58
|
+
readonly instance: IConnectInstance;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Queue name.
|
|
62
|
+
*/
|
|
63
|
+
readonly name: string;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Hours of operation for this queue.
|
|
67
|
+
*/
|
|
68
|
+
readonly hoursOfOperation: IHoursOfOperation;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Optional description.
|
|
72
|
+
*
|
|
73
|
+
* @default - no description
|
|
74
|
+
*/
|
|
75
|
+
readonly description?: string;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Maximum contacts allowed in the queue.
|
|
79
|
+
*
|
|
80
|
+
* @default - Amazon Connect default
|
|
81
|
+
*/
|
|
82
|
+
readonly maxContacts?: number;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Outbound caller configuration.
|
|
86
|
+
*
|
|
87
|
+
* @default - Amazon Connect default
|
|
88
|
+
*/
|
|
89
|
+
readonly outboundCallerConfig?: OutboundCallerConfig;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Queue status.
|
|
93
|
+
*
|
|
94
|
+
* @default QueueStatus.ENABLED
|
|
95
|
+
*/
|
|
96
|
+
readonly status?: QueueStatus;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* L2-style wrapper for AWS::Connect::Queue.
|
|
101
|
+
*/
|
|
102
|
+
export class Queue extends Construct implements IQueue {
|
|
103
|
+
/**
|
|
104
|
+
* Import an existing Amazon Connect queue by ARN.
|
|
105
|
+
*/
|
|
106
|
+
public static fromQueueArn(scope: Construct, id: string, queueArn: string): IQueue {
|
|
107
|
+
return new ImportedQueue(scope, id, queueArn);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The underlying CloudFormation resource.
|
|
112
|
+
*/
|
|
113
|
+
public readonly resource: connect.CfnQueue;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The queue ARN.
|
|
117
|
+
*/
|
|
118
|
+
public readonly queueArn: string;
|
|
119
|
+
|
|
120
|
+
public constructor(scope: Construct, id: string, props: QueueProps) {
|
|
121
|
+
super(scope, id);
|
|
122
|
+
|
|
123
|
+
if (!props.name.trim()) {
|
|
124
|
+
throw new Error('name must not be empty.');
|
|
125
|
+
}
|
|
126
|
+
if (props.maxContacts !== undefined && props.maxContacts < 0) {
|
|
127
|
+
throw new Error('maxContacts must be greater than or equal to 0.');
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
this.resource = new connect.CfnQueue(this, 'Resource', {
|
|
131
|
+
description: props.description,
|
|
132
|
+
hoursOfOperationArn: props.hoursOfOperation.hoursOfOperationArn,
|
|
133
|
+
instanceArn: props.instance.instanceArn,
|
|
134
|
+
maxContacts: props.maxContacts,
|
|
135
|
+
name: props.name,
|
|
136
|
+
outboundCallerConfig: props.outboundCallerConfig,
|
|
137
|
+
status: props.status ?? QueueStatus.ENABLED,
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
this.queueArn = this.resource.getAtt('QueueArn').toString();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
class ImportedQueue extends Construct implements IQueue {
|
|
145
|
+
public readonly queueArn: string;
|
|
146
|
+
|
|
147
|
+
public constructor(scope: Construct, id: string, queueArn: string) {
|
|
148
|
+
super(scope, id);
|
|
149
|
+
this.queueArn = queueArn;
|
|
150
|
+
resourceNameFromSlashArn(this, queueArn);
|
|
151
|
+
}
|
|
152
|
+
}
|