diff --git a/src/push/qmsg.ts b/src/push/qmsg.ts index 1ca3cd9..0cfa590 100644 --- a/src/push/qmsg.ts +++ b/src/push/qmsg.ts @@ -47,6 +47,22 @@ export type QmsgOption = (QmsgPrivateMsgOption | QmsgGroupMsgOption) & { bot?: string } +export interface QmsgResponse { + /** + * 本次请求是否成功 + */ + success: boolean + /** + * 本次请求结果描述 + */ + reason: string + /** + * 错误代码。错误代码目前不可靠,如果要判断是否成功请使用success + */ + code: number + info: any +} + /** * Qmsg酱。使用说明见 [Qmsg酱](https://qmsg.zendee.cn/docs) * @@ -77,7 +93,7 @@ export class Qmsg implements Send { * @param [desp] 消息描述 * @param [option] QmsgOption 选项 */ - async send(title: string, desp: string, option: QmsgOption): Promise { + async send(title: string, desp: string, option: QmsgOption): Promise> { Debugger('title: "%s", desp: "%s", option: "%o"', title, desp, option) const { qq, type = 'send', bot } = option || {} const msg = `${title}${desp ? `\n${desp}` : ''}` diff --git a/src/push/server-chan-turbo.ts b/src/push/server-chan-turbo.ts index 99e2f98..974f970 100644 --- a/src/push/server-chan-turbo.ts +++ b/src/push/server-chan-turbo.ts @@ -9,10 +9,18 @@ export type ChannelValue = 98 | 66 | 1 | 2 | 3 | 8 | 0 | 88 | 18 | 9 export type Channel = `${ChannelValue}` | `${ChannelValue}|${ChannelValue}` +export interface ServerChanTurboConfig { + /** + * Server酱 Turbo 的 SCTKEY + * 请前往 https://sct.ftqq.com/sendkey 领取 + */ + SERVER_CHAN_TURBO_SCTKEY: string +} + /** * 附加参数 */ -export type ServerChanTurboOptions = { +export type ServerChanTurboOption = { /** * 消息卡片内容,选填。最大长度 64。如果不指定,将自动从 desp 中截取生成。 */ @@ -42,6 +50,20 @@ export type ServerChanTurboOptions = { openid?: string } +export interface ServerChanTurboResponse { + // 0 表示成功,其他值表示失败 + code: number + message: string + data: { + // 推送消息的 ID + pushid: string + // 推送消息的阅读凭证 + readkey: string + error: string + errno: number + } +} + /** * Server 酱·Turbo * 文档 https://sct.ftqq.com/ @@ -56,14 +78,15 @@ export class ServerChanTurbo implements Send { /** * * @author CaoMeiYouRen - * @date 2021-02-27 - * @param SCTKEY 请前往 https://sct.ftqq.com/sendkey 领取 + * @date 2024-11-08 + * @param config 请前往 https://sct.ftqq.com/sendkey 领取 */ - constructor(SCTKEY: string) { - this.SCTKEY = SCTKEY - Debugger('set SCTKEY: "%s"', SCTKEY) + constructor(config: ServerChanTurboConfig) { + const { SERVER_CHAN_TURBO_SCTKEY } = config + this.SCTKEY = SERVER_CHAN_TURBO_SCTKEY + Debugger('set SCTKEY: "%s"', this.SCTKEY) if (!this.SCTKEY) { - throw new Error('SCTKEY 是必须的!') + throw new Error('SERVER_CHAN_TURBO_SCTKEY 是必须的!') } } /** @@ -77,19 +100,20 @@ export class ServerChanTurbo implements Send { * 发送消息 * * @author CaoMeiYouRen - * @date 2021-02-25 - * @param text 消息的标题 - * @param desp 消息的内容,支持 Markdown + * @date 2024-11-08 + * @param title 消息的标题 + * @param [desp=''] 消息的内容,支持 Markdown + * @param [option={}] 额外发送选项 */ - async send(text: string, desp: string = '', options: ServerChanTurboOptions = {}): Promise { - Debugger('text: "%s", desp: "%s", options: %O', text, desp, options) - if (options.noip === 1 || options.noip === true) { - options.noip = '1' + async send(title: string, desp: string = '', option: ServerChanTurboOption = {}): Promise> { + Debugger('title: "%s", desp: "%s", option: %O', title, desp, option) + if (option.noip === 1 || option.noip === true) { + option.noip = '1' } const data = { - text, + text: title, desp, - ...options, + ...option, } return ajax({ url: `https://sctapi.ftqq.com/${this.SCTKEY}.send`, diff --git a/src/push/server-chan-v3.ts b/src/push/server-chan-v3.ts index dce45b8..fd4e933 100644 --- a/src/push/server-chan-v3.ts +++ b/src/push/server-chan-v3.ts @@ -1,17 +1,40 @@ import debug from 'debug' import { Send } from '@/interfaces/send' import { ajax } from '@/utils/ajax' +import { SendResponse } from '@/interfaces/response' const Debugger = debug('push:server-chan-v3') /** * 附加参数 */ -export type ServerChanV3Options = { +export type ServerChanV3Option = { tags?: string | string[] // 标签列表,多个标签使用竖线分隔;也可以用数组格式,数组格式下不要加竖线 short?: string // 推送消息的简短描述,用于指定消息卡片的内容部分,尤其是在推送markdown的时候 } +export interface ServerChanV3Config { + /** + * 请前往 https://sc3.ft07.com/sendkey 领取 + */ + SERVER_CHAN_V3_SENDKEY: string +} + +export interface ServerChanV3Response { + // 0 表示成功,其他值表示失败 + code: number + message: string + errno: number + data: { + // 推送消息的 ID + pushid: string + meta: { + android: any + devices: any[] + } + } +} + /** * Server酱³ * 文档:https://sc3.ft07.com/doc @@ -34,11 +57,14 @@ export class ServerChanV3 implements Send { private uid: string = '' /** + * 创建 ServerChanV3 实例 * @author CaoMeiYouRen - * @date 2024-10-04 - * @param sendkey 请前往 https://sc3.ft07.com/sendkey 领取 + * @date 2024-11-08 + * @param config 请前往 https://sc3.ft07.com/sendkey 领取 */ - constructor(sendkey: string) { + constructor(config: ServerChanV3Config) { + const { SERVER_CHAN_V3_SENDKEY } = config + const sendkey = SERVER_CHAN_V3_SENDKEY this.sendkey = sendkey Debugger('set sendkey: "%s"', sendkey) if (!this.sendkey) { @@ -50,15 +76,24 @@ export class ServerChanV3 implements Send { } } - async send(text: string, desp: string = '', options: ServerChanV3Options = {}): Promise { - Debugger('text: "%s", desp: "%s", options: %O', text, desp, options) - if (Array.isArray(options.tags)) { - options.tags = options.tags.join('|') + /** + * 发送消息 + * + * @author CaoMeiYouRen + * @date 2024-11-08 + * @param title 消息的标题 + * @param [desp=''] 消息的内容,支持 Markdown + * @param [option={}] 额外发送选项 + */ + async send(title: string, desp: string = '', option: ServerChanV3Option = {}): Promise> { + Debugger('title: "%s", desp: "%s", option: %O', title, desp, option) + if (Array.isArray(option.tags)) { + option.tags = option.tags.join('|') } const data = { - text, + text: title, desp, - ...options, + ...option, } return ajax({ url: `https://${this.uid}.push.ft07.com/send/${this.sendkey}.send`,