> ## Documentation Index
> Fetch the complete documentation index at: https://dify-6c0370d8-docs-new-agent-experience.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Flomo Tool (10-min)

> Build a functional Dify tool plugin that connects to the Flomo note-taking service end-to-end in about ten minutes

## What You'll Build

By the end of this guide, you'll have created a Dify plugin that:

* Connects to the Flomo note-taking API
* Allows users to save notes from AI conversations directly to Flomo
* Handles authentication and error states properly
* Is ready for distribution in the Dify Marketplace

<CardGroup cols={2}>
  <Card title="Time required" icon="clock">
    10 minutes
  </Card>

  <Card title="Prerequisites" icon="list-check">
    Basic Python knowledge and a Flomo account
  </Card>
</CardGroup>

## Step 1: Install the Dify Plugin CLI and Create a Project

<Steps>
  <Step title="Install Dify Plugin CLI">
    <Tabs>
      <Tab title="Mac">
        ```bash theme={null}
        brew tap langgenius/dify
        brew install dify
        ```
      </Tab>

      <Tab title="Linux">
        Download the latest binary from the [Dify Plugin Daemon releases page](https://github.com/langgenius/dify-plugin-daemon/releases). Pick `dify-plugin-linux-amd64` for x86\_64 or `dify-plugin-linux-arm64` for ARM.

        ```bash theme={null}
        chmod +x dify-plugin-linux-amd64
        sudo mv dify-plugin-linux-amd64 /usr/local/bin/dify
        ```
      </Tab>
    </Tabs>

    Verify the installation:

    ```bash theme={null}
    dify version
    ```
  </Step>

  <Step title="Initialize a plugin project">
    Create a new plugin project using:

    ```bash theme={null}
    dify plugin init
    ```

    Follow the prompts to set up your plugin:

    * Name it `flomo`
    * Select `tool` as the plugin type
    * Complete the other required fields
  </Step>

  <Step title="Navigate to the project">
    ```bash theme={null}
    cd flomo
    ```

    The project contains the basic structure for your plugin with all necessary files.
  </Step>
</Steps>

## Step 2: Define Your Plugin Manifest

<Info>
  The `manifest.yaml` file defines your plugin's metadata, permissions, and capabilities.
</Info>

Create a `manifest.yaml` file:

```yaml theme={null}
version: 0.0.4
type: plugin
author: yourname
label:
  en_US: Flomo
  zh_Hans: Flomo 浮墨笔记
created_at: "2023-10-01T00:00:00Z"
icon: icon.png

resource:
  memory: 67108864  # 64MB
  permission:
    storage:
      enabled: false

plugins:
  tools:
    - provider/flomo.yaml

meta:
  version: 0.0.1
  arch:
    - amd64
    - arm64
  runner:
    language: python
    version: 3.12
    entrypoint: main
```

## Step 3: Create the Tool Definition

A tool plugin uses two YAML files: a **provider** file that declares credentials and lists the tools, and one **tool** file per callable tool. See [General Specifications](/en/develop-plugin/features-and-specs/plugin-types/general-specifications) for the full schema.

Create `provider/flomo.yaml`:

```yaml theme={null}
identity:
  author: yourname
  name: flomo
  label:
    en_US: Flomo Note
    zh_Hans: Flomo 浮墨笔记
  description:
    en_US: Add notes to your Flomo account directly from Dify.
    zh_Hans: 直接从 Dify 添加笔记到您的 Flomo 账户。
  icon: icon.png
credentials_for_provider:
  api_url:
    type: secret-input
    required: true
    label:
      en_US: API URL
      zh_Hans: API URL
    placeholder:
      en_US: https://flomoapp.com/iwh/{token}/{secret}/
    help:
      en_US: Flomo API URL from your Flomo account settings.
      zh_Hans: 从您的 Flomo 账户设置中获取的 API URL。
tools:
  - tools/flomo.yaml
extra:
  python:
    source: provider/flomo.py
```

Create `tools/flomo.yaml`:

```yaml theme={null}
identity:
  name: flomo
  author: yourname
  label:
    en_US: Save to Flomo
    zh_Hans: 保存到 Flomo
description:
  human:
    en_US: Save the conversation content as a Flomo note.
    zh_Hans: 将对话内容保存为 Flomo 笔记。
  llm: >
    Saves content to the user's Flomo account. Use this tool when the user
    asks to save, capture, or remember the current message. Takes a single
    `content` parameter containing the text to save.
parameters:
  - name: content
    type: string
    required: true
    label:
      en_US: Note content
      zh_Hans: 笔记内容
    human_description:
      en_US: Content to save as a note in Flomo.
      zh_Hans: 要保存为 Flomo 笔记的内容。
    llm_description: The text to save as a Flomo note.
    form: llm
extra:
  python:
    source: tools/flomo.py
```

## Step 4: Implement Core Utility Functions

Create a utility module in `utils/flomo_utils.py` for API interaction:

<CodeGroup>
  ```python utils/flomo_utils.py theme={null}
  import requests

  def send_flomo_note(api_url: str, content: str) -> None:
      """
      Send a note to Flomo via the API URL. Raises requests.RequestException on network errors,
      and ValueError on invalid status codes or input.
      """
      api_url = api_url.strip()
      if not api_url:
          raise ValueError("API URL is required and cannot be empty.")
      if not api_url.startswith('https://flomoapp.com/iwh/'):
          raise ValueError(
              "API URL should be in the format: https://flomoapp.com/iwh/{token}/{secret}/"
          )
      if not content:
          raise ValueError("Content cannot be empty.")
      
      headers = {'Content-Type': 'application/json'}
      response = requests.post(api_url, json={"content": content}, headers=headers, timeout=10)
      
      if response.status_code != 200:
          raise ValueError(f"API URL is not valid. Received status code: {response.status_code}")
  ```
</CodeGroup>

## Step 5: Implement the Tool Provider

The Tool Provider handles credential validation. Create `provider/flomo.py`:

<CodeGroup>
  ```python provider/flomo.py theme={null}
  from typing import Any
  from dify_plugin import ToolProvider
  from dify_plugin.errors.tool import ToolProviderCredentialValidationError
  import requests
  from utils.flomo_utils import send_flomo_note

  class FlomoProvider(ToolProvider):
      def _validate_credentials(self, credentials: dict[str, Any]) -> None:
          try:
              api_url = credentials.get('api_url', '').strip()
              # Use utility for validation and sending test note
              send_flomo_note(api_url, "Hello, #flomo https://flomoapp.com")
          except ValueError as e:
              raise ToolProviderCredentialValidationError(str(e))
          except requests.RequestException as e:
              raise ToolProviderCredentialValidationError(f"Connection error: {str(e)}")
  ```
</CodeGroup>

## Step 6: Implement the Tool

The Tool class handles actual API calls when the user invokes the plugin. Create `tools/flomo.py`:

<CodeGroup>
  ```python tools/flomo.py theme={null}
  from collections.abc import Generator
  from typing import Any
  from dify_plugin import Tool
  from dify_plugin.entities.tool import ToolInvokeMessage
  import requests
  from utils.flomo_utils import send_flomo_note

  class FlomoTool(Tool):
      def _invoke(self, tool_parameters: dict[str, Any]) -> Generator[ToolInvokeMessage]:
          content = tool_parameters.get("content", "")
          api_url = self.runtime.credentials.get("api_url", "")
          
          try:
              send_flomo_note(api_url, content)
          except ValueError as e:
              yield self.create_text_message(str(e))
              return
          except requests.RequestException as e:
              yield self.create_text_message(f"Connection error: {str(e)}")
              return
              
          # Return success message and structured data
          yield self.create_text_message(
              "Note created successfully! Your content has been sent to Flomo."
          )
          yield self.create_json_message({
              "status": "success",
              "content": content,
          })
  ```
</CodeGroup>

<Warning>
  Always handle exceptions gracefully and return user-friendly error messages. Remember that your plugin represents your brand in the Dify ecosystem.
</Warning>

## Step 7: Test Your Plugin

<Steps>
  <Step title="Set up debug environment">
    Copy the example environment file:

    ```bash theme={null}
    cp .env.example .env
    ```

    Edit the `.env` file with your Dify environment details:

    ```bash theme={null}
    INSTALL_METHOD=remote
    REMOTE_INSTALL_URL=debug-plugin.dify.dev:5003
    REMOTE_INSTALL_KEY=your_debug_key
    ```

    You can find your debug URL and key in the Dify dashboard: click the **Plugins** icon in the top-right corner, then click the debug icon. Copy the **API Key** and **Host Address** (the host already includes the port).
  </Step>

  <Step title="Install dependencies and run">
    ```bash theme={null}
    pip install -r requirements.txt
    python -m main
    ```

    Your plugin will connect to your Dify instance in debug mode.
  </Step>

  <Step title="Test functionality">
    In your Dify instance, open the **Plugins** page and find your plugin (marked as **debugging**). Add your Flomo API credentials and test sending a note.
  </Step>
</Steps>

## Step 8: Package and Distribute

When you're ready to share your plugin:

```bash theme={null}
dify plugin package ./
```

This creates a `plugin.difypkg` file you can upload to the Dify Marketplace.

## FAQ and Troubleshooting

<AccordionGroup title="Common issues and troubleshooting">
  <Accordion title="Plugin doesn't appear in debug mode">
    Make sure your `.env` file is properly configured and you're using the correct debug key.
  </Accordion>

  <Accordion title="API authentication errors">
    Double-check your Flomo API URL format. It should be in the form: `https://flomoapp.com/iwh/{token}/{secret}/`
  </Accordion>

  <Accordion title="Packaging fails">
    Ensure all required files are present and the `manifest.yaml` structure is valid.
  </Accordion>
</AccordionGroup>

## Summary

You've built a functioning Dify plugin that connects with an external API service. The same pattern works for integrating with thousands of services—from databases and search engines to productivity tools and custom APIs.

<CardGroup cols={2}>
  <Card title="Documentation" icon="book">
    Write your `README.md` in English (en\_US) describing functionality, setup, and usage examples
  </Card>

  <Card title="Localization" icon="language">
    Create additional README files like `readme/README_zh_Hans.md` for other languages
  </Card>
</CardGroup>

<CheckList>
  <CheckListItem id="privacy">
    Add a privacy policy (PRIVACY.md) if publishing your plugin
  </CheckListItem>

  <CheckListItem id="documentation">
    Include comprehensive examples in documentation
  </CheckListItem>

  <CheckListItem id="testing">
    Test thoroughly with various document sizes and formats
  </CheckListItem>
</CheckList>
