├── website-creator
├── web-site-manifest.json
├── index.js
├── website-helper.js
├── css
│ └── style.css
├── gr.html
└── js
│ └── gr.js
├── CODE_OF_CONDUCT.md
├── LICENSE
├── README.md
├── CONTRIBUTING.md
└── template.yaml
/website-creator/web-site-manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "files": [
3 | "./gr.html",
4 | "./css/style.css",
5 | "./js/aws-sdk.min-dr.js",
6 | "./js/gr.js"
7 | ]
8 | }
9 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | ## Code of Conduct
2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
4 | opensource-codeofconduct@amazon.com with any additional questions or comments.
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of
4 | this software and associated documentation files (the "Software"), to deal in
5 | the Software without restriction, including without limitation the rights to
6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7 | the Software, and to permit persons to whom the Software is furnished to do so.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
11 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
12 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
13 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
14 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15 |
16 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # Amazon Connect Global Resiliency APIs demo
3 |
4 | This demo shows how you can leverage [Amazon Connect](https://aws.amazon.com/connect/) Global Resiliency APIs and manage Traffic Distribution Groups(TDG), Claim a phone number to a TDG, Percentage allocate traffic between 2 regions etc.
5 |
6 | ## Usage
7 | Use `sam` to build, invoke and deploy the function.
8 |
9 | ##### SAM Build:
10 | Ensure you are in the root folder
11 |
12 | `sam build --use-container`
13 |
14 | ##### SAM Deploy:
15 |
16 | Create a s3 bucket for hosting the CloudFormation template created by SAM and make a note of it. This will be used as value of the input parameter "--s3-bucket".
17 |
18 | Update the below command with appropriate CloudFormation stack name and valid unique s3 bucket name in the "ParameterValue".
19 |
20 | `sam deploy template.yaml --s3-bucket s3-BUCKET-NAME-FOR-CLOUDFORMATION-TEMPLATE --stack-name CLOUDFORMATION-STACK-NAME --parameter-overrides ParameterKey=parS3BucketForWebSite,ParameterValue=s3-BUCKET-NAME-FOR-WEBSITE-HOSTING --capabilities CAPABILITY_IAM`
21 |
22 |
--------------------------------------------------------------------------------
/website-creator/index.js:
--------------------------------------------------------------------------------
1 | const https = require('https');
2 | const url = require('url');
3 | const WebsiteHelper = require('./website-helper.js');
4 |
5 | exports.handler = (event, context, callback) => {
6 | console.log('Received event:', JSON.stringify(event, null, 2));
7 |
8 | let responseStatus = 'FAILED';
9 | let responseData = {};
10 |
11 | if (event.RequestType === 'Delete') {
12 | sendResponse(event, callback, context.logStreamName, 'SUCCESS');
13 | }
14 |
15 | if (event.RequestType === 'Create') {
16 | if (event.ResourceProperties.customAction === 'configureWebsite') {
17 | console.log('Starting to copy the files');
18 | let _websiteHelper = new WebsiteHelper();
19 |
20 | _websiteHelper.copyWebSiteAssets(event.ResourceProperties,
21 | function(err, data) {
22 | if (err) {
23 | responseData = {
24 | Error: 'Copy of website assets failed'
25 | };
26 | console.log([responseData.Error, ':\n', err].join(''));
27 | } else {
28 | responseStatus = 'SUCCESS';
29 | responseData = {};
30 | }
31 |
32 | sendResponse(event, callback, context.logStreamName, responseStatus, responseData);
33 | });
34 |
35 | }
36 | //sendResponse(event, callback, context.logStreamName, 'SUCCESS');
37 | }
38 |
39 |
40 | };
41 |
42 | /**
43 | * Sends a response to the pre-signed S3 URL
44 | */
45 |
46 | let sendResponse = function(event, callback, logStreamName, responseStatus, responseData) {
47 | const responseBody = JSON.stringify({
48 | Status: responseStatus,
49 | Reason: `See the details in CloudWatch Log Stream: ${logStreamName}`,
50 | PhysicalResourceId: logStreamName,
51 | StackId: event.StackId,
52 | RequestId: event.RequestId,
53 | LogicalResourceId: event.LogicalResourceId,
54 | Data: responseData,
55 | });
56 |
57 | console.log('RESPONSE BODY:\n', responseBody);
58 | const parsedUrl = url.parse(event.ResponseURL);
59 | const options = {
60 | hostname: parsedUrl.hostname,
61 | port: 443,
62 | path: parsedUrl.path,
63 | method: 'PUT',
64 | headers: {
65 | 'Content-Type': '',
66 | 'Content-Length': responseBody.length,
67 | }
68 | };
69 |
70 | const req = https.request(options, (res) => {
71 | console.log('STATUS:', res.statusCode);
72 | console.log('HEADERS:', JSON.stringify(res.headers));
73 | callback(null, 'Successfully sent stack response!');
74 | });
75 |
76 | req.on('error', (err) => {
77 | console.log('sendResponse Error:\n', err);
78 | callback(err);
79 | });
80 |
81 | req.write(responseBody);
82 | req.end();
83 | };
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing Guidelines
2 |
3 | Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional
4 | documentation, we greatly value feedback and contributions from our community.
5 |
6 | Please read through this document before submitting any issues or pull requests to ensure we have all the necessary
7 | information to effectively respond to your bug report or contribution.
8 |
9 |
10 | ## Reporting Bugs/Feature Requests
11 |
12 | We welcome you to use the GitHub issue tracker to report bugs or suggest features.
13 |
14 | When filing an issue, please check existing open, or recently closed, issues to make sure somebody else hasn't already
15 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful:
16 |
17 | * A reproducible test case or series of steps
18 | * The version of our code being used
19 | * Any modifications you've made relevant to the bug
20 | * Anything unusual about your environment or deployment
21 |
22 |
23 | ## Contributing via Pull Requests
24 | Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that:
25 |
26 | 1. You are working against the latest source on the *main* branch.
27 | 2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already.
28 | 3. You open an issue to discuss any significant work - we would hate for your time to be wasted.
29 |
30 | To send us a pull request, please:
31 |
32 | 1. Fork the repository.
33 | 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change.
34 | 3. Ensure local tests pass.
35 | 4. Commit to your fork using clear commit messages.
36 | 5. Send us a pull request, answering any default questions in the pull request interface.
37 | 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation.
38 |
39 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and
40 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/).
41 |
42 |
43 | ## Finding contributions to work on
44 | Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any 'help wanted' issues is a great place to start.
45 |
46 |
47 | ## Code of Conduct
48 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
49 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
50 | opensource-codeofconduct@amazon.com with any additional questions or comments.
51 |
52 |
53 | ## Security issue notifications
54 | If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue.
55 |
56 |
57 | ## Licensing
58 |
59 | See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution.
60 |
--------------------------------------------------------------------------------
/website-creator/website-helper.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const { S3Client, PutObjectCommand } = require("@aws-sdk/client-s3");
4 | const client = new S3Client();
5 | const fs = require('fs');
6 | const _downloadLocation = './web-site-manifest.json';
7 |
8 | /**
9 | * Helper function to interact with s3 hosted website for cfn custom resource.
10 | *
11 | * @class websiteHelper
12 | */
13 | let websiteHelper = (function() {
14 |
15 | /**
16 | * @class websiteHelper
17 | * @constructor
18 | */
19 | let websiteHelper = function() {};
20 |
21 | websiteHelper.prototype.copyWebSiteAssets = function(resourceProperties, cb) {
22 | var destS3Bucket = resourceProperties.destS3Bucket;
23 | var destS3KeyPrefix = resourceProperties.destS3KeyPrefix;
24 | var region = resourceProperties.Region;
25 |
26 | console.log("Copying UI web site");
27 | console.log(['destination bucket:', destS3Bucket].join(' '));
28 | console.log(['destination s3 key prefix:', destS3KeyPrefix].join(' '));
29 | console.log(['region:', region].join(' '));
30 |
31 | fs.readFile(_downloadLocation, 'utf8', function(err, data) {
32 | if (err) {
33 | console.log(err);
34 | return cb(err, null);
35 | }
36 |
37 | console.log(data);
38 | let _manifest = validateJSON(data);
39 |
40 | if (!_manifest) {
41 | return cb('Unable to validate downloaded manifest file JSON', null);
42 | } else {
43 | uploadToS3(_manifest.files, 0, destS3Bucket, destS3KeyPrefix,
44 | function(err, result) {
45 | if (err) {
46 | return cb(err, null);
47 | }
48 | console.log(result);
49 | return cb(null, result);
50 | });
51 | }
52 |
53 | });
54 | };
55 |
56 |
57 | /**
58 | * Helper function to validate the JSON structure of contents of an import manifest file.
59 | * @param {string} body - JSON object stringify-ed.
60 | * @returns {JSON} - The JSON parsed string or null if string parsing failed
61 | */
62 | let validateJSON = function(body) {
63 | try {
64 | let data = JSON.parse(body);
65 | console.log(data);
66 | return data;
67 | } catch (e) {
68 | // failed to parse
69 | console.log('Manifest file contains invalid JSON.');
70 | return null;
71 | }
72 | };
73 |
74 | async function uploadToS3(filelist, index, destS3Bucket, destS3KeyPrefix, cb) {
75 | console.log("Bucket : " + destS3Bucket + " key : " + destS3KeyPrefix);
76 | if (filelist.length > index) {
77 |
78 | const response = fs.readFileSync(filelist[index], 'utf8');
79 | var fileDetails = filelist[index]
80 | fileDetails = fileDetails.substring(2, fileDetails.length);
81 |
82 | let params2 = {
83 | Bucket: destS3Bucket,
84 | Key: destS3KeyPrefix + '/' + fileDetails,
85 | Body: response
86 | };
87 | if (filelist[index].endsWith('.htm') || filelist[index].endsWith('.html')) {
88 | params2.ContentType = "text/html";
89 | } else if (filelist[index].endsWith('.css')) {
90 | params2.ContentType = "text/css";
91 | } else if (filelist[index].endsWith('.js')) {
92 | params2.ContentType = "application/javascript";
93 | } else if (filelist[index].endsWith('.png')) {
94 | params2.ContentType = "image/png";
95 | } else if (filelist[index].endsWith('.jpg') || filelist[index].endsWith('.jpeg')) {
96 | params2.ContentType = "image/jpeg";
97 | } else if (filelist[index].endsWith('.pdf')) {
98 | params2.ContentType = "application/pdf";
99 | } else if (filelist[index].endsWith('.gif')) {
100 | params2.ContentType = "image/gif";
101 | } else if (filelist[index].endsWith('.svg')) {
102 | params2.ContentType = "image/svg+xml";
103 | };
104 |
105 | const putcommand = new PutObjectCommand(params2);
106 | try{
107 | const rp = await client.send(putcommand);
108 | console.log([
109 | [filelist[index]].join('/'), 'uploaded successfully'
110 | ].join(' '));
111 | let _next = index + 1;
112 | uploadToS3(filelist, _next, destS3Bucket, destS3KeyPrefix, function(err, resp) {
113 | if (err) {
114 | return cb(err, null);
115 | }
116 |
117 | cb(null, resp);
118 | });
119 |
120 | }catch(err){
121 | console.log(err);
122 | return cb(['error copying ', [filelist[index]].join('/'), '\n', err]
123 | .join(
124 | ''),
125 | null);
126 |
127 | }
128 | } else {
129 | cb(null, [index, 'files copied'].join(' '));
130 | }
131 | }
132 | return websiteHelper;
133 |
134 | })();
135 |
136 | module.exports = websiteHelper;
--------------------------------------------------------------------------------
/template.yaml:
--------------------------------------------------------------------------------
1 | AWSTemplateFormatVersion: 2010-09-09
2 | Description: >
3 | "Amazon Connect Global Resiliency APIs demo"
4 |
5 | Mappings:
6 | FunctionMap:
7 | Configuration:
8 | S3Bucket: "aws-contact-center-blog"
9 | S3Key: "ram/using-amazon-connect-global-resiliency-to-build-multi-region-resilient-contact-center/"
10 |
11 | Parameters:
12 | parS3BucketForWebSite:
13 | Type: String
14 | AllowedPattern: '(?=^.{3,63}$)(?!^(\d+\.)+\d+$)(^(([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])\.)*([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])$)'
15 | ConstraintDescription: 'Invalid S3 Bucket name'
16 | Description: Enter the (globally unique) name you would like to use for the Amazon S3 bucket where we will store the website assets. This template will fail to deploy if the bucket name you chose is currently in use.
17 |
18 | Metadata:
19 | 'AWS::CloudFormation::Interface':
20 | ParameterGroups:
21 | - Label:
22 | default: Amazon S3 Configuration
23 | Parameters:
24 | - parS3BucketForWebSite
25 |
26 | ParameterLabels:
27 | parS3BucketForWebSite:
28 | default: Website Bucket Name
29 |
30 | Outputs:
31 |
32 | CloudfrontEndpoint:
33 | Description: Endpoint for Cloudfront distribution
34 | Value: !Join
35 | - ''
36 | - - 'https://'
37 | - !GetAtt [RPCloudFrontDistribution, DomainName]
38 | - '/gr.html'
39 |
40 |
41 | Resources:
42 | createWebSiteS3Bucket:
43 | Type: 'AWS::S3::Bucket'
44 | Properties:
45 | BucketName: !Ref parS3BucketForWebSite
46 | VersioningConfiguration:
47 | Status : Enabled
48 | BucketEncryption:
49 | ServerSideEncryptionConfiguration:
50 | - ServerSideEncryptionByDefault:
51 | SSEAlgorithm: AES256
52 | PublicAccessBlockConfiguration:
53 | BlockPublicAcls: True
54 | BlockPublicPolicy: True
55 | IgnorePublicAcls: True
56 | RestrictPublicBuckets: True
57 | WebsiteConfiguration:
58 | IndexDocument: mrr.html
59 | ErrorDocument: error.html
60 | OwnershipControls:
61 | Rules:
62 | - ObjectOwnership: ObjectWriter
63 |
64 |
65 | RPs3BucketPolicy:
66 | Type: AWS::S3::BucketPolicy
67 | DependsOn:
68 | - RPCloudFrontDistributionAccessIdentity
69 | Properties:
70 | Bucket: !Ref createWebSiteS3Bucket
71 | PolicyDocument:
72 | Statement:
73 | -
74 | Action:
75 | - "s3:GetObject"
76 | Effect: "Allow"
77 | Principal:
78 | CanonicalUser:
79 | Fn::GetAtt: [ RPCloudFrontDistributionAccessIdentity , S3CanonicalUserId ]
80 | Resource:
81 | !Sub ${createWebSiteS3Bucket.Arn}/CCP/*
82 |
83 | RPCloudFrontDistributionAccessIdentity:
84 | Type: AWS::CloudFront::CloudFrontOriginAccessIdentity
85 | Properties:
86 | CloudFrontOriginAccessIdentityConfig:
87 | Comment: 'CloudFront endpoint for Global Resiliency blog'
88 |
89 | RPCloudFrontDistribution:
90 | Type: AWS::CloudFront::Distribution
91 | Properties:
92 | DistributionConfig:
93 | Origins:
94 | - DomainName:
95 | !Join
96 | - ''
97 | - - !Ref parS3BucketForWebSite
98 | - .s3.amazonaws.com
99 | Id: !Ref parS3BucketForWebSite
100 | OriginPath: '/CCP'
101 | S3OriginConfig:
102 | OriginAccessIdentity:
103 | !Join
104 | - ''
105 | - - 'origin-access-identity/cloudfront/'
106 | - !Ref RPCloudFrontDistributionAccessIdentity
107 | Enabled: 'true'
108 | Logging:
109 | Bucket: !GetAtt createWebSiteS3Bucket.DomainName
110 | Prefix: 'logs/'
111 | IncludeCookies: 'true'
112 | Comment: CloudFront for Global Resiliency API Demo
113 | DefaultRootObject: gr.html
114 | DefaultCacheBehavior:
115 | AllowedMethods:
116 | - DELETE
117 | - GET
118 | - HEAD
119 | - OPTIONS
120 | - PATCH
121 | - POST
122 | - PUT
123 | TargetOriginId: !Ref parS3BucketForWebSite
124 | ForwardedValues:
125 | QueryString: true
126 | Cookies:
127 | Forward: all
128 | ViewerProtocolPolicy: redirect-to-https
129 | Restrictions:
130 | GeoRestriction:
131 | RestrictionType: whitelist
132 | Locations:
133 | - US
134 |
135 | RPWebSiteContentLambdaRole:
136 | Type: "AWS::IAM::Role"
137 | Properties:
138 | AssumeRolePolicyDocument:
139 | Version: "2012-10-17"
140 | Statement:
141 | -
142 | Effect: "Allow"
143 | Principal:
144 | Service:
145 | - "lambda.amazonaws.com"
146 | Action:
147 | - "sts:AssumeRole"
148 | Path: "/"
149 | Policies:
150 | -
151 | PolicyName: !Sub ${AWS::StackName}-website-creator-policy
152 | PolicyDocument:
153 | Version: "2012-10-17"
154 | Statement:
155 | -
156 | Effect: "Allow"
157 | Action:
158 | - 'logs:CreateLogGroup'
159 | - 'logs:CreateLogStream'
160 | - 'logs:PutLogEvents'
161 | Resource:
162 | - !Sub "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/*"
163 | -
164 | Effect: "Allow"
165 | Action:
166 | - "s3:PutObject"
167 | - "s3:GetObject"
168 | - "s3:PutObjectAcl"
169 | Resource:
170 | - !Join
171 | - ''
172 | - - 'arn:'
173 | - !Ref 'AWS::Partition'
174 | - ':s3:::'
175 | - !Ref parS3BucketForWebSite
176 | - '/*'
177 | -
178 | Effect: "Allow"
179 | Action:
180 | - "s3:PutBucketPublicAccessBlock"
181 | Resource:
182 | - !Join
183 | - ''
184 | - - 'arn:'
185 | - !Ref 'AWS::Partition'
186 | - ':s3:::'
187 | - !Ref parS3BucketForWebSite
188 | -
189 | Effect: "Allow"
190 | Action:
191 | - "s3:GetObject"
192 | Resource:
193 | - !Join
194 | - ''
195 | - - 'arn:'
196 | - !Ref 'AWS::Partition'
197 | - ':s3:::'
198 | - 'amazon-connect-blogs2'
199 | - '/*'
200 |
201 | webSiteCreator:
202 | Type: "AWS::Lambda::Function"
203 | Properties:
204 | Description: >
205 | AWS Lambda Function that will create the website and upload it to the S3 bucket
206 | Handler: "index.handler"
207 | Role: !GetAtt RPWebSiteContentLambdaRole.Arn
208 | Runtime: "nodejs20.x"
209 | MemorySize: 256
210 | Timeout: 120
211 | Code: ./website-creator
212 |
213 | invokeWebSiteCreator:
214 | Type: Custom::CreateWebSite
215 | DependsOn: createWebSiteS3Bucket
216 | Properties:
217 | ServiceToken: !GetAtt webSiteCreator.Arn
218 | customAction: configureWebsite
219 | Region: !Ref AWS::Region
220 | destS3Bucket: !Ref parS3BucketForWebSite
221 | destS3KeyPrefix: CCP
222 |
--------------------------------------------------------------------------------
/website-creator/css/style.css:
--------------------------------------------------------------------------------
1 | html,
2 | body {
3 | border: 0;
4 | margin: 0;
5 | padding: 0;
6 | }
7 |
8 | body {
9 | font: 100% "Lucida Grande", "Lucida Sans Unicode", Arial, sans-serif;
10 | min-width: 100%;
11 | min-height: 101%;
12 | color: #666;
13 | background: #eee;
14 | }
15 |
16 | p,
17 | label,
18 | legend {
19 | font: 1em "Lucida Grande", "Lucida Sans Unicode", Arial, sans-serif;
20 | }
21 |
22 | h1 {
23 | margin: 10px 0 10px;
24 | font-size: 20px;
25 | color: #333333;
26 | }
27 |
28 | hr {
29 | color: inherit;
30 | height: 0;
31 | margin: 6px 0 6px 0;
32 | padding: 0;
33 | border: 1px solid #d9d9d9;
34 | border-style: none none solid;
35 | }
36 |
37 | section {
38 | display: block;
39 | width: 800px;
40 | margin: 10px auto;
41 | padding: 35px;
42 | border: 1px solid #cbcbcb;
43 | background-color: #FFF;
44 | -webkit-border-radius: 5px;
45 | -moz-border-radius: 5px;
46 | border-radius: 5px;
47 | box-shadow: 0 2px 5px rgba(50, 50, 50, 0.1);
48 | -webkit-box-shadow: 0 2px 5px rgba(50, 50, 50, 0.1);
49 | -moz-box-shadow: 0 2px 5px rgba(50, 50, 50, 0.1);
50 | }
51 |
52 |
53 | /* Special CSS for Call Controls Section */
54 |
55 | fieldset.salesOrder {
56 | padding: 7px;
57 | }
58 |
59 | fieldset.callControls {
60 | padding: 3px;
61 | margin: 4px;
62 | -webkit-transition: margin-left 1s ease-in-out;
63 | z-index: 1;
64 | }
65 |
66 | .callControls {
67 | margin: 2px 2px;
68 | display: inline-block;
69 | border: 1px solid #bfbfbf;
70 | border-radius: 5px 5px 5px 5px;
71 | -webkit-border-radius: 5px 5px 5px 5px;
72 | -moz-border-radius: 5px 5px 5px 5px;
73 | font: 1em "Lucida Grande", "Lucida Sans Unicode", Arial, sans-serif;
74 | width: auto;
75 | height: auto;
76 | font-size: 16px;
77 | box-shadow: inset 0 1px 0 0 #fff, inset 0 -1px 0 0 #d9d9d9, inset 0 0 0 1px #f2f2f2, 0 2px 4px 0 #f2f2f2;
78 | -moz-box-shadow: inset 0 1px 0 0 #fff, inset 0 -1px 0 0 #d9d9d9, inset 0 0 0 1px #f2f2f2, 0 2px 4px 0 #f2f2f2;
79 | -webkit-box-shadow: inset 0 1px 0 0 #fff, inset 0 -1px 0 0 #d9d9d9, inset 0 0 0 1px #f2f2f2, 0 2px 4px 0 #f2f2f2;
80 | text-shadow: 0 1px 0 #fff;
81 | background-image: linear-gradient(to top, #f2f2f2, #f2f2f2);
82 | background-color: #f2f2f2;
83 | }
84 |
85 | .callControls:hover,
86 | .callControls:active {
87 | border: 1px solid #8c8c8c;
88 | color: #8c8c8c;
89 | box-shadow: inset 0 1px 0 0 #ffffff, inset 0 -1px 0 0 #d9d9d9, inset 0 0 0 1px #f2f2f2;
90 | -moz-box-shadow: inset 0 1px 0 0 #ffffff, inset 0 -1px 0 0 #d9d9d9, inset 0 0 0 1px #f2f2f2;
91 | -webkit-box-shadow: inset 0 1px 0 0 #ffffff, inset 0 -1px 0 0 #d9d9d9, inset 0 0 0 1px #f2f2f2;
92 | background-color: #f2f2f2;
93 | }
94 |
95 |
96 | /* Form style */
97 |
98 | mark.validate {
99 | display: inline-block;
100 | margin: 12px 0 0 10px;
101 | width: 16px;
102 | height: 16px;
103 | background: transparent none;
104 | }
105 |
106 | mark.valid {
107 | background: url(images/success.gif) no-repeat top left;
108 | }
109 |
110 | mark.error {
111 | background: url(images/error.gif) no-repeat top left;
112 | }
113 |
114 | form label,
115 | section label {
116 | display: inline-block;
117 | float: left;
118 | height: 1em;
119 | line-height: 1em;
120 | padding: 6px 0 0;
121 | width: 135px;
122 | font-size: 1em;
123 | margin: 5px 0;
124 | clear: both;
125 | }
126 |
127 | form label small,
128 | section label small {
129 | font-size: 0.75em;
130 | color: #ccc;
131 | }
132 |
133 | form label.verify {
134 | padding: 0;
135 | margin: 2px 10px 2px 0;
136 | width: 145px;
137 | text-align: right;
138 | }
139 |
140 | form label.verify img {
141 | padding: 1px;
142 | border: 1px solid #cccccc;
143 | -webkit-border-radius: 3px;
144 | -moz-border-radius: 3px;
145 | border-radius: 3px;
146 | }
147 |
148 | form button {
149 | width: 120px;
150 | padding: 4px;
151 | color: #666;
152 | background: #f5f5f5;
153 | border: 1px solid #ccc;
154 | margin: 5px 0;
155 | font: 1em "Lucida Grande", "Lucida Sans Unicode", Arial, sans-serif;
156 | -webkit-border-radius: 5px;
157 | -moz-border-radius: 5px;
158 | border-radius: 5px;
159 | vertical-align: top;
160 | transition: all 0.25s ease-in-out;
161 | -webkit-transition: all 0.25s ease-in-out;
162 | -moz-transition: all 0.25s ease-in-out;
163 | box-shadow: 0 0 5px rgba(81, 203, 238, 0);
164 | -webkit-box-shadow: 0 0 5px rgba(81, 203, 238, 0);
165 | -moz-box-shadow: 0 0 5px rgba(81, 203, 238, 0);
166 | }
167 |
168 | form input,
169 | form textarea,
170 | form select,
171 | section select,
172 | section input,
173 | section textarea {
174 | width: 220px;
175 | padding: 5px;
176 | color: #666;
177 | background: #f5f5f5;
178 | border: 1px solid #ccc;
179 | margin: 5px 0;
180 | font: 1em "Lucida Grande", "Lucida Sans Unicode", Arial, sans-serif;
181 | -webkit-border-radius: 5px;
182 | -moz-border-radius: 5px;
183 | border-radius: 5px;
184 | vertical-align: top;
185 | transition: all 0.25s ease-in-out;
186 | -webkit-transition: all 0.25s ease-in-out;
187 | -moz-transition: all 0.25s ease-in-out;
188 | box-shadow: 0 0 5px rgba(81, 203, 238, 0);
189 | -webkit-box-shadow: 0 0 5px rgba(81, 203, 238, 0);
190 | -moz-box-shadow: 0 0 5px rgba(81, 203, 238, 0);
191 | }
192 |
193 | form select {
194 | width: 232px;
195 | margin: 8px 0;
196 | }
197 |
198 | form input#verify {
199 | width: 55px;
200 | }
201 |
202 | form textarea,
203 | section textarea {
204 | width: 414px;
205 | }
206 |
207 | form input:focus,
208 | form textarea:focus,
209 | form select:focus,
210 | form button:focus,
211 | section input:focus,
212 | section textarea:focus,
213 | section select:focus {
214 | border: 1px solid #ddd;
215 | background-color: #fff;
216 | color: #333;
217 | outline: none;
218 | position: relative;
219 | z-index: 5;
220 | box-shadow: 0 0 5px rgba(81, 203, 238, 1);
221 | -webkit-box-shadow: 0 0 5px rgba(81, 203, 238, 1);
222 | -moz-box-shadow: 0 0 5px rgba(81, 203, 238, 1);
223 | -webkit-transform: scale(1.05);
224 | -moz-transform: scale(1.05);
225 | transition: all 0.25s ease-in-out;
226 | -webkit-transition: all 0.25s ease-in-out;
227 | -moz-transition: all 0.25s ease-in-out;
228 | }
229 |
230 | form input.error,
231 | form textarea.error,
232 | form select.error {
233 | box-shadow: 0 0 5px rgba(204, 0, 0, 0.5);
234 | -webkit-box-shadow: 0 0 5px rgba(204, 0, 0, 0.5);
235 | -moz-box-shadow: 0 0 5px rgba(204, 0, 0, 0.5);
236 | border: 1px solid #faabab;
237 | background: #fef3f3
238 | }
239 |
240 | form input.submit {
241 | width: auto;
242 | cursor: pointer;
243 | position: relative;
244 | border: 1px solid #282828;
245 | color: #fff;
246 | padding: 6px 16px;
247 | text-decoration: none;
248 | font-size: 1.1em;
249 | background: #555;
250 | background: -webkit-gradient( linear, left bottom, left top, color-stop(0.12, rgb(60, 60, 60)), color-stop(1, rgb(85, 85, 85)));
251 | background: -moz-linear-gradient( center bottom, rgb(60, 60, 60) 12%, rgb(85, 85, 85) 100%);
252 | box-shadow: 0 2px 3px rgba(0, 0, 0, 0.25);
253 | -moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
254 | -webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
255 | text-shadow: 0 -1px 1px rgba(0, 0, 0, 0.25);
256 | }
257 |
258 | form input.submit:hover {
259 | background: #282828 !important;
260 | transition: none;
261 | -webkit-transition: none;
262 | -moz-transition: none;
263 | }
264 |
265 | form input.submit:active,
266 | form input.submit:focus {
267 | top: 1px;
268 | }
269 |
270 | form button.delete-comment {
271 | width: auto;
272 | cursor: pointer;
273 | position: relative;
274 | border: 1px solid #282828;
275 | color: #fff;
276 | border-radius: 5px;
277 | padding: 6px 16px;
278 | text-decoration: none;
279 | font-size: 1.1em;
280 | background: #555;
281 | background: -webkit-gradient( linear, left bottom, left top, color-stop(0.12, rgb(60, 60, 60)), color-stop(1, rgb(85, 85, 85)));
282 | background: -moz-linear-gradient( center bottom, rgb(60, 60, 60) 12%, rgb(85, 85, 85) 100%);
283 | box-shadow: 0 2px 3px rgba(0, 0, 0, 0.25);
284 | -moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
285 | -webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
286 | text-shadow: 0 -1px 1px rgba(0, 0, 0, 0.25);
287 | }
288 |
289 | .copy {
290 | width: 30px;
291 | height: 29px;
292 | padding: 5px;
293 | color: #666;
294 | background: #f5f5f5;
295 | border: 1px solid #ccc;
296 | margin: 5px 0;
297 | }
298 |
299 | form button.delete-comment:hover {
300 | background: #282828 !important;
301 | transition: none;
302 | -webkit-transition: none;
303 | -moz-transition: none;
304 | }
305 |
306 | form button.delete-comment:active,
307 | form button.delet-comment:focus {
308 | top: 1px;
309 | }
310 |
311 | form button:hover {
312 | background: #eeeeee;
313 | transition: none;
314 | -webkit-transition: none;
315 | -moz-transition: none;
316 | }
317 |
318 | form input[type="submit"][disabled] {
319 | background: #888;
320 | }
321 |
322 | form fieldset {
323 | padding: 7px;
324 | border: 1px solid #eee;
325 | -webkit-border-radius: 5px;
326 | -moz-border-radius: 5px;
327 | margin: 0 0 20px;
328 | }
329 |
330 | form legend {
331 | padding: 7px 10px;
332 | font-weight: bold;
333 | color: #000;
334 | border: 1px solid #eee;
335 | -webkit-border-radius: 5px;
336 | -moz-border-radius: 5px;
337 | margin-bottom: 0 !important;
338 | margin-bottom: 20px;
339 | }
340 |
341 | form span.required {
342 | font-size: 13px;
343 | color: #ff0000;
344 | }
345 |
346 | section span.required {
347 | font-size: 13px;
348 | color: #ff0000;
349 | }
350 |
351 | fieldset {
352 | padding: 20px;
353 | border: 1px solid #eee;
354 | -webkit-border-radius: 5px;
355 | -moz-border-radius: 5px;
356 | margin: 0 0 20px;
357 | }
358 |
359 | legend {
360 | padding: 7px 10px;
361 | font-weight: bold;
362 | color: #000;
363 | border: 1px solid #eee;
364 | -webkit-border-radius: 5px;
365 | -moz-border-radius: 5px;
366 | margin-bottom: 0 !important;
367 | margin-bottom: 20px;
368 | }
369 |
370 | #message {
371 | margin: 1em 0;
372 | padding: 0;
373 | display: block;
374 | background: transparent none;
375 | }
376 |
377 | acronym {
378 | border-bottom: 1px dotted #ccc;
379 | }
--------------------------------------------------------------------------------
/website-creator/gr.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Amazon Connect - Instance API's
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
141 |
148 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 | Waiting for server to respond
164 |
165 |
166 |
167 |
168 |
169 |
170 |
191 |
192 |
193 |
194 |
221 |
222 |
223 |
224 |
245 |
246 |
247 |
248 |
277 |
278 |
279 |
280 |
362 |
363 |
364 |
365 |
388 |
389 |
390 |
391 |
439 |
440 |
441 | Are you sure you want to delete?
442 |
443 |
444 |
445 |
--------------------------------------------------------------------------------
/website-creator/js/gr.js:
--------------------------------------------------------------------------------
1 |
2 | var credentials;
3 | var secretKey;
4 | var accessKey;
5 | var sessionId;
6 | var connect;
7 | var selectedId, selectedTDGName;
8 | var selectedPhoneId, selectedPhoneNumber;
9 | var tdgList, phoneList;
10 | var dlgSourceAccessKey, dlgSourceSecretKey, dlgSourceRegion, dlgInstanceId;
11 | const GCREATE = 'CREATE';
12 | const GMODIFY = 'MODIFY';
13 | const GVOICE = 'VOICE';
14 | const GCHAT = 'CHAT';
15 | const GSTANDARD = 'STANDARD';
16 | var GDELETE ='';
17 | const DELETEINSTANCE = 'INSTANCE';
18 | const DELETETDG = 'TDG';
19 |
20 | // allowed will be CREATE and MODIFY
21 | var currentOperation = GCREATE;
22 |
23 | $( document ).ready(function() {
24 | /*if (!checkCookie()) {
25 | setAWSConfig(dlgSourceAccessKey, dlgSourceSecretKey, dlgSourceRegion);
26 | setupAll();
27 | } else {
28 | setupAll();
29 | $( "#configDialog" ).dialog( "open" );
30 | }*/
31 | setupAll();
32 | $( "#configDialog" ).dialog( "open" );
33 |
34 | });
35 |
36 | function setupAll() {
37 | //loadConnectAPIs();
38 |
39 |
40 | $("#listTDG").click(() => {
41 | getListTrafficDistributionGroups();
42 | });
43 |
44 | $("#listPhoneNumbers").click(() => {
45 | getAllPhoneNumbers();
46 | });
47 |
48 | $("#listPhoneNumbersTDG").click(() => {
49 | getAllPhoneNumbersByTDG();
50 | });
51 |
52 | $("#claimPhoneNumber").click(() => {
53 | $( "#phClaimDialog" ).dialog( "open" );
54 | $('#sltPhoneNumbersToClaim').empty();
55 | });
56 |
57 | $("#describePhoneNumber").click(() => {
58 | getPhoneNumberInfo(selectedPhoneId);
59 | });
60 |
61 | $("#btnSearchAvailableNumber").click(() => {
62 | getClaimablePhoneNumbers();
63 | });
64 |
65 | $("#btnClaim").click(() => {
66 | claimableThePhoneNumber();
67 | });
68 |
69 | $("#btnClaimAndAssociate").click(() => {
70 | claimablePhoneNumberAndAssociate();
71 | });
72 |
73 | $("#releasePhoneNumber").click(() => {
74 | releaseSelectedPhoneNumber();
75 | });
76 |
77 | $("#createTDG").click(() => {
78 | currentOperation=GCREATE;
79 | clear_form_elements('#frmTDGCreate');
80 | $( "#dlgTDG" ).dialog( "open" );
81 | });
82 |
83 | $("#btnCreateTDG").click(() => {
84 | createTDG();
85 | $( "#dlgTDG" ).dialog( "close" );
86 | });
87 |
88 | $("#replicateInstance").click(() => {
89 | clear_form_elements('#frmReplica');
90 | $( "#dlgInstanceReplica" ).dialog( "open" );
91 | });
92 |
93 | $("#btnCreateInstanceReplica").click(() => {
94 | createReplicateInstance();
95 | });
96 |
97 | $("#describeTDG").click(() => {
98 | describeTDG(selectedId);
99 | });
100 |
101 | $("#getTDG").click(() => {
102 | clear_form_elements('#frmTDGModify');
103 | $( "#dlgTDGModify" ).dialog( "open" );
104 | getTDG(selectedId);
105 | });
106 |
107 | $("#btnModifyTDG").click(() => {
108 | modifyTDG();
109 | });
110 |
111 |
112 | $("#btnRename").click(() => {
113 | renameQC(selectedId);
114 | });
115 |
116 |
117 | $("#deleteTDG").click(() => {
118 | GDELETE = DELETETDG;
119 | $( "#confirmDialog" ).dialog( "open" );
120 | });
121 |
122 | $("#deleteInstance").click(() => {
123 | GDELETE = DELETEINSTANCE;
124 | $( "#confirmDialog" ).dialog( "open" );
125 | });
126 |
127 |
128 | $("#updatePhoneNumber").click(() => {
129 | $("#txtInstanceARN").val(dlgInstanceId);
130 | $( "#dlgUpdatePhoneNumber" ).dialog( "open" );
131 | });
132 |
133 | $("#btnUpdatePhoneNumber2Instance").click(() => {
134 | updatePhoneNumberDetails(1);
135 | });
136 |
137 | $("#btnUpdatePhoneNumber2TDG").click(() => {
138 | updatePhoneNumberDetails(2);
139 | });
140 |
141 | $("#dlgUpdatePhoneNumber").dialog({
142 | autoOpen: false,
143 | width: 800,
144 | modal: true,
145 | resizable: false,
146 | height: "auto"
147 |
148 | });
149 |
150 | $("#phAssociateCFDialog").dialog({
151 | autoOpen: false,
152 | width: 400,
153 | modal: true,
154 | resizable: false,
155 | height: "auto"
156 |
157 | });
158 |
159 | $("#associatePhoneNumberContactFlow").click(() => {
160 | $( "#phAssociateCFDialog" ).dialog( "open" );
161 | });
162 |
163 | $("#btnAssociateCF").click(() => {
164 | associateContactFlowForNumber();
165 | });
166 |
167 | $("#disAssociatePhoneNumberContactFlow").click(() => {
168 | disAssociatePhoneNumberContactFlow();
169 | });
170 |
171 |
172 | $("#awsConfiguration").click(() => {
173 | $( "#configDialog" ).dialog( "open" );
174 | });
175 |
176 | $("#btnPrefillConfiguration").click(() => {
177 | btnPrefillConfiguration();
178 | });
179 |
180 |
181 | $("#btnConfiguration").click(() => {
182 | if (saveCookie()) {
183 | //setupAll();
184 | loadConnectAPIs();
185 | $( "#configDialog" ).dialog( "close" );
186 | } else {
187 | $( "#configDialog" ).dialog( "open" );
188 | }
189 | });
190 |
191 | $("#dialog").dialog({
192 | autoOpen: false,
193 | modal: true
194 | });
195 |
196 | $("#dlgTDG").dialog({
197 | autoOpen: false,
198 | width: 800,
199 | modal: true,
200 | resizable: false,
201 | height: "auto"
202 |
203 | });
204 |
205 | $("#phClaimDialog").dialog({
206 | autoOpen: false,
207 | width: 800,
208 | modal: true,
209 | resizable: false,
210 | height: "auto"
211 |
212 | });
213 |
214 |
215 | $("#dlgTDGModify").dialog({
216 | autoOpen: false,
217 | width: 800,
218 | modal: true,
219 | resizable: false,
220 | height: "auto"
221 |
222 | });
223 |
224 |
225 | $("#dlgInstanceReplica").dialog({
226 | autoOpen: false,
227 | width: 800,
228 | modal: true,
229 | resizable: false,
230 | height: "auto"
231 |
232 | });
233 |
234 | $("#resultDialog").dialog({
235 | autoOpen: false,
236 | modal: true
237 | });
238 |
239 |
240 | $('#configDialog').dialog({
241 | autoOpen: false,
242 | width: 850,
243 | modal: true,
244 | resizable: false,
245 | height: "auto"
246 | });
247 |
248 |
249 | $( "#confirmDialog" ).dialog({
250 | autoOpen: false,
251 | resizable: false,
252 | height: "auto",
253 | width: 400,
254 | modal: true,
255 | buttons: {
256 | "Yes": function() {
257 | $( this ).dialog( "close" );
258 | if(GDELETE === DELETETDG) {
259 | deleteTDG(selectedId);
260 | } else {
261 | deleteInstance(dlgInstanceId);
262 | }
263 | },
264 | Cancel: function() {
265 | $( this ).dialog( "close" );
266 | }
267 | }
268 | });
269 |
270 | qcListTable = $('#qcListTable').DataTable({
271 | columnDefs: [
272 | {
273 | targets: -1,
274 | className: 'dt-body-right'
275 | }
276 | ],
277 | columns: [{title: "Name"},{title: "Status"}],
278 | select: true,
279 | paging: false,
280 | info: false,
281 | searching: false
282 | });
283 |
284 | qcListTable.on( 'select', function ( e, dt, type, indexes ) {
285 | if ( type === 'row' ) {
286 | selectedTDGName = qcListTable.rows( indexes ).data()[0][0];
287 | $('#selectedTDG').val(selectedTDGName);
288 | for (var i=0; i< tdgList.TrafficDistributionGroupSummaryList.length; i++) {
289 | if (selectedTDGName === tdgList.TrafficDistributionGroupSummaryList[i].Name) {
290 | selectedId = tdgList.TrafficDistributionGroupSummaryList[i].Arn;
291 | break;
292 | }
293 | }
294 | }
295 | });
296 |
297 | phListTable = $('#phListTable').DataTable({
298 | columnDefs: [
299 | {
300 | targets: -1,
301 | className: 'dt-body-right'
302 | }
303 | ],
304 | columns: [{title: "Phone Number"},{title: "Type"}, {title: "Country"}],
305 | select: true,
306 | paging: false,
307 | info: false,
308 | searching: false
309 | });
310 |
311 | phListTable.on( 'select', function ( e, dt, type, indexes ) {
312 | if ( type === 'row' ) {
313 | selectedPhoneNumber = phListTable.rows( indexes ).data()[0][0];
314 | $('#selectedPhoneNumber').val(selectedPhoneNumber);
315 | for (var i=0; i< phoneList.ListPhoneNumbersSummaryList.length; i++) {
316 | if (selectedPhoneNumber === phoneList.ListPhoneNumbersSummaryList[i].PhoneNumber) {
317 | selectedPhoneId = phoneList.ListPhoneNumbersSummaryList[i].PhoneNumberArn;
318 | break;
319 | }
320 | }
321 | }
322 | });
323 | //getAllPhoneNumbers();
324 | //getListTrafficDistributionGroups();
325 | }
326 |
327 | async function updatePhoneNumberDetails(option) {
328 | try {
329 | handleWindow(true, '');
330 | var sa;
331 | if(option === 1) {
332 | sa = await updatePhoneNumber (selectedPhoneId, dlgInstanceId);
333 | } else {
334 | sa = await updatePhoneNumber (selectedPhoneId, $('#sltTDGs').val());
335 | }
336 | console.log(sa);
337 | handleWindow(false, '');
338 | showResults("Successfully updated phone number");
339 | getAllPhoneNumbers();
340 | } catch(e) {
341 | console.log(e);
342 | handleWindow(false, '');
343 | showResults(e);
344 | }
345 |
346 | }
347 |
348 | async function disAssociatePhoneNumberContactFlow() {
349 | try {
350 | handleWindow(true, '');
351 | let sa = await disassociatePhoneNumberContactFlow (selectedPhoneId, dlgInstanceId);
352 | console.log(sa);
353 | handleWindow(false, '');
354 | showResults("Successfully disassociated flow from the selected number");
355 | } catch(e) {
356 | console.log(e);
357 | handleWindow(false, '');
358 | showResults(e);
359 | }
360 |
361 | }
362 |
363 | async function associateContactFlowForNumber() {
364 | try {
365 | handleWindow(true, '');
366 | var contactFlowId = $('#sltContactFlowToAssociate').val();
367 | let sa = await associatePhoneNumberContactFlow(selectedPhoneId, dlgInstanceId, contactFlowId);
368 | console.log(sa);
369 | $( "#phAssociateCFDialog" ).dialog( "close" );
370 | handleWindow(false, '');
371 | showResults("Successfully associated flow to the selected number");
372 |
373 | } catch(e) {
374 | console.log(e);
375 | handleWindow(false, '');
376 | showResults(e);
377 | }
378 |
379 | }
380 | async function releaseSelectedPhoneNumber() {
381 | try {
382 | handleWindow(true, '');
383 | var resp = await releasePhoneNumber(selectedPhoneId);
384 | console.log(resp);
385 | getAllPhoneNumbers();
386 | handleWindow(false, '');
387 | showResults("Successfully released the selected number from your instance");
388 |
389 | } catch(e) {
390 | console.log(e);
391 | handleWindow(false, '');
392 | showResults(e);
393 | }
394 |
395 | }
396 |
397 | async function claimablePhoneNumberAndAssociate() {
398 | try {
399 | handleWindow(true, '');
400 | var phoneNumber = $('#sltPhoneNumbersToClaim').val();
401 | var phoneNumberDescription = $('#txtDescription').val();
402 | var contactFlowId = $('#sltContactFlowToAssociate').val();
403 | var resp = await claimPhoneNumber(dlgInstanceId, phoneNumber, phoneNumberDescription);
404 | console.log(resp);
405 | resp = associatePhoneNumberContactFlow(resp.PhoneNumberId, dlgInstanceId, contactFlowId);
406 | getAllPhoneNumbers();
407 | handleWindow(false, '');
408 | $( "#phClaimDialog" ).dialog( "close" );
409 | } catch(e) {
410 | console.log(e);
411 | handleWindow(false, '');
412 | showResults(e);
413 | }
414 |
415 | }
416 |
417 | async function claimableThePhoneNumber() {
418 | try {
419 | handleWindow(true, '');
420 | var phoneNumber = $('#sltPhoneNumbersToClaim').val();
421 | var phoneNumberDescription = $('#txtDescription').val();
422 | var resp, tdg;
423 | tdg = $('#sltTDG').val();
424 | if(tdg != '-') {
425 | resp = await claimPhoneNumber(tdg, phoneNumber, phoneNumberDescription);
426 |
427 | } else {
428 | resp = await claimPhoneNumber(dlgInstanceId, phoneNumber, phoneNumberDescription);
429 |
430 | }
431 | console.log(resp);
432 | getAllPhoneNumbers();
433 | handleWindow(false, '');
434 | $( "#phClaimDialog" ).dialog( "close" );
435 |
436 | } catch(e) {
437 | console.log(e);
438 | handleWindow(false, '');
439 | showResults(e);
440 | }
441 |
442 | }
443 |
444 | async function getClaimablePhoneNumbers() {
445 | try {
446 | handleWindow(true, '');
447 | var phoneNumberCountryCode = $('#sltCountry').val();
448 | var phoneNumberType = $('#sltPhoneNumberType').val();
449 | let sa = await searchAvailablePhoneNumbers(dlgInstanceId, phoneNumberCountryCode, phoneNumberType, null, 10, null);
450 | console.log(sa);
451 | formatJSON(sa, '#rpFormatted');
452 | $('#sltPhoneNumbersToClaim').empty();
453 | for(var i=0; i < sa.AvailableNumbersList.length; i++){
454 | var j = sa.AvailableNumbersList[i];
455 | $('#sltPhoneNumbersToClaim').append('');
456 | }
457 |
458 | handleWindow(false, '');
459 | } catch(e) {
460 | console.log(e);
461 | handleWindow(false, '');
462 | showResults(e);
463 | }
464 |
465 | }
466 |
467 | async function getPhoneNumberInfo(phId) {
468 | try {
469 | handleWindow(true, '');
470 | var ph = await describePhoneNumber(phId);
471 | console.log(ph);
472 | formatJSON(ph, '#rpFormatted');
473 | handleWindow(false, '');
474 | } catch(e) {
475 | console.log(e);
476 | handleWindow(false, '');
477 | showResults(e);
478 | }
479 |
480 | }
481 |
482 | async function getAllPhoneNumbersByTDG() {
483 | try {
484 | handleWindow(true, '');
485 | var phCountryCode = ["US", "AU", "FR"];
486 | var phNumberTypes = ["TOLL_FREE", "DID"];
487 |
488 | phoneList = await listPhoneNumbersV2(selectedId, 1000, null, phCountryCode, phNumberTypes, null);
489 | console.log(phoneList);
490 | formatJSON(phoneList, '#rpFormatted');
491 | phListTable.clear();
492 | for (var i=0; i< phoneList.ListPhoneNumbersSummaryList.length; i++) {
493 | var value = phoneList.ListPhoneNumbersSummaryList[i];
494 | phListTable.row.add([value.PhoneNumber, value.PhoneNumberType, value.PhoneNumberCountryCode ]);
495 | }
496 | phListTable.draw();
497 |
498 | var cfList = await listContactFlows(dlgInstanceId);
499 | console.log(cfList);
500 |
501 | $('#sltContactFlowToAssociate').empty();
502 | for(var i=0; i < cfList.ContactFlowSummaryList.length; i++){
503 | var j = cfList.ContactFlowSummaryList[i];
504 | if(j.ContactFlowType === "CONTACT_FLOW") {
505 | $('#sltContactFlowToAssociate').append('');
506 | }
507 | }
508 |
509 | handleWindow(false, '');
510 | } catch(e) {
511 | console.log(e);
512 | handleWindow(false, '');
513 | showResults(e);
514 | }
515 |
516 | }
517 |
518 | async function getAllPhoneNumbers() {
519 | try {
520 | handleWindow(true, '');
521 | var phCountryCode = ["US", "AU", "FR"];
522 | var phNumberTypes = ["TOLL_FREE", "DID"];
523 | phoneList = await listPhoneNumbersV2(dlgInstanceId, 1000, null, phCountryCode, phNumberTypes, null);
524 | console.log(phoneList);
525 | formatJSON(phoneList, '#rpFormatted');
526 | phListTable.clear();
527 | for (var i=0; i< phoneList.ListPhoneNumbersSummaryList.length; i++) {
528 | var value = phoneList.ListPhoneNumbersSummaryList[i];
529 | phListTable.row.add([value.PhoneNumber, value.PhoneNumberType, value.PhoneNumberCountryCode ]);
530 | }
531 | phListTable.draw();
532 |
533 | var cfList = await listContactFlows(dlgInstanceId);
534 | console.log(cfList);
535 |
536 | $('#sltContactFlowToAssociate').empty();
537 | for(var i=0; i < cfList.ContactFlowSummaryList.length; i++){
538 | var j = cfList.ContactFlowSummaryList[i];
539 | if(j.ContactFlowType === "CONTACT_FLOW") {
540 | $('#sltContactFlowToAssociate').append('');
541 | }
542 | }
543 |
544 | handleWindow(false, '');
545 | } catch(e) {
546 | console.log(e);
547 | handleWindow(false, '');
548 | showResults(e);
549 | }
550 |
551 | }
552 |
553 |
554 | async function modifyTDG() {
555 | try {
556 | handleWindow(true, '');
557 | let config = {};
558 | //config["TelephonyConfig"] ={};
559 | //config["TelephonyConfig"]["Distribution"] =[];
560 | config["Distributions"] =[];
561 | let region1Details = {};
562 | let region2Details = {};
563 | region1Details["Region"] = $("#txtRegion1").val();
564 | region1Details["Percentage"] = $("#txtPercentage1").val();
565 | region2Details["Region"] = $("#txtRegion2").val();
566 | region2Details["Percentage"] = $("#txtPercentage2").val();
567 | config["Distributions"].push(region1Details);
568 | config["Distributions"].push(region2Details);
569 | let resp = await updateTrafficDistribution(selectedId, config);
570 | console.log(resp);
571 | formatJSON(resp, '#rpFormatted');
572 | handleWindow(false, '');
573 | $( "#dlgTDGModify" ).dialog( "close" );
574 | } catch(e) {
575 | console.log(e);
576 | handleWindow(false, '');
577 | showResults(e);
578 | }
579 |
580 | }
581 |
582 | async function createReplicateInstance() {
583 | try {
584 | handleWindow(true, '');
585 | let resp = await replicateInstance(dlgInstanceId, $('#txtReplicaName').val(), $('#txtReplicaRegion').val());
586 | console.log(resp);
587 | formatJSON(resp, '#rpFormatted');
588 | handleWindow(false, '');
589 | $( "#dlgInstanceReplica" ).dialog( "close" );
590 | } catch(e) {
591 | console.log(e);
592 | handleWindow(false, '');
593 | showResults(e);
594 | }
595 |
596 | }
597 |
598 | async function createTDG() {
599 | try {
600 | handleWindow(true, '');
601 | let resp = await createTrafficDistributionGroup(dlgInstanceId, $('#tdgName').val(), $('#tdgDescription').val());
602 | console.log(resp);
603 | formatJSON(resp, '#rpFormatted');
604 | getListTrafficDistributionGroups();
605 | handleWindow(false, '');
606 | $( "#dlgTDG" ).dialog( "close" );
607 | } catch(e) {
608 | console.log(e);
609 | handleWindow(false, '');
610 | showResults(e);
611 | }
612 |
613 | }
614 |
615 | async function deleteTDG() {
616 | try {
617 | handleWindow(true, '');
618 | let resp = await deleteTrafficDistributionGroup(selectedId);
619 | console.log(resp);
620 | formatJSON(resp, '#rpFormatted');
621 | getListTrafficDistributionGroups();
622 | handleWindow(false, '');
623 | } catch(e) {
624 | console.log(e);
625 | handleWindow(false, '');
626 | showResults(e);
627 | }
628 |
629 | }
630 |
631 |
632 | async function describeTDG() {
633 | try {
634 | handleWindow(true, '');
635 | let resp = await describeTrafficDistributionGroup(selectedId);
636 | console.log(resp);
637 | formatJSON(resp, '#rpFormatted');
638 | handleWindow(false, '');
639 | } catch(e) {
640 | console.log(e);
641 | handleWindow(false, '');
642 | showResults(e);
643 | }
644 |
645 | }
646 |
647 | async function getTDG() {
648 | try {
649 | handleWindow(true, '');
650 | let resp = await getTrafficDistribution(selectedId);
651 | console.log(resp);
652 | formatJSON(resp, '#rpFormatted');
653 |
654 | $("#txtRegion1").val(resp.TelephonyConfig.Distributions[0].Region);
655 | $("#txtPercentage1").val(resp.TelephonyConfig.Distributions[0].Percentage);
656 | $("#txtRegion2").val(resp.TelephonyConfig.Distributions[1].Region);
657 | $("#txtPercentage2").val(resp.TelephonyConfig.Distributions[1].Percentage);
658 |
659 | handleWindow(false, '');
660 | } catch(e) {
661 | console.log(e);
662 | handleWindow(false, '');
663 | showResults(e);
664 | }
665 |
666 | }
667 |
668 | async function getListTrafficDistributionGroups() {
669 | try {
670 | handleWindow(true, '');
671 | tdgList = await listTrafficDistributionGroups(dlgInstanceId, null, 10);
672 | console.log(tdgList);
673 |
674 | formatJSON(tdgList, '#rpFormatted');
675 | /* var cfList = await listContactFlows(dlgInstanceId);
676 | console.log(cfList);
677 |
678 | $('#sltContactFlowToAssociate').empty();
679 | for(var i=0; i < cfList.ContactFlowSummaryList.length; i++){
680 | var j = cfList.ContactFlowSummaryList[i];
681 | if(j.ContactFlowType === "CONTACT_FLOW") {
682 | $('#sltContactFlowToAssociate').append('');
683 | }
684 | }*/
685 |
686 | qcListTable.clear();
687 | for (var i=0; i< tdgList.TrafficDistributionGroupSummaryList.length; i++) {
688 | var value = tdgList.TrafficDistributionGroupSummaryList[i];
689 | qcListTable.row.add([value.Name, value.Status]);
690 | }
691 | qcListTable.draw();
692 |
693 | $('#sltTDG').empty();
694 | $('#sltTDGs').empty();
695 | $('#sltTDG').append('');
696 | for(var i=0; i < tdgList.TrafficDistributionGroupSummaryList.length; i++){
697 | var j = tdgList.TrafficDistributionGroupSummaryList[i];
698 | $('#sltTDG').append('');
699 | $('#sltTDGs').append('');
700 | }
701 |
702 | handleWindow(false, '');
703 | } catch(e) {
704 | console.log(e);
705 | handleWindow(false, '');
706 | showResults(e);
707 | }
708 |
709 | }
710 |
711 |
712 | const updatePhoneNumber = (phoneNumberId, targetArn ) => {
713 | return new Promise((resolve,reject) => {
714 | var params = {PhoneNumberId : phoneNumberId, TargetArn : targetArn };
715 | console.log(params);
716 | connect.updatePhoneNumber(params, function (err, res) {
717 | if (err)
718 | reject(err);
719 | else
720 | resolve(res);
721 | });
722 | });
723 | }
724 |
725 | const updateTrafficDistribution = (id, telephonyConfig ) => {
726 | return new Promise((resolve,reject) => {
727 | var params = {Id : id, TelephonyConfig : telephonyConfig };
728 | console.log(params);
729 | connect.updateTrafficDistribution(params, function (err, res) {
730 | if (err)
731 | reject(err);
732 | else
733 | resolve(res);
734 | });
735 | });
736 | }
737 |
738 | const replicateInstance = (instanceId, replicaAlias, region ) => {
739 | return new Promise((resolve,reject) => {
740 | var params = {InstanceId : instanceId, ReplicaRegion : region, ReplicaAlias : replicaAlias };
741 | console.log(params);
742 | connect.replicateInstance(params, function (err, res) {
743 | if (err)
744 | reject(err);
745 | else
746 | resolve(res);
747 | });
748 | });
749 | }
750 |
751 | const describeTrafficDistributionGroup = (trafficDistributionGroupId) => {
752 | return new Promise((resolve,reject) => {
753 | var params = {TrafficDistributionGroupId : trafficDistributionGroupId };
754 | console.log(params);
755 | connect.describeTrafficDistributionGroup(params, function (err, res) {
756 | if (err)
757 | reject(err);
758 | else
759 | resolve(res);
760 | });
761 | });
762 | }
763 |
764 |
765 | const deleteTrafficDistributionGroup = (trafficDistributionGroupId) => {
766 | return new Promise((resolve,reject) => {
767 | var params = {TrafficDistributionGroupId : trafficDistributionGroupId };
768 | console.log(params);
769 | connect.deleteTrafficDistributionGroup(params, function (err, res) {
770 | if (err)
771 | reject(err);
772 | else
773 | resolve(res);
774 | });
775 | });
776 | }
777 |
778 | const createTrafficDistributionGroup = (instanceId, name, description) => {
779 | return new Promise((resolve,reject) => {
780 | var params = {Name : name, Description: description, InstanceId : instanceId };
781 | console.log(params);
782 | connect.createTrafficDistributionGroup(params, function (err, res) {
783 | if (err)
784 | reject(err);
785 | else
786 | resolve(res);
787 | });
788 | });
789 | }
790 |
791 | const listTrafficDistributionGroups = (instanceId, nextToken, maxResults) => {
792 | return new Promise((resolve,reject) => {
793 | var params = {InstanceId : instanceId, NextToken : nextToken, MaxResults : maxResults };
794 | console.log(params);
795 | connect.listTrafficDistributionGroups(params, function (err, res) {
796 | if (err)
797 | reject(err);
798 | else
799 | resolve(res);
800 | });
801 | });
802 | }
803 |
804 | const getTrafficDistribution = (id) => {
805 | return new Promise((resolve,reject) => {
806 | var params = {Id : id};
807 | console.log(params);
808 | connect.getTrafficDistribution(params, function (err, res) {
809 | if (err)
810 | reject(err);
811 | else
812 | resolve(res);
813 | });
814 | });
815 | }
816 |
817 |
818 | const describeTrafficRouting = (voiceConfiguration) => {
819 | return new Promise((resolve,reject) => {
820 | var params = {VoiceConfiguration : voiceConfiguration};
821 | console.log(params);
822 | connect.describeTrafficRouting(params, function (err, res) {
823 | if (err)
824 | reject(err);
825 | else
826 | resolve(res);
827 | });
828 | });
829 | }
830 |
831 | const updateTrafficRouting = (failover, voiceConfiguration) => {
832 | return new Promise((resolve,reject) => {
833 | var params = {Failover : failover, VoiceConfiguration : voiceConfiguration};
834 | console.log(params);
835 | connect.updateTrafficRouting(params, function (err, res) {
836 | if (err)
837 | reject(err);
838 | else
839 | resolve(res);
840 | });
841 | });
842 | }
843 |
844 | const searchAvailablePhoneNumbers = (targetArn, phoneNumberCountryCode, phoneNumberType, phoneNumberPrefix, maxResults, nextToken ) => {
845 | return new Promise((resolve,reject) => {
846 | var params = {TargetArn : targetArn, PhoneNumberCountryCode : phoneNumberCountryCode,
847 | PhoneNumberType : phoneNumberType, PhoneNumberPrefix : phoneNumberPrefix, MaxResults : maxResults,
848 | NextToken : nextToken};
849 | console.log(params);
850 | connect.searchAvailablePhoneNumbers(params, function (err, res) {
851 | if (err)
852 | reject(err);
853 | else
854 | resolve(res);
855 | });
856 | });
857 | }
858 |
859 | const listPhoneNumbersV2 = (targetArn, maxResults, nextToken, phoneNumberCountryCodes, phoneNumberTypes, phoneNumberPrefix) => {
860 | return new Promise((resolve,reject) => {
861 | var params = {TargetArn : targetArn, MaxResults : maxResults, NextToken : nextToken,
862 | PhoneNumberCountryCodes : phoneNumberCountryCodes, PhoneNumberTypes : phoneNumberTypes,
863 | PhoneNumberPrefix : phoneNumberPrefix};
864 | console.log(params);
865 | connect.listPhoneNumbersV2(params, function (err, res) {
866 | if (err)
867 | reject(err);
868 | else
869 | resolve(res);
870 | });
871 | });
872 | }
873 |
874 | const listPhoneNumbers = (instanceId ) => {
875 | return new Promise((resolve,reject) => {
876 | var params = {InstanceId : instanceId};
877 | console.log(params);
878 | connect.listPhoneNumbers(params, function (err, res) {
879 | if (err)
880 | reject(err);
881 | else
882 | resolve(res);
883 | });
884 | });
885 | }
886 |
887 | const describePhoneNumber = (phoneNumberId ) => {
888 | return new Promise((resolve,reject) => {
889 | var params = {PhoneNumberId : phoneNumberId};
890 | console.log(params);
891 | connect.describePhoneNumber(params, function (err, res) {
892 | if (err)
893 | reject(err);
894 | else
895 | resolve(res);
896 | });
897 | });
898 | }
899 |
900 | const listContactFlows = (instanceId) => {
901 | return new Promise((resolve,reject) => {
902 | var params = {InstanceId : instanceId};
903 | console.log(params);
904 | connect.listContactFlows(params, function (err, res) {
905 | if (err)
906 | reject(err);
907 | else
908 | resolve(res);
909 | });
910 | });
911 | }
912 |
913 | const claimPhoneNumber = (targetArn, phoneNumber, phoneNumberDescription) => {
914 | return new Promise((resolve,reject) => {
915 | var params = {TargetArn : targetArn, PhoneNumber : phoneNumber, PhoneNumberDescription : phoneNumberDescription};
916 | console.log(params);
917 | connect.claimPhoneNumber(params, function (err, res) {
918 | if (err)
919 | reject(err);
920 | else
921 | resolve(res);
922 | });
923 | });
924 | }
925 |
926 | const associatePhoneNumberContactFlow = (phoneNumberId, instanceId, contactFlowId) => {
927 | return new Promise((resolve,reject) => {
928 | var params = {PhoneNumberId : phoneNumberId, InstanceId : instanceId, ContactFlowId : contactFlowId};
929 | console.log(params);
930 | connect.associatePhoneNumberContactFlow(params, function (err, res) {
931 | if (err)
932 | reject(err);
933 | else
934 | resolve(res);
935 | });
936 | });
937 | }
938 |
939 | const releasePhoneNumber = (phoneNumberId) => {
940 | return new Promise((resolve,reject) => {
941 | var params = {PhoneNumberId : phoneNumberId};
942 | console.log(params);
943 | connect.releasePhoneNumber(params, function (err, res) {
944 | if (err)
945 | reject(err);
946 | else
947 | resolve(res);
948 | });
949 | });
950 | }
951 |
952 | const disassociatePhoneNumberContactFlow = (phoneNumberId, instanceId) => {
953 | return new Promise((resolve,reject) => {
954 | var params = {PhoneNumberId : phoneNumberId, InstanceId : instanceId};
955 | console.log(params);
956 | connect.disassociatePhoneNumberContactFlow(params, function (err, res) {
957 | if (err)
958 | reject(err);
959 | else
960 | resolve(res);
961 | });
962 | });
963 | }
964 |
965 | const deleteInstance = (instanceId) => {
966 | return new Promise((resolve,reject) => {
967 | var params = {InstanceId : instanceId};
968 | console.log(params);
969 | connect.deleteInstance(params, function (err, res) {
970 | if (err)
971 | reject(err);
972 | else
973 | resolve(res);
974 | });
975 | });
976 | }
977 |
978 | function showResults(message){
979 | $('#resultSpan').text(message);
980 | $("#resultDialog").dialog("open");
981 | }
982 |
983 | function loadConnectAPIs() {
984 | connect = new AWS.Connect({ region: dlgSourceRegion} ) ;
985 | }
986 |
987 | async function getIPJSON(){
988 | try{
989 | let a = await makeAJAXGet('https://ip-ranges.amazonaws.com/ip-ranges.json');
990 | console.log(a);
991 | var ac = [];
992 | var ec2 = [];
993 | for(var i=0; i< a.prefixes.length; i++) {
994 | var item = a.prefixes[i];
995 | if(item.service === 'AMAZON_CONNECT'){
996 | ac.push(item);
997 | }
998 | if(item.service === 'EC2_INSTANCE_CONNECT'){
999 | ec2.push(item);
1000 | }
1001 | }
1002 | var f = {};
1003 | f.amazonconnect = ac;
1004 | f.ec2 = ec2;
1005 | formatJSON(f, '#rpFormatted');
1006 | }catch(e){
1007 | console.log(e)
1008 | }
1009 |
1010 | }
1011 |
1012 | const makeAJAXGet = (url) => {
1013 | return new Promise((resolve,reject) => {
1014 | var posting = $.ajax({
1015 | url: url,
1016 | method: "GET",
1017 | dataType: 'json'
1018 | })
1019 | .done(function (msg) {
1020 | resolve(msg);
1021 | })
1022 | .fail(function (msg) {
1023 | reject(msg);
1024 | });
1025 |
1026 | });
1027 | }
1028 |
1029 |
1030 | function handleWindow(openClose, text) {
1031 | if(openClose == true) {
1032 | $( "#dialog" ).dialog( "open" );
1033 | } else {
1034 | $( "#dialog" ).dialog( "close" );
1035 | }
1036 |
1037 | if(text.length>1) {
1038 | $('#waitingSpan').text(text);
1039 | } else {
1040 | $('#waitingSpan').text(' Waiting for server to respond');
1041 | }
1042 | }
1043 |
1044 | function setAWSConfig(accessKey, secretKey, rgn) {
1045 |
1046 | AWS.config.update({
1047 | accessKeyId: accessKey, secretAccessKey: secretKey, region: rgn
1048 | });
1049 | AWS.config.credentials.get(function (err) {
1050 | if (err)
1051 | console.log(err);
1052 | else {
1053 | credentials = AWS.config.credentials;
1054 | getSessionToken();
1055 | }
1056 | });
1057 |
1058 | }
1059 |
1060 | function formatJSON(data, element) {
1061 | $(element).html(prettyPrintJson.toHtml(data));
1062 | }
1063 |
1064 |
1065 | function getSessionToken() {
1066 | var sts = new AWS.STS();
1067 | sts.getSessionToken(function (err, data) {
1068 | if (err) console.log("Error getting credentials");
1069 | else {
1070 | secretKey = data.Credentials.SecretAccessKey;
1071 | accessKey = data.Credentials.AccessKeyId;
1072 | sessionId = data.Credentials.SessionToken;
1073 | }
1074 | });
1075 | }
1076 |
1077 | function clear_form_elements(ele) {
1078 | $(':input',ele)
1079 | .not(':button, :submit, :reset')
1080 | .val('')
1081 | .prop('checked', false)
1082 | .prop('selected', false);
1083 | }
1084 |
1085 | function saveCookie() {
1086 | dlgSourceAccessKey=$("#dlgSourceAccessKey").val();
1087 | dlgSourceSecretKey=$("#dlgSourceSecretKey").val();
1088 | dlgSourceRegion=$("#dlgSourceRegion").val();
1089 | dlgInstanceId = $("#dlgInstanceId").val();
1090 |
1091 | if(!checkAllMandatoryFields()) {
1092 | $('#spnAWSMessage').text('');
1093 | setAWSConfig(dlgSourceAccessKey, dlgSourceSecretKey, dlgSourceRegion);
1094 | return true;
1095 | }else{
1096 | $('#spnAWSMessage').text('All fields are mandatory and cannot be whitespaces or null');
1097 | return false;
1098 | }
1099 |
1100 | /*if(!checkAllMandatoryFields()) {
1101 | setCookie("dlgSourceAccessKey", dlgSourceAccessKey,100);
1102 | setCookie("dlgSourceSecretKey", dlgSourceSecretKey,100 );
1103 | setCookie("dlgSourceRegion", dlgSourceRegion,100);
1104 | setCookie("dlgInstanceId", dlgInstanceId,100);
1105 | $('#spnAWSMessage').text('');
1106 | setAWSConfig(dlgSourceAccessKey, dlgSourceSecretKey, dlgSourceRegion);
1107 | return true;
1108 | }else{
1109 | $('#spnAWSMessage').text('All fields are mandatory and cannot be whitespaces or null');
1110 | return false;
1111 | }*/
1112 | }
1113 |
1114 | function getCookie(c_name)
1115 | {
1116 | var i,x,y,ARRcookies=document.cookie.split(";");
1117 | for (i=0;i 31 && (charCode < 48 || charCode > 57)) {
1174 | return false;
1175 | }
1176 | return true;
1177 | }
1178 |
--------------------------------------------------------------------------------