send-notify-robot
Version:
62 lines (61 loc) • 2.19 kB
TypeScript
import { AxiosRequestConfig } from "axios";
export type MsgType = 'text' | 'link' | 'markdown' | 'actionCard' | 'feedCard';
export type isAtAll = boolean;
export type atUserIds = string[] | number[];
export type atMobiles = string[];
interface TextConfig {
content: string;
isAtAll?: isAtAll;
atUserIds?: atUserIds;
atMobiles?: atMobiles;
}
interface LinkConfig {
title: string;
content: string;
messageUrl: string;
picUrl?: string;
}
interface MarkdownConfig {
title: string;
content: string;
isAtAll?: isAtAll;
atUserIds?: atUserIds;
atMobiles?: atMobiles;
}
interface ActionCardBase {
title: string;
content: string;
btnOrientation?: 0 | 1;
}
export interface ActionCardSingle extends ActionCardBase {
singleTitle: string;
singleURL: string;
}
export interface ActionCardIndependent extends ActionCardBase {
btns: Array<{
title: string;
actionURL: string;
}>;
}
type ActionCardConfig = ActionCardSingle | ActionCardIndependent;
interface FeedCardConfig {
links: Array<{
title: string;
messageURL: string;
picURL: string;
}>;
}
export type ExtractMsgConfig<T extends MsgType> = T extends 'text' ? TextConfig : T extends 'link' ? LinkConfig : T extends 'markdown' ? MarkdownConfig : T extends 'actionCard' ? ActionCardConfig : T extends 'feedCard' ? FeedCardConfig : never;
export type DingMessageConfig<T extends MsgType> = T extends 'text' ? TextConfig : T extends 'link' ? LinkConfig : T extends 'markdown' ? MarkdownConfig : T extends 'actionCard' ? ActionCardConfig : T extends "feedCard" ? FeedCardConfig : never;
export interface RobotDingType {
sendDing<T extends MsgType>(msgType: T, params: DingMessageConfig<T>): Promise<any>;
}
export declare class RobotDing {
readonly webhook: string;
readonly secret: string;
readonly config: AxiosRequestConfig;
constructor(webhook: string, secret: string, config?: AxiosRequestConfig);
sendDing<T extends MsgType>(msgType: T, config: DingMessageConfig<T>): Promise<any>;
protected sendService<T extends MsgType>(msgType: T, postData: DingMessageConfig<T>): Promise<any>;
}
export {};