Add Activepieces integration for workflow automation
- Add Activepieces fork with SmoothSchedule custom piece - Create integrations app with Activepieces service layer - Add embed token endpoint for iframe integration - Create Automations page with embedded workflow builder - Add sidebar visibility fix for embed mode - Add list inactive customers endpoint to Public API - Include SmoothSchedule triggers: event created/updated/cancelled - Include SmoothSchedule actions: create/update/cancel events, list resources/services/customers 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"extends": [
|
||||
"../../../../.eslintrc.base.json"
|
||||
],
|
||||
"ignorePatterns": [
|
||||
"!**/*"
|
||||
],
|
||||
"overrides": [
|
||||
{
|
||||
"files": [
|
||||
"*.ts",
|
||||
"*.tsx",
|
||||
"*.js",
|
||||
"*.jsx"
|
||||
],
|
||||
"rules": {}
|
||||
},
|
||||
{
|
||||
"files": [
|
||||
"*.ts",
|
||||
"*.tsx"
|
||||
],
|
||||
"rules": {}
|
||||
},
|
||||
{
|
||||
"files": [
|
||||
"*.js",
|
||||
"*.jsx"
|
||||
],
|
||||
"rules": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
# pieces-instabase
|
||||
|
||||
This library was generated with [Nx](https://nx.dev).
|
||||
|
||||
## Building
|
||||
|
||||
Run `nx build pieces-instabase` to build the library.
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "@activepieces/piece-instabase",
|
||||
"version": "0.0.1",
|
||||
"type": "commonjs",
|
||||
"main": "./src/index.js",
|
||||
"types": "./src/index.d.ts",
|
||||
"dependencies": {
|
||||
"tslib": "^2.3.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"name": "pieces-instabase",
|
||||
"$schema": "../../../../node_modules/nx/schemas/project-schema.json",
|
||||
"sourceRoot": "packages/pieces/community/instabase/src",
|
||||
"projectType": "library",
|
||||
"release": {
|
||||
"version": {
|
||||
"manifestRootsToUpdate": [
|
||||
"dist/{projectRoot}"
|
||||
],
|
||||
"currentVersionResolver": "git-tag",
|
||||
"fallbackCurrentVersionResolver": "disk"
|
||||
}
|
||||
},
|
||||
"tags": [],
|
||||
"targets": {
|
||||
"build": {
|
||||
"executor": "@nx/js:tsc",
|
||||
"outputs": [
|
||||
"{options.outputPath}"
|
||||
],
|
||||
"options": {
|
||||
"outputPath": "dist/packages/pieces/community/instabase",
|
||||
"tsConfig": "packages/pieces/community/instabase/tsconfig.lib.json",
|
||||
"packageJson": "packages/pieces/community/instabase/package.json",
|
||||
"main": "packages/pieces/community/instabase/src/index.ts",
|
||||
"assets": [
|
||||
"packages/pieces/community/instabase/*.md",
|
||||
{
|
||||
"input": "packages/pieces/community/instabase/src/i18n",
|
||||
"output": "./src/i18n",
|
||||
"glob": "**/!(i18n.json)"
|
||||
}
|
||||
],
|
||||
"buildableProjectDepsInPackageJsonType": "dependencies",
|
||||
"updateBuildableProjectDepsInPackageJson": true
|
||||
},
|
||||
"dependsOn": [
|
||||
"prebuild",
|
||||
"^build"
|
||||
]
|
||||
},
|
||||
"nx-release-publish": {
|
||||
"options": {
|
||||
"packageRoot": "dist/{projectRoot}"
|
||||
}
|
||||
},
|
||||
"prebuild": {
|
||||
"dependsOn": [
|
||||
"^build"
|
||||
],
|
||||
"executor": "nx:run-commands",
|
||||
"options": {
|
||||
"cwd": "packages/pieces/community/instabase",
|
||||
"command": "bun install --no-save --silent"
|
||||
}
|
||||
},
|
||||
"lint": {
|
||||
"executor": "@nx/eslint:lint",
|
||||
"outputs": [
|
||||
"{options.outputFile}"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
{
|
||||
"Integrate with Instabase AI Hub to automate document processing and AI workflows": "Integrate with Instabase AI Hub to automate document processing and AI workflows",
|
||||
"API Token": "API Token",
|
||||
"IB Context": "IB Context",
|
||||
"API Root URL": "API Root URL",
|
||||
"Your Instabase API token": "Your Instabase API token",
|
||||
"Organization ID (for org accounts) or User ID (for community accounts)": "Organization ID (for org accounts) or User ID (for community accounts)",
|
||||
"API base URL (e.g., https://aihub.instabase.com/api for community accounts)": "API base URL (e.g., https://aihub.instabase.com/api for community accounts)",
|
||||
"\n## Instabase AI Hub Connection Setup\n\n### Prerequisites\n- Create an AI Hub account at [Instabase](https://www.instabase.com)\n- Generate an API token from your account settings\n- Obtain your organization ID or user ID for the IB-Context header\n\n### Authentication Fields\n\n**API Token**: Your API token from Instabase (required for Bearer authentication)\n\n**IB Context**: Your organization ID or user ID\n- For organization accounts: Use your organization ID\n- For community accounts: Use your user ID or omit this": "\n## Instabase AI Hub Connection Setup\n\n### Prerequisites\n- Create an AI Hub account at [Instabase](https://www.instabase.com)\n- Generate an API token from your account settings\n- Obtain your organization ID or user ID for the IB-Context header\n\n### Authentication Fields\n\n**API Token**: Your API token from Instabase (required for Bearer authentication)\n\n**IB Context**: Your organization ID or user ID\n- For organization accounts: Use your organization ID\n- For community accounts: Use your user ID or omit this field\n\n**API Root URL**: The base URL for API calls\n- For community accounts: `https://aihub.instabase.com/api`\n- For organization accounts: `https://your-organization.instabase.com/api` (replace with your custom domain)\n",
|
||||
"Create Conversation and Upload Files": "Create Conversation and Upload Files",
|
||||
"Converse with Document": "Converse with Document",
|
||||
"Custom API Call": "Custom API Call",
|
||||
"Create a new conversation and upload files to it": "Create a new conversation and upload files to it",
|
||||
"Ask a question about a document in a conversation": "Ask a question about a document in a conversation",
|
||||
"Make a custom API call to a specific endpoint": "Make a custom API call to a specific endpoint",
|
||||
"Conversation Name": "Conversation Name",
|
||||
"Description": "Description",
|
||||
"Files": "Files",
|
||||
"Organization": "Organization",
|
||||
"Workspace": "Workspace",
|
||||
"Enable Object Detection": "Enable Object Detection",
|
||||
"Enable Entity Detection": "Enable Entity Detection",
|
||||
"Write Converted Images": "Write Converted Images",
|
||||
"Write Thumbnails": "Write Thumbnails",
|
||||
"Fast Mode": "Fast Mode",
|
||||
"Enable Multilanguage Support": "Enable Multilanguage Support",
|
||||
"Enable Advanced Multilanguage Mode": "Enable Advanced Multilanguage Mode",
|
||||
"Conversation": "Conversation",
|
||||
"Question": "Question",
|
||||
"Documents": "Documents",
|
||||
"Model Mode": "Model Mode",
|
||||
"Method": "Method",
|
||||
"Headers": "Headers",
|
||||
"Query Parameters": "Query Parameters",
|
||||
"Body": "Body",
|
||||
"Response is Binary ?": "Response is Binary ?",
|
||||
"No Error on Failure": "No Error on Failure",
|
||||
"Timeout (in seconds)": "Timeout (in seconds)",
|
||||
"Name of the conversation": "Name of the conversation",
|
||||
"Description of the conversation": "Description of the conversation",
|
||||
"Files to upload to the conversation": "Files to upload to the conversation",
|
||||
"Organization ID (for organization accounts)": "Organization ID (for organization accounts)",
|
||||
"Workspace name where the conversation is created": "Workspace name where the conversation is created",
|
||||
"Enable object detection for extracting tables and checkboxes": "Enable object detection for extracting tables and checkboxes",
|
||||
"Enable entity detection for signatures and barcodes": "Enable entity detection for signatures and barcodes",
|
||||
"Save image files generated when processing documents": "Save image files generated when processing documents",
|
||||
"Generate and save thumbnails of processed documents": "Generate and save thumbnails of processed documents",
|
||||
"Skip preprocessing steps for faster processing": "Skip preprocessing steps for faster processing",
|
||||
"Enable support for non-Latin languages": "Enable support for non-Latin languages",
|
||||
"Enable advanced support for complex non-Latin languages": "Enable advanced support for complex non-Latin languages",
|
||||
"Select the conversation": "Select the conversation",
|
||||
"The question to ask the document": "The question to ask the document",
|
||||
"Select the documents to query": "Select the documents to query",
|
||||
"The model to use to answer the question": "The model to use to answer the question",
|
||||
"Enable fast mode for quicker responses": "Enable fast mode for quicker responses",
|
||||
"Authorization headers are injected automatically from your connection.": "Authorization headers are injected automatically from your connection.",
|
||||
"Enable for files like PDFs, images, etc..": "Enable for files like PDFs, images, etc..",
|
||||
"Default": "Default",
|
||||
"Advanced": "Advanced",
|
||||
"GET": "GET",
|
||||
"POST": "POST",
|
||||
"PATCH": "PATCH",
|
||||
"PUT": "PUT",
|
||||
"DELETE": "DELETE",
|
||||
"HEAD": "HEAD",
|
||||
"New Conversation": "New Conversation",
|
||||
"Triggers when a new conversation is created": "Triggers when a new conversation is created"
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
|
||||
import { createCustomApiCallAction } from '@activepieces/pieces-common';
|
||||
import { PieceAuth, createPiece, Property } from "@activepieces/pieces-framework";
|
||||
import { PieceCategory } from '@activepieces/shared';
|
||||
import { HttpMethod, httpClient, AuthenticationType } from '@activepieces/pieces-common';
|
||||
import { converseWithDocumentAction } from './lib/actions/converse-with-document';
|
||||
import { createConversationAction } from './lib/actions/create-conversation';
|
||||
import { newConversationTrigger } from './lib/triggers/new-conversation';
|
||||
|
||||
const markdown = `
|
||||
## Instabase AI Hub Connection Setup
|
||||
|
||||
### Prerequisites
|
||||
- Create an AI Hub account at [Instabase](https://www.instabase.com)
|
||||
- Generate an API token from your account settings
|
||||
- Obtain your organization ID or user ID for the IB-Context header
|
||||
|
||||
### Authentication Fields
|
||||
|
||||
**API Token**: Your API token from Instabase (required for Bearer authentication)
|
||||
|
||||
**IB Context**: Your organization ID or user ID
|
||||
- For organization accounts: Use your organization ID
|
||||
- For community accounts: Use your user ID or omit this field
|
||||
|
||||
**API Root URL**: The base URL for API calls
|
||||
- For community accounts: \`https://aihub.instabase.com/api\`
|
||||
- For organization accounts: \`https://your-organization.instabase.com/api\` (replace with your custom domain)
|
||||
`;
|
||||
|
||||
export const instabaseAuth = PieceAuth.CustomAuth({
|
||||
required: true,
|
||||
description: markdown,
|
||||
props: {
|
||||
apiToken: PieceAuth.SecretText({
|
||||
displayName: 'API Token',
|
||||
description: 'Your Instabase API token',
|
||||
required: true,
|
||||
}),
|
||||
ibContext: Property.ShortText({
|
||||
displayName: 'IB Context',
|
||||
description: 'Organization ID (for org accounts) or User ID (for community accounts)',
|
||||
required: false,
|
||||
}),
|
||||
apiRoot: Property.ShortText({
|
||||
displayName: 'API Root URL',
|
||||
description: 'API base URL (e.g., https://aihub.instabase.com/api for community accounts)',
|
||||
required: true,
|
||||
}),
|
||||
},
|
||||
validate: async ({ auth }) => {
|
||||
try {
|
||||
const { apiToken, ibContext, apiRoot } = auth;
|
||||
|
||||
try {
|
||||
const parsedUrl = new URL(apiRoot);
|
||||
if (parsedUrl.protocol !== 'https:') {
|
||||
return {
|
||||
valid: false,
|
||||
error: 'API Root URL must use HTTPS protocol'
|
||||
};
|
||||
}
|
||||
if (!parsedUrl.pathname.endsWith('/api')) {
|
||||
return {
|
||||
valid: false,
|
||||
error: 'API Root URL must end with /api'
|
||||
};
|
||||
}
|
||||
} catch {
|
||||
return {
|
||||
valid: false,
|
||||
error: 'Please enter a valid API Root URL'
|
||||
};
|
||||
}
|
||||
|
||||
const headers: Record<string, string> = {
|
||||
'Authorization': `Bearer ${apiToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
|
||||
if (ibContext) {
|
||||
headers['IB-Context'] = ibContext;
|
||||
}
|
||||
|
||||
const response = await httpClient.sendRequest({
|
||||
method: HttpMethod.POST,
|
||||
url: `${apiRoot}/v2/batches`,
|
||||
headers,
|
||||
body: { name: 'test-connection' },
|
||||
authentication: {
|
||||
type: AuthenticationType.BEARER_TOKEN,
|
||||
token: apiToken,
|
||||
},
|
||||
});
|
||||
|
||||
if (response.status >= 200 && response.status < 300) {
|
||||
return {
|
||||
valid: true,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
valid: false,
|
||||
error: `API connection failed with status ${response.status}. Please check your credentials and API root URL.`,
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
valid: false,
|
||||
error: `Connection failed: ${error instanceof Error ? error.message : 'Unknown error'}. Please verify your API token and URL.`,
|
||||
};
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
export const instabase = createPiece({
|
||||
displayName: "Instabase",
|
||||
description: "Integrate with Instabase AI Hub to automate document processing and AI workflows",
|
||||
auth: instabaseAuth,
|
||||
minimumSupportedRelease: '0.36.1',
|
||||
logoUrl: "https://cdn.activepieces.com/pieces/instabase.png",
|
||||
categories: [PieceCategory.ARTIFICIAL_INTELLIGENCE],
|
||||
authors: ["onyedikachi-david"],
|
||||
actions: [
|
||||
createConversationAction,
|
||||
converseWithDocumentAction,
|
||||
createCustomApiCallAction({
|
||||
baseUrl: (auth) => auth ? auth.props.apiRoot : '',
|
||||
auth: instabaseAuth,
|
||||
authMapping: async (auth) => {
|
||||
const headers: Record<string, string> = {
|
||||
'Authorization': `Bearer ${auth.props.apiToken}`,
|
||||
};
|
||||
const ibContext = auth.props.ibContext;
|
||||
if (ibContext) {
|
||||
headers['IB-Context'] = ibContext;
|
||||
}
|
||||
return headers;
|
||||
},
|
||||
}),
|
||||
],
|
||||
triggers: [
|
||||
newConversationTrigger,
|
||||
],
|
||||
});
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
import { createAction, Property } from '@activepieces/pieces-framework';
|
||||
import { HttpMethod } from '@activepieces/pieces-common';
|
||||
import { instabaseAuth } from '../../index';
|
||||
import { makeInstabaseApiCall } from '../common';
|
||||
|
||||
interface ConverseWithDocumentResponse {
|
||||
prompt_id: string | null;
|
||||
answer: string | null;
|
||||
}
|
||||
|
||||
export const converseWithDocumentAction = createAction({
|
||||
auth: instabaseAuth,
|
||||
name: 'converse_with_document',
|
||||
displayName: 'Converse with Document',
|
||||
description: 'Ask a question about a document in a conversation',
|
||||
props: {
|
||||
conversation_id: Property.Dropdown({
|
||||
auth: instabaseAuth,
|
||||
displayName: 'Conversation',
|
||||
description: 'Select the conversation',
|
||||
required: true,
|
||||
refreshers: [],
|
||||
options: async ({ auth }) => {
|
||||
if (!auth) {
|
||||
return {
|
||||
options: [],
|
||||
disabled: true,
|
||||
};
|
||||
}
|
||||
try {
|
||||
const response = await makeInstabaseApiCall<{ conversations: Array<{ id: string; name: string; description?: string }> }>(
|
||||
auth,
|
||||
'/v2/conversations',
|
||||
HttpMethod.GET
|
||||
);
|
||||
|
||||
const options = response.conversations.map(conversation => ({
|
||||
label: conversation.name,
|
||||
value: conversation.id,
|
||||
}));
|
||||
|
||||
return {
|
||||
options,
|
||||
disabled: false,
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
options: [],
|
||||
disabled: true,
|
||||
};
|
||||
}
|
||||
},
|
||||
}),
|
||||
question: Property.LongText({
|
||||
displayName: 'Question',
|
||||
description: 'The question to ask the document',
|
||||
required: true,
|
||||
}),
|
||||
document_ids: Property.MultiSelectDropdown({
|
||||
auth: instabaseAuth,
|
||||
displayName: 'Documents',
|
||||
description: 'Select the documents to query',
|
||||
required: true,
|
||||
refreshers: ['conversation_id'],
|
||||
options: async ({ auth, conversation_id }) => {
|
||||
if (!conversation_id || !auth) {
|
||||
return {
|
||||
options: [],
|
||||
disabled: true,
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await makeInstabaseApiCall<{
|
||||
documents: Array<{ id: number; name: string; state: string; uploadTimestamp: string }>
|
||||
}>(
|
||||
auth,
|
||||
`/v2/conversations/${conversation_id}`,
|
||||
HttpMethod.GET
|
||||
);
|
||||
|
||||
const options = response.documents
|
||||
.filter(doc => doc.state === 'PROCESSED')
|
||||
.map(document => ({
|
||||
label: document.name,
|
||||
value: document.id,
|
||||
}));
|
||||
|
||||
return {
|
||||
options,
|
||||
disabled: false,
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
options: [],
|
||||
disabled: true,
|
||||
};
|
||||
}
|
||||
},
|
||||
}),
|
||||
mode: Property.StaticDropdown({
|
||||
displayName: 'Model Mode',
|
||||
description: 'The model to use to answer the question',
|
||||
required: false,
|
||||
options: {
|
||||
options: [
|
||||
{ label: 'Default', value: 'default' },
|
||||
{ label: 'Advanced', value: 'advanced' },
|
||||
{ label: 'Fast Mode', value: 'fast_mode' },
|
||||
],
|
||||
},
|
||||
defaultValue: 'default',
|
||||
}),
|
||||
fast_mode: Property.Checkbox({
|
||||
displayName: 'Fast Mode',
|
||||
description: 'Enable fast mode for quicker responses',
|
||||
required: false,
|
||||
defaultValue: false,
|
||||
}),
|
||||
},
|
||||
async run({ auth, propsValue }) {
|
||||
const {
|
||||
conversation_id,
|
||||
question,
|
||||
document_ids,
|
||||
mode = 'default',
|
||||
fast_mode = false,
|
||||
} = propsValue;
|
||||
|
||||
const endpoint = `/v2/conversations/${conversation_id}/prompts`;
|
||||
|
||||
const requestBody = {
|
||||
question,
|
||||
document_ids,
|
||||
mode,
|
||||
fast_mode,
|
||||
};
|
||||
|
||||
const response = await makeInstabaseApiCall<ConverseWithDocumentResponse>(
|
||||
auth as any,
|
||||
endpoint,
|
||||
HttpMethod.POST,
|
||||
requestBody
|
||||
);
|
||||
|
||||
return response;
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,172 @@
|
||||
import { createAction, Property, ApFile } from '@activepieces/pieces-framework';
|
||||
import { HttpMethod, httpClient } from '@activepieces/pieces-common';
|
||||
import { instabaseAuth } from '../../index';
|
||||
import FormData from 'form-data';
|
||||
|
||||
interface FileObject {
|
||||
file: ApFile;
|
||||
}
|
||||
|
||||
interface CreateConversationResponse {
|
||||
id: string;
|
||||
name: string;
|
||||
upload_status?: {
|
||||
success?: Array<{ name: string }>;
|
||||
failure?: Array<{ name: string }>;
|
||||
};
|
||||
}
|
||||
|
||||
export const createConversationAction = createAction({
|
||||
auth: instabaseAuth,
|
||||
name: 'create_conversation',
|
||||
displayName: 'Create Conversation and Upload Files',
|
||||
description: 'Create a new conversation and upload files to it',
|
||||
props: {
|
||||
name: Property.ShortText({
|
||||
displayName: 'Conversation Name',
|
||||
description: 'Name of the conversation',
|
||||
required: false,
|
||||
}),
|
||||
description: Property.LongText({
|
||||
displayName: 'Description',
|
||||
description: 'Description of the conversation',
|
||||
required: false,
|
||||
}),
|
||||
files: Property.Array({
|
||||
displayName: 'Files',
|
||||
description: 'Files to upload to the conversation',
|
||||
required: true,
|
||||
properties: {
|
||||
file: Property.File({
|
||||
displayName: 'File',
|
||||
description: 'File to upload',
|
||||
required: true,
|
||||
}),
|
||||
},
|
||||
}),
|
||||
org: Property.ShortText({
|
||||
displayName: 'Organization',
|
||||
description: 'Organization ID (for organization accounts)',
|
||||
required: false,
|
||||
}),
|
||||
workspace: Property.ShortText({
|
||||
displayName: 'Workspace',
|
||||
description: 'Workspace name where the conversation is created',
|
||||
required: false,
|
||||
}),
|
||||
enable_object_detection: Property.Checkbox({
|
||||
displayName: 'Enable Object Detection',
|
||||
description: 'Enable object detection for extracting tables and checkboxes',
|
||||
required: false,
|
||||
defaultValue: false,
|
||||
}),
|
||||
enable_entity_detection: Property.Checkbox({
|
||||
displayName: 'Enable Entity Detection',
|
||||
description: 'Enable entity detection for signatures and barcodes',
|
||||
required: false,
|
||||
defaultValue: true,
|
||||
}),
|
||||
write_converted_image: Property.Checkbox({
|
||||
displayName: 'Write Converted Images',
|
||||
description: 'Save image files generated when processing documents',
|
||||
required: false,
|
||||
defaultValue: true,
|
||||
}),
|
||||
write_thumbnail: Property.Checkbox({
|
||||
displayName: 'Write Thumbnails',
|
||||
description: 'Generate and save thumbnails of processed documents',
|
||||
required: false,
|
||||
defaultValue: true,
|
||||
}),
|
||||
fast_mode: Property.Checkbox({
|
||||
displayName: 'Fast Mode',
|
||||
description: 'Skip preprocessing steps for faster processing',
|
||||
required: false,
|
||||
defaultValue: false,
|
||||
}),
|
||||
enable_multilanguage_support: Property.Checkbox({
|
||||
displayName: 'Enable Multilanguage Support',
|
||||
description: 'Enable support for non-Latin languages',
|
||||
required: false,
|
||||
defaultValue: false,
|
||||
}),
|
||||
enable_multilanguage_advanced_mode: Property.Checkbox({
|
||||
displayName: 'Enable Advanced Multilanguage Mode',
|
||||
description: 'Enable advanced support for complex non-Latin languages',
|
||||
required: false,
|
||||
defaultValue: false,
|
||||
}),
|
||||
},
|
||||
async run({ auth, propsValue }) {
|
||||
const {
|
||||
name,
|
||||
description,
|
||||
files,
|
||||
org,
|
||||
workspace,
|
||||
enable_object_detection = false,
|
||||
enable_entity_detection = true,
|
||||
write_converted_image = true,
|
||||
write_thumbnail = true,
|
||||
fast_mode = false,
|
||||
enable_multilanguage_support = false,
|
||||
enable_multilanguage_advanced_mode = false,
|
||||
} = propsValue;
|
||||
|
||||
const fileObjects = (files as FileObject[]) || [];
|
||||
|
||||
if (!fileObjects || fileObjects.length === 0) {
|
||||
throw new Error('At least one file is required');
|
||||
}
|
||||
|
||||
const formData = new FormData();
|
||||
|
||||
if (name) {
|
||||
formData.append('name', name);
|
||||
}
|
||||
if (description) {
|
||||
formData.append('description', description);
|
||||
}
|
||||
if (org) {
|
||||
formData.append('org', org);
|
||||
}
|
||||
if (workspace) {
|
||||
formData.append('workspace', workspace);
|
||||
}
|
||||
|
||||
formData.append('enable_object_detection', enable_object_detection.toString());
|
||||
formData.append('enable_entity_detection', enable_entity_detection.toString());
|
||||
formData.append('write_converted_image', write_converted_image.toString());
|
||||
formData.append('write_thumbnail', write_thumbnail.toString());
|
||||
formData.append('fast_mode', fast_mode.toString());
|
||||
formData.append('enable_multilanguage_support', enable_multilanguage_support.toString());
|
||||
formData.append('enable_multilanguage_advanced_mode', enable_multilanguage_advanced_mode.toString());
|
||||
|
||||
fileObjects.forEach((fileObj) => {
|
||||
const file = fileObj.file;
|
||||
const fileBuffer = file.base64 ? Buffer.from(file.base64, 'base64') : file.data;
|
||||
formData.append('files', fileBuffer, file.filename);
|
||||
});
|
||||
|
||||
const headers: Record<string, string> = {
|
||||
'Authorization': `Bearer ${auth.props.apiToken}`,
|
||||
};
|
||||
|
||||
const ibContext = auth.props.ibContext;
|
||||
if (ibContext) {
|
||||
headers['IB-Context'] = ibContext;
|
||||
}
|
||||
|
||||
const response = await httpClient.sendRequest<CreateConversationResponse>({
|
||||
method: HttpMethod.POST,
|
||||
url: `${auth.props.apiRoot}/v2/conversations`,
|
||||
headers: {
|
||||
...headers,
|
||||
...formData.getHeaders(),
|
||||
},
|
||||
body: formData,
|
||||
});
|
||||
|
||||
return response.body;
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,41 @@
|
||||
import { instabaseAuth } from '../../index';
|
||||
import { AuthenticationType, httpClient, HttpMethod } from '@activepieces/pieces-common';
|
||||
import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework';
|
||||
|
||||
|
||||
|
||||
export const createInstabaseHeaders = (auth: AppConnectionValueForAuthProperty<typeof instabaseAuth>): Record<string, string> => {
|
||||
const headers: Record<string, string> = {
|
||||
'Authorization': `Bearer ${auth.props.apiToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
|
||||
if (auth.props.ibContext) {
|
||||
headers['IB-Context'] = auth.props.ibContext;
|
||||
}
|
||||
|
||||
return headers;
|
||||
};
|
||||
|
||||
export const makeInstabaseApiCall = async <T = any>(
|
||||
auth: AppConnectionValueForAuthProperty<typeof instabaseAuth>,
|
||||
endpoint: string,
|
||||
method: HttpMethod = HttpMethod.GET,
|
||||
body?: any
|
||||
): Promise<T> => {
|
||||
const url = `${auth.props.apiRoot}${endpoint}`;
|
||||
const headers = createInstabaseHeaders(auth);
|
||||
|
||||
const response = await httpClient.sendRequest<T>({
|
||||
method,
|
||||
url,
|
||||
headers,
|
||||
body,
|
||||
authentication: {
|
||||
type: AuthenticationType.BEARER_TOKEN,
|
||||
token: auth.props.apiToken,
|
||||
},
|
||||
});
|
||||
|
||||
return response.body;
|
||||
};
|
||||
@@ -0,0 +1,64 @@
|
||||
import { createTrigger, TriggerStrategy, AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework';
|
||||
import { DedupeStrategy, Polling, pollingHelper, HttpMethod } from '@activepieces/pieces-common';
|
||||
import { instabaseAuth } from '../../index';
|
||||
import { makeInstabaseApiCall } from '../common';
|
||||
|
||||
type Conversation = {
|
||||
id: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
};
|
||||
|
||||
const polling: Polling<AppConnectionValueForAuthProperty<typeof instabaseAuth>, Record<string, never>> = {
|
||||
strategy: DedupeStrategy.TIMEBASED,
|
||||
items: async ({ auth }) => {
|
||||
const response = await makeInstabaseApiCall<{ conversations: Conversation[] }>(
|
||||
auth,
|
||||
'/v2/conversations',
|
||||
HttpMethod.GET
|
||||
);
|
||||
|
||||
const conversations = response.conversations || [];
|
||||
|
||||
const items = conversations.map((conversation) => ({
|
||||
epochMilliSeconds: Date.now(),
|
||||
data: conversation,
|
||||
}));
|
||||
|
||||
return items;
|
||||
},
|
||||
};
|
||||
|
||||
export const newConversationTrigger = createTrigger({
|
||||
auth: instabaseAuth,
|
||||
name: 'new_conversation',
|
||||
displayName: 'New Conversation',
|
||||
description: 'Triggers when a new conversation is created',
|
||||
props: {},
|
||||
type: TriggerStrategy.POLLING,
|
||||
sampleData: {
|
||||
id: 'conv_123',
|
||||
name: 'Sample Conversation',
|
||||
description: 'A sample conversation for testing',
|
||||
},
|
||||
async onEnable(context) {
|
||||
await pollingHelper.onEnable(polling, {
|
||||
auth: context.auth,
|
||||
store: context.store,
|
||||
propsValue: context.propsValue,
|
||||
});
|
||||
},
|
||||
async onDisable(context) {
|
||||
await pollingHelper.onDisable(polling, {
|
||||
auth: context.auth,
|
||||
store: context.store,
|
||||
propsValue: context.propsValue,
|
||||
});
|
||||
},
|
||||
async test(context) {
|
||||
return await pollingHelper.test(polling, context);
|
||||
},
|
||||
async run(context) {
|
||||
return await pollingHelper.poll(polling, context);
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"extends": "../../../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"importHelpers": true,
|
||||
"noImplicitOverride": true,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noPropertyAccessFromIndexSignature": true
|
||||
},
|
||||
"files": [],
|
||||
"include": [],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.lib.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../../../dist/out-tsc",
|
||||
"declaration": true,
|
||||
"types": ["node"]
|
||||
},
|
||||
"include": ["src/**/*.ts"]
|
||||
}
|
||||
Reference in New Issue
Block a user