Skip to content

Commit

Permalink
Merge pull request RockChinQ#1154 from Yi-Lyu/master
Browse files Browse the repository at this point in the history
将微信消息时间戳传递给 dify,便于 dify 通过消息时间戳来做业务逻辑。
  • Loading branch information
RockChinQ authored Mar 2, 2025
2 parents 98a9fed + 92e1ac5 commit faecb70
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pkg/platform/sources/dingtalk.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async def target2yiri(
remark=""
),
message_chain = message_chain,
time = datetime.datetime.now(),
time = event.incoming_message.create_at,
source_platform_object=event,
)
elif event.conversation == 'GroupMessage':
Expand All @@ -95,7 +95,7 @@ async def target2yiri(
last_speak_timestamp=0,
mute_time_remaining=0
)
time = datetime.datetime.now(),
time = event.incoming_message.create_at
return platform_events.GroupMessage(
sender =sender,
message_chain = message_chain,
Expand Down
18 changes: 15 additions & 3 deletions pkg/platform/sources/qqofficial.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ async def target2yiri(event:QQOfficialEvent):
remark = "",
)
return platform_events.FriendMessage(
sender = friend,message_chain = yiri_chain,time = event.timestamp,
sender = friend,message_chain = yiri_chain,time = int(
datetime.datetime.strptime(
event.timestamp, "%Y-%m-%dT%H:%M:%S%z"
).timestamp()
),
source_platform_object=event
)

Expand Down Expand Up @@ -105,7 +109,11 @@ async def target2yiri(event:QQOfficialEvent):
last_speak_timestamp=0,
mute_time_remaining=0
)
time = event.timestamp
time = int(
datetime.datetime.strptime(
event.timestamp, "%Y-%m-%dT%H:%M:%S%z"
).timestamp()
)
return platform_events.GroupMessage(
sender = sender,
message_chain=yiri_chain,
Expand All @@ -128,7 +136,11 @@ async def target2yiri(event:QQOfficialEvent):
last_speak_timestamp=0,
mute_time_remaining=0
)
time = event.timestamp,
time = int(
datetime.datetime.strptime(
event.timestamp, "%Y-%m-%dT%H:%M:%S%z"
).timestamp()
),
return platform_events.GroupMessage(
sender =sender,
message_chain = yiri_chain,
Expand Down
3 changes: 3 additions & 0 deletions pkg/platform/types/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class MessageEvent(Event):
message_chain: platform_message.MessageChain
"""消息内容。"""

time: float | None = None
"""消息发送时间戳。"""

source_platform_object: typing.Optional[typing.Any] = None
"""原消息平台对象。
供消息平台适配器开发者使用,如果回复用户时需要使用原消息事件对象的信息,
Expand Down
6 changes: 6 additions & 0 deletions pkg/provider/runners/difysvapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import uuid
import re
import base64
import datetime

import aiohttp

Expand Down Expand Up @@ -69,6 +70,7 @@ async def _preprocess_user_message(
"""
plain_text = ""
image_ids = []

if isinstance(query.user_message.content, list):
for ce in query.user_message.content:
if ce.type == "text":
Expand Down Expand Up @@ -230,6 +232,9 @@ async def _workflow_messages(

plain_text, image_ids = await self._preprocess_user_message(query)

# 尝试获取 CreateTime
create_time = int(query.message_event.time) if query.message_event.time else int(datetime.datetime.now().timestamp())

files = [
{
"type": "image",
Expand All @@ -246,6 +251,7 @@ async def _workflow_messages(
"langbot_user_message_text": plain_text,
"langbot_session_id": f"{query.session.launcher_type.value}_{query.session.launcher_id}",
"langbot_conversation_id": cov_id,
"langbot_msg_create_time": create_time,
},
user=f"{query.session.launcher_type.value}_{query.session.launcher_id}",
files=files,
Expand Down

0 comments on commit faecb70

Please sign in to comment.