MCPcopy Index your code
hub / github.com/LeslieLeung/dify-connector

github.com/LeslieLeung/dify-connector @v0.1.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.1.2 ↗ · + Follow
194 symbols 430 edges 37 files 22 documented · 11%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

dify-connector

English | 简体中文

dify-connector 是一个将 Dify 发布到各种 IM 平台的工具。

特性

  • 将 Dify 应用发布到各种 IM 平台(Discord, 钉钉等)
  • ✅Discord
  • ✅钉钉
  • (计划中) Telegram
  • 更多...(欢迎 PR)
  • 提供 OpenAI 兼容的 API
  • 作为 Dify 的 Go SDK 使用
  • (计划中) 管理控制台,用于管理 IM 频道和 Dify 应用
  • (计划中) 为 Dify 应用提供内容审查 API

部署

开始之前

你应该在 Discord 或者钉钉中创建一个机器人,并获取机器人的凭证。

如果你不知道如何获取凭证,互联网和官方文档是你的朋友。

其他前提条件:

  • 一个 Dify 实例(你可以使用官方实例)
  • 一个 MySQL 8.0 数据库(你可以使用其他数据库,只要它被 GORM 支持)

Docker Compose(推荐)

你应该在你的服务器上安装 Docker 和 Docker Compose。

git clone https://github.com/leslieleung/dify-connector.git
docker-compose up -d

Docker

你应该在你的服务器上安装 Docker。并且你应该准备好一个数据库(推荐 MySQL 8.0)。

docker run -d --name dify-connector -e DATABASE_DSN=<YOUR_DSN> -e BOOTSTRAP_CHANNEL=<YOUR_CHANNEL> leslieleung/dify-connector:latest

命令

  • help: 显示帮助信息
  • app: 管理 Dify 应用
  • add: 添加一个 Dify 应用。用法: app add name type base_url api_key
  • list: 列出所有 Dify 应用。
  • remove: 移除一个 Dify 应用。用法: app remove id
  • toggle: 切换一个 Dify 应用。用法: app toggle id
  • use: 使用一个 Dify 应用。用法: app use id

Dify SDK

阻塞模式

package main

import (
  "errors"
  "github.com/google/uuid"
  "github.com/leslieleung/dify-connector/pkg/dify"
  "io"
)

func main() {
    client := dify.New("https://api.dify.ai", "app-xxx")
    client.SetDebug()

    text := "Hello, how are you?"

    req := dify.CompletionMessageRequest{
        Inputs: map[string]interface{}{
        "query": text,
        },
        User: uuid.New().String(),
    }

    resp, err := client.CompletionMessage(req)
    if err != nil {
        panic(err)
    }
    print(resp.Answer)
}

流式模式

package main

import (
  "errors"
  "github.com/google/uuid"
  "github.com/leslieleung/dify-connector/pkg/dify"
  "io"
)

func main() {
  client := dify.New("https://api.dify.ai", "app-xxx")
  client.SetDebug()

  text := "Hello, how are you?"

  req := dify.CompletionMessageRequest{
    Inputs: map[string]interface{}{
      "query": text,
    },
    User: uuid.New().String(),
  }

  resp, err := client.CompletionMessageStreaming(req)
  if err != nil {
    panic(err)
  }
  for {
    r, err := resp.Recv()
    if err != nil {
      if errors.Is(err, io.EOF) {
        break
      }
    }
    if r.Answer != "" {
      print(r.Answer)
    }
  }
}

Extension points exported contracts — how you extend this code

Command (Interface)
(no doc) [3 implementers]
internal/command/command.go
Channel (Interface)
(no doc) [2 implementers]
internal/channel/channel.go
Unmarshaler (Interface)
(no doc) [1 implementers]
pkg/dify/stream.go
Option (FuncType)
(no doc)
internal/log/log.go
Option (FuncType)
(no doc)
internal/hub/hub.go
ErrorAccumulator (Interface)
(no doc) [1 implementers]
pkg/dify/stream.go

Core symbols most depended-on inside this repo

GetDB
called by 15
internal/database/db.go
Error
called by 7
pkg/dify/typedef.go
Unmarshal
called by 6
pkg/dify/stream.go
Close
called by 4
pkg/dify/stream.go
Wait
called by 4
pkg/dify/stream.go
New
called by 3
pkg/dify/dify.go
SetDebug
called by 3
pkg/dify/dify.go
Execute
called by 3
internal/command/command.go

Shape

Function 75
Method 57
Struct 53
Interface 6
FuncType 2
TypeAlias 1

Languages

Go100%

Modules by API surface

pkg/dify/typedef.go28 symbols
pkg/dify/stream.go23 symbols
pkg/dify/dify.go20 symbols
internal/log/log.go14 symbols
internal/command/app.go10 symbols
internal/command/command.go8 symbols
internal/channel/discord.go7 symbols
internal/channel/dingtalk.go7 symbols
internal/hub/hub.go6 symbols
internal/database/channel.go6 symbols
internal/database/app.go6 symbols
internal/command/chat.go5 symbols

Datastores touched

(mysql)Database · 1 repos

For agents

$ claude mcp add dify-connector \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page