feat: add wxpusher message push

pull/90/head
moonrailgun 2 years ago
parent 230f00ac30
commit 1c09b17211

@ -28,6 +28,11 @@ interface InboxMessage {
* /
*/
messageSnippet: string;
/**
*
*/
messagePlainContent: string;
}
/**

@ -80,6 +80,7 @@ export interface MessageInboxItem extends BasicInboxItem {
converseId: string;
messageId: string;
messageSnippet: string;
messagePlainContent?: string;
};
}

@ -1,4 +1,4 @@
import { TcService, TcDbService } from 'tailchat-server-sdk';
import { TcService, TcDbService, InboxStruct, call } from 'tailchat-server-sdk';
import type {
WXPusherUserDocument,
WXPusherUserModel,
@ -41,6 +41,29 @@ class WxpusherService extends TcService {
return;
}
this.registerEventListener(
'chat.inbox.append',
async (inboxItem: InboxStruct, ctx) => {
if (inboxItem.type === 'message') {
const userId = inboxItem.userId;
const message = inboxItem.payload;
let title = 'new';
if (message.groupId) {
const groupInfo = await call(ctx).getGroupInfo(message.groupId);
title = groupInfo.name;
}
const content = message.messagePlainContent ?? message.messageSnippet; // 优先使用去节点的内容
try {
await this.sendMessage(userId, [title, content].join('\n'));
} catch (err) {
console.error(err);
}
}
}
);
this.registerAction('getWXPusherUserId', this.getWXPusherUserId);
this.registerAction('createQRCode', this.createQRCode);
this.registerAction('callback', this.callback, {

@ -40,6 +40,7 @@ class InboxService extends TcService {
converseId: payload.converseId,
messageId: payload.messageId,
messageSnippet: payload.content,
messagePlainContent: payload.plain,
},
});
})

Loading…
Cancel
Save