diff --git a/README.md b/README.md index abbe478c0..6a256fb18 100644 --- a/README.md +++ b/README.md @@ -10,15 +10,19 @@ Dify接入微信生态的**详细教程**请查看文章 [**手摸手教你把 D 如果我的项目对您有帮助请点一个star吧~ +
+ +
- -![image-1](./docs/images/image1.jpg) - -![image-2](./docs/images/image2.jpg) +
+ +
基本的dify workflow api支持 -![image-3](./docs/images/image4.jpg) +
+ +
目前Dify已经测试过的通道如下: @@ -34,12 +38,17 @@ Dify接入微信生态的**详细教程**请查看文章 [**手摸手教你把 D # 交流群 +
+ ||| |:-:|:-:| |添加我的微信拉你进交流群|开源不易,感谢打赏🎉| +
+ # 最新功能 + ## 1. 支持gewechat登录微信 基于[Gewechat](https://github.com/Devo919/Gewechat)项目实现的微信个人号通道,使用ipad协议登录,相比itchat协议更稳定。 @@ -83,11 +92,23 @@ python app.py ``` 启动成功后,可以看到如下日志信息,注意token和appid会**自动保存**到config.json,无需手动保存 -![gewechat_login](./docs/gewechat/gewechat_login.jpg) +
+ +
+## 2. 用户信息对接dify + +新增用户信息对接dify的能力,会把用户id、用户名称、群聊id、群聊名称信息传递给dify,搭配 gewechat_channel 提供的wxid与chatroomid, +可以在dify中识别出每个用户,实现个性化服务。详细教程请查看:[用户信息对接dify](./docs/user-info/README.md) + +
+ +
## 2. 支持企业微信个人号(仅支持windows系统) -![wework](./docs/images/wework.jpg) +
+ +
> 1. 有**封号风险**,请使用企业微信**小号**测试 > 2. 在登录旧版本的企业微信时可能会出现企业微信版本过低,无法登录情况,参考[issue1525](https://github.com/zhayujie/chatgpt-on-wechat/issues/1525),请尝试更换其他企业微信号重试 @@ -160,8 +181,13 @@ python app.py ## 3. 集成[JinaSum](https://github.com/hanfangyuan4396/jina_sum)插件 使用Jina Reader和ChatGPT支持总结公众号、小红书、知乎等分享卡片链接,配置详情请查看[JinaSum](https://github.com/hanfangyuan4396/jina_sum) -![plugin-jinasum-1](./plugins/jina_sum/docs/images/wechat_mp.jpg) -![plugin-jinasum-1](./plugins/jina_sum/docs/images/red.jpg) +
+ +
+ +
+ +
## 4. 新增[CustomDifyApp](https://github.com/hanfangyuan4396/dify-on-wechat/tree/master/plugins/custom_dify_app)插件 支持根据群聊名称关键词自动切换不同的Dify应用,也支持为单聊配置专门的Dify应用。 @@ -176,11 +202,13 @@ dify官网已正式上线工作流模式,可以导入本项目下的[dsl文件 (ps: 感觉工作流类型应用不太适合作为聊天机器人,现在它还没有会话的概念,需要自己管理上下文。但是它可以调用各种工具,通过http请求和外界交互,适合执行业务逻辑复杂的任务;它可以导入导出工作流dsl文件,方便分享移植。也许以后dsl文件+配置文件就可以作为本项目的一个插件。) ## 6. 支持COZE API -![image-5](./docs/images/image5.jpg) - -![image-6](./docs/images/image6.jpg) - +
+ +
+
+ +
### 6.1 如何快速启动coze微信机器人 @@ -233,6 +261,7 @@ dify语音相关配置如下,另外需要在dify应用中开启语音转文字 ``` # 更新日志 +- 2024/12/14 支持用户信息对接dify - 2024/12/04 新增 [gewechat](https://github.com/Devo919/Gewechat) 通道,相比itchat更稳定。 - 2024/10/01 新增插件CustomDifyApp与GroupAtAutoreply,CustomDifyApp支持根据群聊名称关键词自动切换不同的Dify应用,GroupAtAutoreply支持群聊艾特自动回复,贡献者[**blankbro**](https://github.com/blankbro) - 2024/09/18 支持dify voice @@ -377,5 +406,4 @@ docker logs -f dify-on-wechat # 查看二维码并登录 感谢 **NLP工程化** 知识星球对本项目的支持 - (提供Dify源码剖析及答疑,Dify对话系统源码等) diff --git a/channel/gewechat/README.md b/channel/gewechat/README.md new file mode 100644 index 000000000..beb15a603 --- /dev/null +++ b/channel/gewechat/README.md @@ -0,0 +1,132 @@ +# 1. gewechat channel简介 + +Gewechat channel是基于[Gewechat](https://github.com/Devo919/Gewechat)项目实现的微信个人号通道,使用ipad协议登录,该协议能获取到wxid,能发送语音条消息,相比itchat协议更稳定。 + +api文档地址为:[gewechat api](https://apifox.com/apidoc/shared-69ba62ca-cb7d-437e-85e4-6f3d3df271b1/api-197179336) + +# 2. gewechat 服务部署教程 + +gewechat 服务需要自行部署,[dify-on-wechat](https://github.com/hanfangyuan4396/dify-on-wechat) 项目只负责对接gewechat服务,请参考下方教程部署gewechat服务。 + +## 2.1 下载镜像 + +感谢gewechat交流群中的大佬 `@1H` 重构了镜像,让gewe镜像不依赖cgroup和docker --privilege,可以在更高版本的ubuntu、debian以及macos系统上运行。 + +```bash +# 从阿里云镜像仓库拉取(国内) +docker pull registry.cn-chengdu.aliyuncs.com/tu1h/wechotd:alpine +docker tag registry.cn-chengdu.aliyuncs.com/tu1h/wechotd:alpine gewe + +# 或从GitHub镜像仓库拉取 +docker pull ghcr.io/tu1h/wechotd/wechotd:alpine +docker tag ghcr.io/tu1h/wechotd/wechotd:alpine gewe +``` + +## 2.2 使用docker启动 + +```bash +mkdir -p gewechat/data +docker run -itd -v gewechat/data:/root/temp -p 2531:2531 -p 2532:2532 --restart=always --name=gewe gewe +``` + +## 2.3 使用docker compose启动 + +首先创建必要的数据目录: + +```bash +mkdir -p gewechat/data +``` + +创建 `docker-compose.yml` 文件: + +```yaml +version: '3' +services: + gewechat: + image: gewe + container_name: gewe + volumes: + - ./gewechat/data:/root/temp + ports: + - "2531:2531" + - "2532:2532" + restart: always +``` + +运行: +```bash +docker compose up -d +``` + +## 2.4 成功日志 + +看到如下日志,表示gewechat服务启动成功 + +
+ +
+ +# 3. 使用dify-on-wechat对接gewechat服务 + +## 3.1 gewechat相关参数配置 + +在config.json中需要配置以下gewechat相关的参数: + +```bash +{ + "channel_type": "gewechat" # 通道类型,请设置为gewechat + "gewechat_token": "", # gewechat服务的token,用于接口认证 + "gewechat_app_id": "", # gewechat服务的应用ID + "gewechat_base_url": "http://本机ip:2531/v2/api", # gewechat服务的API基础URL + "gewechat_callback_url": "http://本机ip:9919/v2/api/callback/collect", # 回调URL,用于接收消息 + "gewechat_download_url": "http://本机ip:2532/download", # 文件下载URL +} +``` + +参数说明: +- `gewechat_token`: gewechat服务的认证token,首次登录时,可以留空,启动dify-on-wechat服务时,会**自动获取token**并**自动保存到config.json**中 +- `gewechat_app_id`: gewechat服务分配的设备ID,首次登录时,可以留空,启动dify-on-wechat服务时,会**自动获取appid**并**自动保存到config.json**中 +- `gewechat_base_url`: gewechat服务的API基础地址,请根据实际情况配置,如果gewechat服务与dify-on-wechat服务部署在同一台机器上,可以配置为`http://本机ip:2531/v2/api` +- `gewechat_callback_url`: 接收gewechat消息的回调地址,请根据实际情况配置,如果gewechat服务与dify-on-wechat服务部署在同一台机器上,可以配置为`http://本机ip:9919/v2/api/callback/collect`,如无特殊需要,请使用9919端口号 +- `gewechat_download_url`: 文件下载地址,用于下载语音、图片等文件,请根据实际部署情况配置,如果gewechat服务与dify-on-wechat服务部署在同一台机器上,可以配置为`http://本机ip:2532/download` + +注意:请确保您的回调地址(callback_url),即dify-on-wechat启动的回调服务可以被gewechat服务正常访问到。如果您使用Docker部署,需要注意网络配置,确保容器之间可以正常通信。 + +## 3.2 dify相关参数配置 + +在config.json中需要配置以下dify相关参数: + +```bash +{ + "dify_api_base": "https://api.dify.ai/v1", # dify base url + "dify_api_key": "app-xxx", # dify api key + "dify_app_type": "chatbot", # dify应用类型,对应聊天助手 + "channel_type": "gewechat", # 通道类型设置为gewechat + "model": "dify", # 模型名称设置为dify + "single_chat_prefix": [""], # 私聊触发前缀 + "single_chat_reply_prefix": "", # 私聊回复前缀 + "group_chat_prefix": ["@bot"], # 群聊触发前缀 + "group_name_white_list": ["ALL_GROUP"], # 允许响应的群组 +} +``` + +关于dify_api_base、dify_api_key等参数的获取方法,请参考文章 [手摸手教你把 Dify 接入微信生态](https://docs.dify.ai/v/zh-hans/learn-more/use-cases/dify-on-wechat)。 + +## 3.3 启动dify-on-wechat服务 + +完成上述配置后,你需要确保gewechat服务已正常启动,dify-on-wechat的依赖已安装(见 [dify-on-wechat项目README](https://github.com/hanfangyuan4396/dify-on-wechat) 或 [手摸手教你把 Dify 接入微信生态](https://docs.dify.ai/v/zh-hans/learn-more/use-cases/dify-on-wechat) ),然后运行以下命令启动服务: + +```bash +python app.py +``` +启动成功后,可以看到如下日志信息,注意token和appid会自动保存到config.json,无需手动保存 + +
+ +
+ +# 4. gewechat_channel 服务的限制 +1. gewechat 要求必须搭建服务到**同省**服务器或者电脑里方可正常使用,即登录微信的手机与gewechat服务必须在同一省 +2. gewechat 开源框架**只支持**下载接收到的图片,不支持下载文件 +3. gewechat_channel 目前暂时**只支持接收文字消息**,**只支持发送文字消息与图片消息**,后续支持的消息类型会逐步完善 +4. 此项目仅用于个人娱乐场景,请**勿用于任何商业场景** diff --git a/docs/gewechat/README.md b/docs/gewechat/README.md index 00b1586c9..f693cc917 100644 --- a/docs/gewechat/README.md +++ b/docs/gewechat/README.md @@ -62,7 +62,9 @@ docker compose up -d 看到如下日志,表示gewechat服务启动成功 -![gewechat_service_success](./gewechat_service_success.jpg) +
+ +
# 3. 使用dify-on-wechat对接gewechat服务 @@ -119,7 +121,9 @@ python app.py ``` 启动成功后,可以看到如下日志信息,注意token和appid会自动保存到config.json,无需手动保存 -![gewechat_login](./gewechat_login.jpg) +
+ +
# 4. gewechat_channel 服务的限制 1. gewechat 要求必须搭建服务到**同省**服务器或者电脑里方可正常使用,即登录微信的手机与gewechat服务必须在同一省 diff --git a/docs/user-info/README.md b/docs/user-info/README.md new file mode 100644 index 000000000..9ef80a0b5 --- /dev/null +++ b/docs/user-info/README.md @@ -0,0 +1,65 @@ +# 用户信息对接dify + +## 1. 简介 + +新增用户信息对接dify的能力,会把用户id、用户名称、群聊id、群聊名称信息传递给dify,搭配 [**gewechat_channel**](../gewechat/README.md) 提供的wxid与chatroomid, +可以在dify中识别出每个用户,实现个性化服务。 + +此功能参考了 [wechat-assistant-pro](https://github.com/leochen-g/wechat-assistant-pro/issues/76) + +## 2.快速开始 + +### 2.1 创建Dify应用 + +下载提供的 [用户信息.yml](../../dsl/用户信息.yml) 文件,在Dify中通过导入DSL文件的方式创建应用,如下图所示: + +
+ +
+ +### 2.2 添加用户信息变量 + +如下图所示,在刚刚创建的应用中,已经预先创建了`user_id`、`user_name`、`room_id`、`room_name`变量,在工作流中可以使用这些变量来唯一标识用户或获取用户信息,从而实现对不同用户的个性化服务。 + +
+ +
+ +你可以在自己创建的工作流中添加上述4个变量,但是在配置变量时,需要注意: +1. 保证变量名一致 +2. 最大长度设置大一些,推荐128 +3. **取消**勾选必填 + +### 2.3 发布应用,启动dify-on-wechat服务 + +发布此应用,并获取dify_api_base、dify_api_key,详情请参考[**手摸手教你把 Dify 接入微信生态**](https://docs.dify.ai/v/zh-hans/learn-more/use-cases/dify-on-wechat),不再赘述。 + +在dify-on-wechat的config.json中需要配置以下dify相关参数: + +```bash +{ + "dify_api_base": "https://api.dify.ai/v1", # dify base url + "dify_api_key": "app-xxx", # dify api key + "dify_app_type": "chatbot", # dify应用类型,对应聊天助手 + "channel_type": "gewechat", # 通道类型设置为gewechat + "model": "dify", # 模型名称设置为dify + "single_chat_prefix": [""], # 私聊触发前缀 + "single_chat_reply_prefix": "", # 私聊回复前缀 + "group_chat_prefix": ["@bot"], # 群聊触发前缀 + "group_name_white_list": ["ALL_GROUP"], # 允许响应的群组 +} +``` + +上述的channel_type使用了 **gewechat**,gewechat_channel 的使用方法请参考 [**gewechat_channel**](../gewechat/README.md) + +### 2.4 接收用户信息测试 + +分别测试私聊和群聊,在下图中可以看到能够正常获取到用户信息并返回。 + +
+ +
+ +
+ +
\ No newline at end of file diff --git a/docs/user-info/import-user-info-dsl.jpg b/docs/user-info/import-user-info-dsl.jpg new file mode 100644 index 000000000..0fda8fd9b Binary files /dev/null and b/docs/user-info/import-user-info-dsl.jpg differ diff --git a/docs/user-info/user-info-fields.jpg b/docs/user-info/user-info-fields.jpg new file mode 100644 index 000000000..744dd3415 Binary files /dev/null and b/docs/user-info/user-info-fields.jpg differ diff --git a/docs/user-info/user-info-room.jpg b/docs/user-info/user-info-room.jpg new file mode 100644 index 000000000..84624de3a Binary files /dev/null and b/docs/user-info/user-info-room.jpg differ diff --git a/docs/user-info/user-info-single.jpg b/docs/user-info/user-info-single.jpg new file mode 100644 index 000000000..c655b7800 Binary files /dev/null and b/docs/user-info/user-info-single.jpg differ diff --git "a/dsl/\347\224\250\346\210\267\344\277\241\346\201\257.yml" "b/dsl/\347\224\250\346\210\267\344\277\241\346\201\257.yml" new file mode 100644 index 000000000..900412c60 --- /dev/null +++ "b/dsl/\347\224\250\346\210\267\344\277\241\346\201\257.yml" @@ -0,0 +1,146 @@ +app: + description: '' + icon: 🤖 + icon_background: '#FFEAD5' + mode: advanced-chat + name: 用户信息 + use_icon_as_answer_icon: false +kind: app +version: 0.1.4 +workflow: + conversation_variables: [] + environment_variables: [] + features: + file_upload: + allowed_file_extensions: + - .JPG + - .JPEG + - .PNG + - .GIF + - .WEBP + - .SVG + allowed_file_types: + - image + allowed_file_upload_methods: + - local_file + - remote_url + enabled: false + fileUploadConfig: + audio_file_size_limit: 50 + batch_count_limit: 5 + file_size_limit: 15 + image_file_size_limit: 10 + video_file_size_limit: 100 + workflow_file_upload_limit: 10 + image: + enabled: false + number_limits: 3 + transfer_methods: + - local_file + - remote_url + number_limits: 3 + opening_statement: '' + retriever_resource: + enabled: true + sensitive_word_avoidance: + enabled: false + speech_to_text: + enabled: false + suggested_questions: [] + suggested_questions_after_answer: + enabled: false + text_to_speech: + enabled: false + language: '' + voice: '' + graph: + edges: + - data: + isInIteration: false + sourceType: start + targetType: answer + id: 1734151208078-source-answer-target + source: '1734151208078' + sourceHandle: source + target: answer + targetHandle: target + type: custom + zIndex: 0 + nodes: + - data: + desc: '' + selected: false + title: 开始 + type: start + variables: + - label: 用户id + max_length: 128 + options: [] + required: false + type: text-input + variable: user_id + - label: 用户名称 + max_length: 128 + options: [] + required: false + type: text-input + variable: user_name + - label: 群聊id + max_length: 128 + options: [] + required: false + type: text-input + variable: room_id + - label: 群聊名称 + max_length: 128 + options: [] + required: false + type: text-input + variable: room_name + height: 167 + id: '1734151208078' + position: + x: 428 + y: 215 + positionAbsolute: + x: 428 + y: 215 + selected: true + sourcePosition: right + targetPosition: left + type: custom + width: 243 + - data: + answer: '用户id:{{#1734151208078.user_id#}} + + 用户名称:{{#1734151208078.user_name#}} + + 群聊id:{{#1734151208078.room_id#}} + + 群聊名称:{{#1734151208078.room_name#}} + + 收到消息:{{#sys.query#}} + + ' + desc: '' + selected: false + title: 直接回复 + type: answer + variables: [] + height: 178 + id: answer + position: + x: 793 + y: 298 + positionAbsolute: + x: 793 + y: 298 + selected: false + sourcePosition: right + targetPosition: left + type: custom + width: 243 + viewport: + x: 54 + y: 62 + zoom: 1 diff --git a/plugins/jina_sum/README.md b/plugins/jina_sum/README.md index 88ca7cf66..22f4f2352 100644 --- a/plugins/jina_sum/README.md +++ b/plugins/jina_sum/README.md @@ -3,9 +3,17 @@ ChatGPT on WeChat项目插件, 使用jina reader和ChatGPT总结网页链接内 支持总结公众号、小红书、csdn等分享卡片链接(有的卡片链接会触发验证,一般直链没有此问题) -![wechat_mp](./docs/images/wechat_mp.jpg) -![red](./docs/images/red.jpg) -![csdn](./docs/images/csdn.jpg) +
+ +
+ +
+ +
+ +
+ +
config.json 配置说明 ```bash