Build a Botpress Integration Easily: Flowise Examp...
# 📖tutorials
f
[YouTube Video](

https://youtu.be/fS8r4KvZ118

) In this beginner-friendly tutorial, I’ll guide you through the process of building a custom integration with Botpress, using Flowise as our example. Whether you're new to Botpress or looking to enhance your skills, this video will provide you with easy-to-follow steps and essential tips. We'll cover everything from setting up your environment to writing your first lines of TypeScript, all aimed at creating a functional integration. Perfect for developers at any skill level who want to expand their toolkit with Botpress customizations. Code: index.ts file:
Copy code
javascript
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:
Copy code
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'),
      },
    },
  }, 
})
q
I don’t understand why everyone is always praising Decay so much. He’s doing the exact same things as the rest of us here, only more and better. If Decay were a simple ice cream seller in Istanbul, this is what his work would look like https://www.youtube.com/shorts/1LoNj7EOkPE
c
you guys are on a roll 🦾⚡⚡
c
WOOOOOOOOOOOOOOOW
f
Its not done at all, but I can hopefully finish it soon 🙂
c
that would be amazing, I use flowise myself in my CRM
f
It's very nice to hear that you find it useful!
c
https://fordv2vimagesfinal.up.railway.app/chat/ I buily this English Voice Agent to demo for Ford
only test on PC please, not compatible with other devices
u could have skipped the whole process and just used flowise's APIs right?
just a post request and retrieving the response is enough
f
Yup that is completely correct. This is basically just the execute code card, but all you have to give is the endpoint and the body
I am on my phone, but I look forward to trying it tomorrow
m
@crooked-van-25152 I retract my nomination and postive statements LOLOLOLOLOL
28 Views