fresh-fireman-491
04/13/2024, 10:07 PMjavascript
import axios from 'axios'
import * as botpress from '.botpress'
export default new botpress.Integration({
register: async () => {},
unregister: async () => { },
actions: {
async sendData({ input, logger }): Promise<{ success: true; response: any; } | { success: false; response: null; }> {
logger.forBot().info('Sending data to Flowise')
const apiEndpoint = input.api
try {
const requestData = JSON.parse(input.data)
const { data: response, status } = await axios.post(apiEndpoint, { question: requestData })
logger.forBot().info(`Successfully sent data to Flowise, status code: ${status}`)
return { success: true, response }
} catch (error) {
let status = 'Unknown Error';
let message = 'An unknown error occurred';
if (axios.isAxiosError(error)) {
status = error.response ? error.response.status.toString() : 'Network Error';
message = error.message;
logger.forBot().error(`Error sending data to Flowise. Status: ${status}, Message: ${message}`, {
response: error.response?.data,
});
} else if (error instanceof SyntaxError) {
logger.forBot().error(`Error parsing input JSON data: ${error.message}`);
} else {
logger.forBot().error(`Error sending data to Flowise. Message: ${message}`, {
error,
});
}
return { success: false, response: null }
}
}
},
channels: {},
handler: async () => {},
})
integration.definition.ts:
javascript
import { IntegrationDefinition } from '@botpress/sdk'
import { z } from 'zod'
const INTEGRATION_NAME = 'decayintegrations/flowise'
export default new IntegrationDefinition({
name: INTEGRATION_NAME,
version: '0.2.0',
title: 'Flowise',
channels: {},
actions: {
sendData: {
input: {
schema: z
.object({
api: z.string().min(1, { message: 'Must not be empty' }).describe('Flowise Prediction API endpoint to send data to'),
data: z.string().min(1, { message: 'Must not be empty' }).describe('JSON string of data to send'),
})
.describe('Input schema for sending data'),
},
output: {
schema: z
.object({
success: z.boolean().describe('True if the data was sent successfully'),
response: z
.any()
.describe(
'Data received from Flowise after sending data.'
)
.nullable(),
})
.describe('Output schema after sending data, expecting any JSON structure'),
},
},
},
})
microscopic-shampoo-2255
04/13/2024, 11:10 PMquick-musician-29561
04/14/2024, 4:38 AMcold-jewelry-54343
04/14/2024, 6:27 PMcurved-dress-55324
04/14/2024, 6:52 PMfresh-fireman-491
04/14/2024, 7:22 PMcurved-dress-55324
04/14/2024, 7:23 PMfresh-fireman-491
04/14/2024, 7:26 PMcurved-dress-55324
04/14/2024, 7:26 PMcurved-dress-55324
04/14/2024, 7:27 PMcurved-dress-55324
04/14/2024, 7:45 PMcurved-dress-55324
04/14/2024, 7:46 PMfresh-fireman-491
04/14/2024, 7:47 PMfresh-fireman-491
04/14/2024, 7:47 PMmicroscopic-shampoo-2255
04/15/2024, 9:36 AM