You are currently viewing Creating a Custom Tool in Flowise to Add Items to a Google Sheet

Creating a Custom Tool in Flowise to Add Items to a Google Sheet

Introduction

This guide will walk you through creating a custom tool in Flowise (Version 2.0) to add items to a Google spreadsheet via a chatbot. The process is split into two parts:

  1. Creating the Custom Tool: This tool will add items to a to-do list.
  2. Integrating with Google Sheets via Make.com: We will link the tool to Google Sheets so that to-do items are automatically added to the spreadsheet.

Part 1: Creating the Custom Tool in Flowwise

image of custom tool demo

1st Step: Set Up the Chat Flow

  1. Open Flowwise and create a new chat flow.
  2. Save the chat flow and name it, e.g., “Custom Tool Demo”
  3. Add Nodes:
    • Go to Nodes > Agents and add the xxxOpenAI function agentxxx / Tool Agent to the canvas.
    • Go to Nodes > Chat Models and add the OpenAI chat model or other compatible chat model to the canvas.
    • Connect the chat model to the agent.
    • Select your credentials and set the model to GPT-3.5 Turbo with a temperature of 0.7.
  4. Add Memory:
    • Go to Nodes > Memory and add the Buffer Memory node to the canvas.
    • Connect the memory node to the agent.
  5. Add Custom Tools:
    • Go to Nodes > Tools and add the Custom Tool node to the canvas.
    • Connect the Custom Tool to the agent.
    • You can add multiple custom tools if needed, but we’ll use just one for this demo.

2nd Step: Create the Custom Tool

  1. Create a New Tool:
    • You can do this directly from the canvas or by returning to the Flowwise dashboard and selecting Tools > Create.
  2. Name and Describe the Tool:
    • Name: Add a unique name, e.g., “add_to_do_tool,” following the naming convention (lowercase, underscores for spaces).
    • Description: Add a detailed description, e.g., “Use this tool when adding an item to the to-do list.”
  3. Define Output Schema:
    • Add a new property called to_do_text.
    • Set the type to string.
    • Provide a description, e.g., “The to-do item description.”
    • Mark the property as required.
  4. Write JavaScript Logic:
    • Clear the sample code.
    • Add a return statement to return a message like "item added successfully" after the logic executes.
    • Save the tool by clicking on “Add.”

Step 3: Integrate the Custom Tool into the Chat Flow

  1. Go back to your chat flow.
  2. In the Custom Tool node, select the newly created tool from the dropdown.
  3. Save the chat flow.
  4. Test the Tool:
    • Open the chat and type a command like “Add ‘buy milk’ to the to-do list.”
    • Verify that the bot responds with the correct message and that the input is processed correctly.

Part 2: Integrating with Google Sheets via Make.com

image of make configuration

1st Step: Create a Google Spreadsheet

  1. Log in to Google Sheets and create a new spreadsheet.
  2. Name it, e.g., “To-Do List”
  3. Add a title for the first column, e.g., “To-Do Items” and format it as bold.

2nd Step: Set Up Make.com Integration

  1. Sign Up for a free account at Make.com.
  2. Create a New Scenario:
    • Go to Scenarios and select Create New Scenario.
    • Use a Template to speed up the process. Search for a webhook that adds items to Google Sheets.
  3. Configure the Webhook:
    • Name the webhook, e.g., “Flowise AI”
    • Copy the API endpoint provided by Make.com.
  4. Test the Webhook Using Postman:
    • Open Postman, set the method to POST, and paste the API endpoint.
    • In the Body tab, select raw JSON and enter a test value, e.g., {"to_do_text": "sample text"}.
    • Click Send and ensure you get a response of “Accepted.”
  5. Link to Google Spreadsheet:
    • In Make.com, link the webhook to your Google Sheet.
    • Map the to_do_text property to the correct column in your spreadsheet.
    • Save the scenario and toggle it on.

Step 3: Finalize and Test the Custom Tool

image of add to-do tool
  1. Modify the Tool Code in Flowwise:
    • Go back to Flowwise, open the add_to_do_tool, and replace the placeholder URL with the webhook URL from Make.com.
    • Update the code to send the to_do_text property to the webhook.
    • The sample code is as shown below:
/*
* You can use any libraries imported in Flowise
* You can use properties specified in Input Schema as variables. Ex: Property = userid, Variable = $userid
* You can get default flow config: $flow.sessionId, $flow.chatId, $flow.chatflowId, $flow.input, $flow.state
* You can get custom variables: $vars.<variable-name>
* Must return a string value at the end of function
*/
const fetch = require('node-fetch');
const webhookUrl = 'https://hook.eu1.make.com/abcdef';
const body = {
	"to_do_text": $to_do_text
};
const options = {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json'
    },
    body: JSON.stringify(body)
};
try {
    const response = await fetch(webhookUrl, options);
    const text = await response.text();
    return text;
} catch (error) {
    console.error(error);
    return '';
}

2. Restart Flowwise to apply changes.

3. Test the Complete Setup:

  • Ask the chatbot to add an item to the to-do list.
  • Verify that the item appears in your Google spreadsheet.

Conclusion

You have now created a custom tool in Flowwise that can add items to a Google Spreadsheet via a chatbot interaction. This process can be expanded to create more complex integrations and automate various tasks.

Contact us, if you need any help

For more details, visit the Documents site of Flowise AI

Admin Intelligent Web Developers

The Admin of the Intelligent Web Developer website is a web developer with over 20+ years of experience. He has a passion for web development and loves to share his knowledge with others. He has created this website to help others learn web development and to find the best resources for their needs.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.