@dcrays/dcgchat 0.3.30 → 0.3.31
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 +2 -2
- package/src/bot.ts +10 -1
- package/src/channel.ts +20 -7
package/package.json
CHANGED
package/src/bot.ts
CHANGED
|
@@ -180,8 +180,11 @@ export async function handleDcgchatMessage(msg: InboundMessage, accountId: strin
|
|
|
180
180
|
}
|
|
181
181
|
setParamsMessage(effectiveSessionKey, mergedParams)
|
|
182
182
|
// 与 OpenClaw 会话投递里仍可能出现的 ctx.to=SenderId(userId)对齐,便于 getOutboundMsgParams 命中
|
|
183
|
-
|
|
183
|
+
dcgLogger(
|
|
184
|
+
`target normalize: rawTarget=${userId}, normalizedTarget=${effectiveSessionKey}, conversationId=${conversationId ?? ''}, messageId=${msg.content.message_id}`
|
|
185
|
+
)
|
|
184
186
|
setParamsMessage(userId, mergedParams)
|
|
187
|
+
dcgLogger(`target alias bound: aliasTarget=${userId} -> sessionKey=${effectiveSessionKey}`)
|
|
185
188
|
const outboundCtx = getEffectiveMsgParams(effectiveSessionKey)
|
|
186
189
|
const agentEntry =
|
|
187
190
|
effectiveAgentId && effectiveAgentId !== 'main' ? config.agents?.list?.find((a) => a.id === effectiveAgentId) : undefined
|
|
@@ -249,6 +252,9 @@ export async function handleDcgchatMessage(msg: InboundMessage, accountId: strin
|
|
|
249
252
|
OriginatingTo: effectiveSessionKey,
|
|
250
253
|
...mediaPayload
|
|
251
254
|
})
|
|
255
|
+
dcgLogger(
|
|
256
|
+
`inbound context target: rawTarget=${userId}, normalizedTarget=${effectiveSessionKey}, ctx.To=${String(ctxPayload.To ?? '')}, ctx.SessionKey=${String(ctxPayload.SessionKey ?? '')}, ctx.OriginatingTo=${String(ctxPayload.OriginatingTo ?? '')}`
|
|
257
|
+
)
|
|
252
258
|
|
|
253
259
|
const sentMediaKeys = new Set<string>()
|
|
254
260
|
const getMediaKey = (url: string) => url.split(/[\\/]/).pop() ?? url
|
|
@@ -442,6 +448,9 @@ export async function handleDcgchatMessage(msg: InboundMessage, accountId: strin
|
|
|
442
448
|
|
|
443
449
|
// Record session metadata
|
|
444
450
|
const storePath = core.channel.session.resolveStorePath(config.session?.store)
|
|
451
|
+
dcgLogger(
|
|
452
|
+
`record session route: rawTarget=${userId}, normalizedTarget=${effectiveSessionKey}, updateLastRoute.to=${effectiveSessionKey}, accountId=${route.accountId}`
|
|
453
|
+
)
|
|
445
454
|
core.channel.session
|
|
446
455
|
.recordInboundSession({
|
|
447
456
|
storePath,
|
package/src/channel.ts
CHANGED
|
@@ -15,8 +15,15 @@ export type DcgchatMediaSendOptions = {
|
|
|
15
15
|
text?: string
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
function normalizeSessionTarget(rawTo: string): string {
|
|
19
|
+
const cleaned = rawTo.replace('dcg-cron:', '').trim()
|
|
20
|
+
if (!cleaned) return ''
|
|
21
|
+
return getParamsMessage(cleaned)?.sessionKey?.trim() || cleaned
|
|
22
|
+
}
|
|
23
|
+
|
|
18
24
|
export async function sendDcgchatMedia(opts: DcgchatMediaSendOptions): Promise<void> {
|
|
19
|
-
const
|
|
25
|
+
const sessionKey = normalizeSessionTarget(opts.sessionKey ?? '')
|
|
26
|
+
const msgCtx = getOutboundMsgParams(sessionKey)
|
|
20
27
|
if (!isWsOpen()) {
|
|
21
28
|
dcgLogger(`outbound media skipped -> ws not open: ${opts.mediaUrl ?? ''}`)
|
|
22
29
|
return
|
|
@@ -36,21 +43,20 @@ export async function sendDcgchatMedia(opts: DcgchatMediaSendOptions): Promise<v
|
|
|
36
43
|
|
|
37
44
|
try {
|
|
38
45
|
const botToken = msgCtx.botToken ?? getOpenClawConfig()?.channels?.["dcgchat"]?.botToken ?? ''
|
|
39
|
-
console.log('🚀 ~ sendDcgchatMedia ~ botToken:', botToken)
|
|
40
46
|
const url = opts.mediaUrl ? await ossUpload(opts.mediaUrl, botToken, 1) : ''
|
|
41
47
|
wsSendRaw(msgCtx, {
|
|
42
48
|
response: opts.text ?? '',
|
|
43
49
|
message_tags: { source: 'file' },
|
|
44
50
|
files: [{ url, name: fileName }]
|
|
45
51
|
})
|
|
46
|
-
dcgLogger(`dcgchat: sendMedia session=${
|
|
52
|
+
dcgLogger(`dcgchat: sendMedia session=${sessionKey}, file=${fileName}`)
|
|
47
53
|
} catch (error) {
|
|
48
54
|
wsSendRaw(msgCtx, {
|
|
49
55
|
response: opts.text ?? '',
|
|
50
56
|
message_tags: { source: 'file' },
|
|
51
57
|
files: [{ url: opts.mediaUrl ?? '', name: fileName }]
|
|
52
58
|
})
|
|
53
|
-
dcgLogger(`dcgchat: error sendMedia session=${
|
|
59
|
+
dcgLogger(`dcgchat: error sendMedia session=${sessionKey}: ${String(error)}`, 'error')
|
|
54
60
|
}
|
|
55
61
|
}
|
|
56
62
|
|
|
@@ -141,7 +147,7 @@ export const dcgchatPlugin: ChannelPlugin<ResolvedDcgchatAccount> = {
|
|
|
141
147
|
})
|
|
142
148
|
},
|
|
143
149
|
messaging: {
|
|
144
|
-
normalizeTarget: (raw) => raw
|
|
150
|
+
normalizeTarget: (raw) => normalizeSessionTarget(raw ?? '') || undefined,
|
|
145
151
|
targetResolver: {
|
|
146
152
|
looksLikeId: (raw) => Boolean(raw?.trim()),
|
|
147
153
|
hint: 'effectiveSessionKey(与 SessionKey 一致;勿填配置里的 WS userId)'
|
|
@@ -155,10 +161,17 @@ export const dcgchatPlugin: ChannelPlugin<ResolvedDcgchatAccount> = {
|
|
|
155
161
|
},
|
|
156
162
|
outbound: {
|
|
157
163
|
deliveryMode: 'direct',
|
|
164
|
+
resolveTarget: ({ to }) => {
|
|
165
|
+
const normalized = normalizeSessionTarget(to ?? '')
|
|
166
|
+
if (!normalized) {
|
|
167
|
+
return { ok: false, error: new Error('target is empty') }
|
|
168
|
+
}
|
|
169
|
+
return { ok: true, to: normalized }
|
|
170
|
+
},
|
|
158
171
|
textChunkLimit: 4000,
|
|
159
172
|
sendText: async (ctx) => {
|
|
160
173
|
const isCron = ctx.to.indexOf('dcg-cron:') >= 0
|
|
161
|
-
const to = ctx.to
|
|
174
|
+
const to = normalizeSessionTarget(ctx.to)
|
|
162
175
|
dcgLogger(`channel sendText to ${ctx.to} `)
|
|
163
176
|
const outboundCtx = getOutboundMsgParams(to)
|
|
164
177
|
const cronMsgId = getCronMessageId(to)
|
|
@@ -189,7 +202,7 @@ export const dcgchatPlugin: ChannelPlugin<ResolvedDcgchatAccount> = {
|
|
|
189
202
|
},
|
|
190
203
|
sendMedia: async (ctx) => {
|
|
191
204
|
const isCron = ctx.to.indexOf('dcg-cron:') >= 0
|
|
192
|
-
const to = ctx.to
|
|
205
|
+
const to = normalizeSessionTarget(ctx.to)
|
|
193
206
|
const outboundCtx = getOutboundMsgParams(to)
|
|
194
207
|
const msgCtx = getParamsMessage(to) ?? outboundCtx
|
|
195
208
|
const cronMsgId = getCronMessageId(to)
|