perf: 支持企业微信群聊机器人通知

This commit is contained in:
xiaojunnuo
2024-11-23 23:58:31 +08:00
parent 5450246f06
commit b805a29259
19 changed files with 163 additions and 41 deletions
+21 -7
View File
@@ -1,19 +1,20 @@
import { PluginRequestHandleReq } from "../plugin";
import { Registrable } from "../registry/index.js";
import { FormItemProps } from "../dt/index.js";
import { FormItemProps, HistoryResult, Pipeline } from "../dt/index.js";
import { HttpClient, ILogger, utils } from "@certd/basic";
import * as _ from "lodash-es";
import { IEmailService } from "../service";
import { IEmailService } from "../service/index.js";
export type NotificationBody = {
userId: number;
title: string;
content: string;
pipeline: Pipeline;
pipelineId: number;
result?: HistoryResult;
historyId: number;
url: string;
extra?: any;
options?: any;
errorMessage?: string;
url?: string;
};
export type NotificationRequestHandleReqInput<T = any> = {
@@ -34,11 +35,21 @@ export type NotificationDefine = Registrable & {
[key: string]: NotificationInputDefine;
};
};
export type NotificationInstanceConfig = {
id: number;
type: string;
userId: number;
setting: {
[key: string]: any;
};
};
export interface INotificationService {
send(body: NotificationBody): Promise<void>;
getById(id: number): Promise<NotificationInstanceConfig>;
}
export interface INotification extends INotificationService {
export interface INotification {
ctx: NotificationContext;
[key: string]: any;
}
@@ -55,6 +66,9 @@ export abstract class BaseNotification implements INotification {
http!: HttpClient;
logger!: ILogger;
abstract send(body: NotificationBody): Promise<void>;
// eslint-disable-next-line @typescript-eslint/no-empty-function
async onInstance() {}
setCtx(ctx: NotificationContext) {
this.ctx = ctx;
this.http = ctx.http;
@@ -2,7 +2,6 @@
import { Decorator } from "../decorator/index.js";
import * as _ from "lodash-es";
import { notificationRegistry } from "./registry.js";
import { http, logger, utils } from "@certd/basic";
import { NotificationContext, NotificationDefine, NotificationInputDefine } from "./api.js";
// 提供一个唯一 key
@@ -39,7 +38,7 @@ export function NotificationInput(input?: NotificationInputDefine): PropertyDeco
};
}
export function newNotification(type: string, input: any, ctx?: NotificationContext) {
export function newNotification(type: string, input: any, ctx: NotificationContext) {
const register = notificationRegistry.get(type);
if (register == null) {
throw new Error(`notification ${type} not found`);
@@ -50,11 +49,7 @@ export function newNotification(type: string, input: any, ctx?: NotificationCont
access[key] = input[key];
}
if (!ctx) {
ctx = {
http,
logger,
utils,
};
throw new Error("ctx is required");
}
access.ctx = ctx;
return access;