@dcrays/dcgchat-test 0.4.21 → 0.4.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/channel.ts +26 -2
package/package.json
CHANGED
package/src/channel.ts
CHANGED
|
@@ -8,7 +8,8 @@ import {
|
|
|
8
8
|
getDcgchatRuntime,
|
|
9
9
|
getInfoBySessionKey,
|
|
10
10
|
getOpenClawConfig,
|
|
11
|
-
hasSentMediaKey
|
|
11
|
+
hasSentMediaKey,
|
|
12
|
+
setCronMessageId
|
|
12
13
|
} from './utils/global.js'
|
|
13
14
|
import { isWsOpen, mergeDefaultParams, mergeSessionParams, sendFinal, wsSendRaw } from './transport.js'
|
|
14
15
|
import { dcgLogger, setLogger } from './utils/log.js'
|
|
@@ -103,10 +104,30 @@ function outboundChatId(rawTo: string | undefined, normalizedTo: string): string
|
|
|
103
104
|
}
|
|
104
105
|
|
|
105
106
|
export async function sendDcgchatMedia(opts: DcgchatMediaSendOptions): Promise<void> {
|
|
107
|
+
const rawOpt = (opts.sessionKey ?? '').trim()
|
|
108
|
+
const strippedForCron = rawOpt.replace(/^dcg-cron:/i, '').trim()
|
|
109
|
+
const fromIsolatedCron = extractCronJobIdFromIsolatedSessionKey(strippedForCron) !== null
|
|
110
|
+
const fromDcgCronWrapper = rawOpt.toLowerCase().startsWith('dcg-cron:')
|
|
111
|
+
|
|
106
112
|
let sessionKey = normalizeSessionTarget(opts.sessionKey ?? '')
|
|
107
113
|
sessionKey = resolveIsolatedCronSessionToJobSessionKey(sessionKey)
|
|
114
|
+
|
|
115
|
+
/** 定时自动执行未走 onRunCronJob,须与 finishedDcgchatCron 共用同一 messageId,否则附件与气泡错位 */
|
|
116
|
+
if (
|
|
117
|
+
!opts.messageId?.trim() &&
|
|
118
|
+
(fromIsolatedCron || fromDcgCronWrapper) &&
|
|
119
|
+
!getCronMessageId(sessionKey)
|
|
120
|
+
) {
|
|
121
|
+
setCronMessageId(sessionKey, `${Date.now()}`)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const cronMid = getCronMessageId(sessionKey)
|
|
108
125
|
const baseCtx = getOutboundMsgParams(sessionKey)
|
|
109
|
-
const msgCtx = opts.messageId?.trim()
|
|
126
|
+
const msgCtx = opts.messageId?.trim()
|
|
127
|
+
? { ...baseCtx, messageId: opts.messageId.trim() }
|
|
128
|
+
: cronMid
|
|
129
|
+
? { ...baseCtx, messageId: cronMid }
|
|
130
|
+
: baseCtx
|
|
110
131
|
if (!isWsOpen()) {
|
|
111
132
|
dcgLogger(`outbound media skipped -> ws not isWsOpen failed open: ${opts.mediaUrl ?? ''}`)
|
|
112
133
|
return
|
|
@@ -326,6 +347,9 @@ export const dcgchatPlugin: ChannelPlugin<ResolvedDcgchatAccount> = {
|
|
|
326
347
|
const to = resolveIsolatedCronSessionToJobSessionKey(normalizedFromTo)
|
|
327
348
|
const outboundCtx = getOutboundMsgParams(to)
|
|
328
349
|
const msgCtx = getParamsMessage(to) ?? outboundCtx
|
|
350
|
+
if (isCron && !getCronMessageId(to)) {
|
|
351
|
+
setCronMessageId(to, `${Date.now()}`)
|
|
352
|
+
}
|
|
329
353
|
const cronMsgId = getCronMessageId(to)
|
|
330
354
|
const fallbackMessageId = `${Date.now()}`
|
|
331
355
|
const messageId = cronMsgId || (isCron ? fallbackMessageId : msgCtx?.messageId || fallbackMessageId)
|