- About the UISchema, I debuged it on https://rjsf-team.github.io/react-jsonschema-form/
-
-
Save zacker330/f8dcc842151020b0895a12f9a3617019 to your computer and use it in GitHub Desktop.
APITable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ConnectClient, StartOutboundVoiceContactCommand } from '@aws-sdk/client-connect'; | |
import { ResponseStatusCodeEnums } from '../enum/response.status.code.enums'; | |
import { IActionResponse, IErrorResponse } from '../interface/action.response'; | |
interface IAwsConnectRequest { | |
Region: string; | |
AccessKeyId: string; | |
SecretAccessKey: string; | |
DestinationPhoneNumber: string; | |
ContactFlowId: string; | |
InstanceId: string; | |
ClientToken?: string; | |
SourcePhoneNumber?: string; | |
QueueId?: string; | |
Attributes?: any; | |
} | |
function newSuccessResp(contactId: string|undefined): IActionResponse<string>{ | |
return { | |
success: true, | |
data: { | |
data: "ContactId:" + contactId | |
}, | |
code: ResponseStatusCodeEnums.Success, | |
}; | |
} | |
function newFailedResp(requestId: string|undefined): IActionResponse<string>{ | |
return { | |
success: false, | |
data: { | |
errors: [ | |
{ | |
message: 'requestId:' + requestId, | |
}, | |
], | |
}, | |
code: ResponseStatusCodeEnums.ServerError, | |
}; | |
} | |
export async function phoneCall(request: IAwsConnectRequest): Promise<IActionResponse<string>> { | |
try { | |
const credential = { | |
accessKeyId: request.AccessKeyId, | |
secretAccessKey: request.SecretAccessKey, | |
}; | |
const client = new ConnectClient({ | |
region: request.Region, | |
credentials: credential, | |
}); | |
const input = { | |
DestinationPhoneNumber: request.DestinationPhoneNumber, | |
ContactFlowId: request.ContactFlowId, | |
InstanceId: request.InstanceId, | |
ClientToken: request.ClientToken, | |
SourcePhoneNumber: request.SourcePhoneNumber, | |
QueueId: request.QueueId, | |
Attributes: request.Attributes, | |
}; | |
const command = new StartOutboundVoiceContactCommand(input); | |
const response = await client.send(command); | |
if (response.$metadata.httpStatusCode === 200) { | |
return newSuccessResp(response.ContactId); | |
} else { | |
return newFailedResp(response.$metadata.requestId); | |
} | |
} catch (error: any) { | |
const res: IErrorResponse = { | |
errors: [ | |
{ | |
message: error.message, | |
}, | |
], | |
}; | |
return { | |
success: false, | |
data: res, | |
code: ResponseStatusCodeEnums.ServerError, | |
}; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// packages/room-server/src/automation/actions/aws-connect.actions.ts | |
import { phoneCall } from './aws-connect'; | |
import { IActionResponse } from './interface/action.response'; | |
import { IBaseAction, IUiSchema } from './interface/base.action'; | |
import { AutomationAction } from './decorators/automation.action.decorator'; | |
import { IJsonSchema } from '@apitable/core'; | |
@AutomationAction('awsConnect') | |
export class AwsConnectAction implements IBaseAction { | |
async endpoint(input: any): Promise<IActionResponse<any>> { | |
return Promise.resolve(input).then((input) => phoneCall(input)); | |
} | |
// https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/connect/command/StartOutboundVoiceContactCommand/ | |
getInputSchema(): IJsonSchema { | |
return { | |
type: 'object', | |
required: ['Region', 'AccessKeyId', 'SecretAccessKey', 'DestinationPhoneNumber', 'ContactFlowId', 'InstanceId'], | |
properties: { | |
Region: { | |
type: 'string', | |
description: 'region of the AWS', | |
title: 'Region', | |
}, | |
AccessKeyId: { | |
type: 'string', | |
description: 'AccessKeyId of AWS user', | |
title: 'Access Key Id', | |
}, | |
SecretAccessKey: { | |
type: 'string', | |
description: 'SecretAccessKey of AWS user', | |
title: 'Secret Access Key', | |
}, | |
DestinationPhoneNumber: { | |
type: 'string', | |
description: 'The phone number of the destination, in E.164 format.', | |
title: 'Destination Phone Number', | |
}, | |
ContactFlowId: { | |
type: 'string', | |
description: | |
'The identifier of the flow for the outbound call. To see the ContactFlowId in the Amazon Connect console user interface, on the navigation menu go to Routing, Contact Flows. Choose the flow. On the flow page, under the name of the flow, choose Show additional flow information. The ContactFlowId is the last part of the ARN, shown here in bold:', | |
title: 'Contact Flow Id', | |
}, | |
InstanceId: { | |
type: 'string', | |
description: | |
'The identifier of the Amazon Connect instance. You can find the instance ID in the Amazon Resource Name (ARN) of the instance.', | |
title: 'Instance Id', | |
}, | |
ClientToken: { | |
type: 'string', | |
description: | |
'A unique, case-sensitive identifier that you provide to ensure the idempotency of the request. If not provided, the Amazon Web Services SDK populates this field. For more information about idempotency, see Making retries safe with idempotent APIs. The token is valid for 7 days after creation. If a contact is already started, the contact ID is returned.', | |
title: 'Client Token', | |
}, | |
SourcePhoneNumber: { | |
type: 'string', | |
description: | |
'The phone number associated with the Amazon Connect instance, in E.164 format. If you do not specify a source phone number, you must specify a queue.', | |
title: 'Source Phone Number', | |
}, | |
QueueId: { | |
type: 'string', | |
description: | |
'The queue for the call. If you specify a queue, the phone displayed for caller ID is the phone number specified in the queue. If you do not specify a queue, the queue defined in the flow is used. If you do not specify a queue, you must specify a source phone number.', | |
title: 'Queue Id', | |
}, | |
Attributes: { | |
type: 'object', | |
description: | |
'A custom key-value pair using an attribute map. The attributes are standard Amazon Connect attributes, and can be accessed in flows just like any other contact attributes. There can be up to 32,768 UTF-8 bytes across all key-value pairs per contact. Attribute keys can include only alphanumeric, dash, and underscore characters.', | |
title: 'Attributes', | |
additionalProperties: { | |
type: 'string', | |
}, | |
}, | |
}, | |
}; | |
} | |
getOutputSchema(): IJsonSchema { | |
return { | |
type: 'object', | |
properties:{ | |
type: 'string', | |
title: 'ContactId' | |
} | |
}; | |
} | |
getUISchema(): IUiSchema { | |
return { | |
Region: { | |
'ui:autofocus': true, | |
'ui:emptyValue': '', | |
'ui:placeholder': 'Region is required', | |
}, | |
SecretAccessKey: { | |
'ui:widget': 'password', | |
}, | |
AccessKeyId: { | |
'ui:widget': 'password', | |
}, | |
SourcePhoneNumber: { | |
'ui:options': { | |
inputType: 'tel', | |
}, | |
}, | |
DestinationPhoneNumber: { | |
'ui:options': { | |
inputType: 'tel', | |
}, | |
}, | |
}; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// packages/room-server/src/automation/actions/index.ts | |
import { Module } from '@nestjs/common'; | |
import path from 'path'; | |
import fs from 'fs'; | |
import process from 'process'; | |
import {AwsConnectAction} from './aws-connect.actions'; | |
export * as webhook from './webhook'; | |
export * as ruliu from './ruliu'; | |
export * as slack from './slack'; | |
export * as sms from './sms'; | |
const actionEnterpriseModulePath = path.join(__dirname, '../../enterprise/automation/action'); | |
const isEnterpriseLevel: boolean = fs.existsSync(actionEnterpriseModulePath); | |
if (isEnterpriseLevel) { | |
import(`${actionEnterpriseModulePath}/index`).then((module) => { | |
const keys = Object.keys(module); | |
for(const key of keys) { | |
exports[key] = module[key]; | |
} | |
}, (err) => { | |
console.error('load enterprise action module error'); | |
console.error(err);111 | |
process.exit(1); | |
}); | |
} | |
// regist AwsConnectAction as an action | |
@Module({ | |
imports: [AwsConnectAction], | |
}) | |
export class AutomationActionModule {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment