Skip to content

Commit

Permalink
Tested components (#12130)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcortes committed May 28, 2024
1 parent e84d977 commit 3f79be7
Show file tree
Hide file tree
Showing 10 changed files with 516 additions and 8 deletions.
98 changes: 98 additions & 0 deletions components/leexi/actions/create-call/create-call.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import app from "../../leexi.app.mjs";

export default {
key: "leexi-create-call",
name: "Create Call",
description: "Create a new call in Leexi. [See the documentation](https://developer.leexi.ai/)",
version: "0.0.1",
type: "action",
props: {
app,
recordingS3Key: {
type: "string",
label: "Recording S3 Key",
description: "The S3 key returned by the presign_recording_url endpoint.",
},
externalId: {
type: "string",
label: "External ID",
description: "The ID of the call in your system.",
},
integrationUserExternalId: {
type: "string",
label: "Integration User External ID",
description: "The external ID of the user making the call on your platform.",
},
integrationUserName: {
type: "string",
label: "Integration User Name",
description: "The name of the user making the call on your platform.",
},
direction: {
type: "string",
label: "Call Direction",
description: "The direction of the call (inbound or outbound).",
options: [
"inbound",
"outbound",
],
},
performedAt: {
type: "string",
label: "Performed At",
description: "The start time of the call, in ISO8601 format. Eg. `2024-01-09T17:05:09+01:00`",
},
description: {
type: "string",
label: "Description",
description: "A description of the call.",
optional: true,
},
rawPhoneNumber: {
type: "string",
label: "Phone Number",
description: "The phone number of the caller.",
optional: true,
},
},
methods: {
createCall(args = {}) {
return this.app.post({
path: "/calls",
...args,
});
},
},
async run({ $ }) {
const {
createCall,
recordingS3Key,
externalId,
integrationUserExternalId,
integrationUserName,
direction,
performedAt,
description,
rawPhoneNumber,
} = this;

const response = await createCall({
$,
data: {
recording_s3_key: recordingS3Key,
external_id: externalId,
integration_user: {
external_id: integrationUserExternalId,
name: integrationUserName,
},
direction,
performed_at: performedAt,
description,
raw_phone_number: rawPhoneNumber,
},
});

$.export("$summary", "Successfully created a new call.");
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { readFileSync } from "fs";
import app from "../../leexi.app.mjs";

export default {
key: "leexi-create-presign-recording-url",
name: "Create Presigned Recording URL",
description: "Creates a presigned URL for uploading a call recording. [See the documentation](https://developer.leexi.ai/)",
version: "0.0.1",
type: "action",
props: {
app,
extension: {
propDefinition: [
app,
"extension",
],
},
filePath: {
type: "string",
label: "File Path",
description: "The path to the file to upload. Eg. `/tmp/recording.mp3`",
},
},
methods: {
createPresignedRecordingUrl(args = {}) {
return this.app.post({
path: "/calls/presign_recording_url",
...args,
});
},
uploadFile(args = {}) {
return this.app.put({
...args,
});
},
},
async run({ $ }) {
const {
uploadFile,
createPresignedRecordingUrl,
extension,
filePath,
} = this;

const response = await createPresignedRecordingUrl({
$,
data: {
extension,
},
});

if (!response.success) {
$.export("$error", "Failed to create a presigned URL for recording.");
return response;
}

const {
data: {
headers,
url,
},
} = response;

const path = filePath?.startsWith("/tmp")
? filePath
: `/tmp/${filePath}`;

await uploadFile({
$,
headers,
url,
data: readFileSync(path),
});

$.export("$summary", "Successfully created a presigned URL for recording");
return response;
},
};
41 changes: 41 additions & 0 deletions components/leexi/actions/get-call/get-call.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import app from "../../leexi.app.mjs";

export default {
key: "leexi-get-call",
name: "Get Call",
description: "Get details of a call by its ID. [See the documentation](https://developer.leexi.ai/)",
version: "0.0.1",
type: "action",
props: {
app,
callId: {
propDefinition: [
app,
"callId",
],
},
},
methods: {
getCall({
callId, ...args
} = {}) {
return this.app._makeRequest({
path: `/calls/${callId}`,
...args,
});
},
},
async run({ $ }) {
const {
getCall,
callId,
} = this;

const response = await getCall({
$,
callId,
});
$.export("$summary", `Successfully retrieved details for call ID \`${response.data?.uuid}\`.`);
return response;
},
};
45 changes: 45 additions & 0 deletions components/leexi/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const BASE_URL = "https://public-api.leexi.ai";
const VERSION_PATH = "/v1";
const LAST_CREATED_AT = "lastCreatedAt";
const DEFAULT_LIMIT = 100;
const DEFAULT_MAX = 300;

const EXTENSION_OPTIONS = [
".mp4",
".mkv",
".avi",
".webm",
".mov",
".wmv",
".mpg",
".mpeg",
".mp3",
".wav",
".aac",
".flac",
".ogg",
".m4a",
".wma",
".opus",
".aiff",
".alac",
".amr",
".ape",
".dts",
".ac3",
".mid",
".mp2",
".mpc",
".ra",
".tta",
".vox",
];

export default {
BASE_URL,
VERSION_PATH,
DEFAULT_LIMIT,
DEFAULT_MAX,
LAST_CREATED_AT,
EXTENSION_OPTIONS,
};
11 changes: 11 additions & 0 deletions components/leexi/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
async function iterate(iterations) {
const items = [];
for await (const item of iterations) {
items.push(item);
}
return items;
}

export default {
iterate,
};
Loading

0 comments on commit 3f79be7

Please sign in to comment.