VUE 集成企微机器人通知

message-robot

便于线上异常问题及时发现处理,项目中集成企微机器人通知,及时接收问题并处理

企微机器人通知工具类

复制代码
export class MessageRobotUtil {
  constructor() {}

  /**
   * 发送 markdown 消息
   * @param robotKey 机器人 ID
   * @param title 消息标题
   * @param items 消息内容
   */
  public sendMarkdownMessage(robotKey: string, title: string, items: Record<string, string>) {
    const content = this.generateMarkdownMessageContent(title, items);
    this.sendMessage(robotKey, {
      msgtype: "markdown",
      markdown: { content: content },
    });
  }

  /**
   * 构建 markdown 消息内容
   * @param title 消息标题
   * @param items 消息内容 键值对
   * @returns
   */
  private generateMarkdownMessageContent(title: string, items: Record<string, any>) {
    let content = `### 【${title}】`;
    content += "\n";

    for (const key in items) {
      content += `> ${key}: <font color="warning">${items[key]}</font>\n`;
    }
    return content;
  }

  /**
   * 消息发送
   * @param robotKey 机器人 ID
   * @param message 消息内容
   */
  private sendMessage(robotKey: string, message: Record<string, any>) {
    // 跟地址 https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=****
    const url = "/cgi-bin/webhook/send?key=" + robotKey;
    fetch(url, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify(message),
    });
  }
}
相关推荐
ruanno_top2 小时前
四个 canvas 组件,在 2 倍屏上一直是糊的
vue.js
ruanno_top3 小时前
一个脏数据能让整条折线消失:图表组件的四种数据契约
vue.js
猫先生Mr.Mao14 小时前
RoboRSI详解:机器人自进化为什么需要任务结构和技能边界
机器人·多智能体·论文解读·具身智能·自进化·roborsi
FlyWIHTSKY21 小时前
vue2和vue3有什么区别,用法上有哪些区别
前端·javascript·vue.js
敢敢のwings1 天前
RPV-SemNav 深度解析:让机器人先理解房间,再决定去哪里找目标
机器人
ruanno_top1 天前
能点,但 Tab 不到:两个组件把「可操作」做了一半
vue.js
爱吃烧烤的技术渣1 天前
别再手写 CRUD 了:我把 Element Plus 的工作量压缩成一份列 schema
前端·vue.js
徐小夕1 天前
万字长文!DeepSeek Super-agent × 企业知识库架构深度拆解与落地实践
前端·vue.js·github
好悬给我拽开线1 天前
RoboJEPA:扩展机器人潜在世界模型
机器人
金融Tech趋势派2 天前
企业微信客户管理工具哪个好?按企业规模、行业与合规要求的三层判断标准
人工智能·企业微信