fix(通知): 微信订阅消息的每条跳过路径都写日志,不再静默
以前 sendWechatSubscribeToUser 的四条提前返回(no-template / disabled-by-user / no-wechat-openid / no-access-token)都不写日志,线上排查「通知没发出去」时 容器日志里一片空白,只能靠猜。现在每条都打一行 [WeChatSubscribe] ... 跳过:原因, 另外 createSongSelectedNotification 在「用户关了通知总开关」时也补了一行。 用途:发布一首新歌后执行 docker logs --timestamps voicehub-app | grep WeChatSubscribe 即可直接看到卡在哪一步(模板没配 / 用户没绑微信 / 拿不到 token / 没有额度 43101 / 字段 47003)。
This commit is contained in:
@@ -163,6 +163,9 @@ export async function createSongSelectedNotification(
|
||||
|
||||
// 如果用户关闭了此类通知,则不发送
|
||||
if (settings && !settings.enabled) {
|
||||
console.warn(
|
||||
`[Notification] SONG_SELECTED → user ${userId} 跳过:该用户关闭了通知总开关,微信/MeoW/邮件都不会发`
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -350,7 +353,10 @@ export async function createSongPlayedNotification(songId: number, ipAddress?: s
|
||||
}
|
||||
// 同步发送 微信订阅消息(只有绑了微信、且刚点过授权的用户收得到,见 wechatSubscribeService)
|
||||
try {
|
||||
await sendWechatSubscribeToUser(targetUserId, 'SONG_PLAYED', { songTitle: song.title, message: userMessage })
|
||||
await sendWechatSubscribeToUser(targetUserId, 'SONG_PLAYED', {
|
||||
songTitle: song.title,
|
||||
message: userMessage
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('发送微信订阅消息失败:', error)
|
||||
}
|
||||
@@ -554,7 +560,11 @@ export async function createSongRejectedNotification(
|
||||
}
|
||||
// 同步发送 微信订阅消息(只有绑了微信、且刚点过授权的用户收得到,见 wechatSubscribeService)
|
||||
try {
|
||||
await sendWechatSubscribeToUser(userId, 'SONG_REJECTED', { songTitle: songInfo.title, reason: reason, message })
|
||||
await sendWechatSubscribeToUser(userId, 'SONG_REJECTED', {
|
||||
songTitle: songInfo.title,
|
||||
reason: reason,
|
||||
message
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('发送微信订阅消息失败:', error)
|
||||
}
|
||||
@@ -591,7 +601,9 @@ export async function createSubmissionNoteClearedNotification(
|
||||
ipAddress?: string
|
||||
) {
|
||||
try {
|
||||
const uniqueUserIds = [...new Set(userIds.filter((userId) => Number.isInteger(userId) && userId > 0))]
|
||||
const uniqueUserIds = [
|
||||
...new Set(userIds.filter((userId) => Number.isInteger(userId) && userId > 0))
|
||||
]
|
||||
|
||||
if (uniqueUserIds.length === 0) {
|
||||
return []
|
||||
@@ -651,7 +663,10 @@ export async function createSystemNotification(
|
||||
}
|
||||
// 同步发送 微信订阅消息(只有绑了微信、且刚点过授权的用户收得到,见 wechatSubscribeService)
|
||||
try {
|
||||
await sendWechatSubscribeToUser(userId, 'SYSTEM_NOTICE', { songTitle: title, message: content })
|
||||
await sendWechatSubscribeToUser(userId, 'SYSTEM_NOTICE', {
|
||||
songTitle: title,
|
||||
message: content
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('发送微信订阅消息失败:', error)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user