Skip to content

Commit

Permalink
Merge branch 'master' of github.com:hanfangyuan4396/dify-on-wechat in…
Browse files Browse the repository at this point in the history
…to master
  • Loading branch information
hanfangyuan4396 committed Jan 3, 2025
2 parents 7d05d56 + aa883ee commit b08c13c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions bridge/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ContextType(Enum):
PATPAT = 21 # 拍了拍
FUNCTION = 22 # 函数调用
EXIT_GROUP = 23 #退出
SYS_NOTICE = 51 # 系统通知


def __str__(self):
Expand Down
13 changes: 12 additions & 1 deletion channel/gewechat/gewechat_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import web
from urllib.parse import urlparse

from bridge.context import Context
from bridge.context import Context, ContextType
from bridge.reply import Reply, ReplyType
from channel.chat_channel import ChatChannel
from channel.gewechat.gewechat_message import GeWeChatMessage
Expand Down Expand Up @@ -179,6 +179,17 @@ def POST(self):

gewechat_msg = GeWeChatMessage(data, channel.client)

# 忽略(可能是)系统通知的消息 TODO:待验证
if gewechat_msg.ctype == ContextType.SYS_NOTICE:
logger.info(f"[gewechat] ignore system notice message")
return "success"

# 根据微信原始id规律,暂时通过"wxid_"开头判断是用户消息,其他一律判断为公众号或其他非用户消息
# TODO:微信曾开放过修改原始id的权限,可能存在不是"wxid_"开头的用户消息,存在误判
if not gewechat_msg.actual_user_id or not gewechat_msg.actual_user_id.startswith("wxid_"):
logger.info(f"[gewechat] ignore message from non-user account: {gewechat_msg.actual_user_id}, content: {gewechat_msg.content}")
return "success"

context = channel._compose_context(
gewechat_msg.ctype,
gewechat_msg.content,
Expand Down
5 changes: 5 additions & 0 deletions channel/gewechat/gewechat_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ def __init__(self, msg, client: GewechatClient):
else:
self.ctype = ContextType.TEXT
self.content = content_xml
elif msg_type == 51:
# TODO:推测可能是系统通知,待进一步测试
self.ctype = ContextType.SYS_NOTICE
self.content = "[系统状态通知]"
return
else:
raise NotImplementedError("Unsupported message type: Type:{}".format(msg_type))

Expand Down

0 comments on commit b08c13c

Please sign in to comment.