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),
    });
  }
}
相关推荐
拼图2098 小时前
element-plus——图标推荐
javascript·vue.js·elementui
沫儿笙10 小时前
克鲁斯焊接机器人保护气省气方案
人工智能·机器人
midsummer_woo11 小时前
基于springboot+vue+mysql工程教育认证的计算机课程管理平台(源码+论文)
vue.js·spring boot·mysql
喝拿铁写前端12 小时前
技术是决策与代价的平衡 —— 超大系统从 Vue 2 向 Vue 3 演进的思考
前端·vue.js·架构
豆豆(设计前端)13 小时前
如何成为高级前端开发者:系统化成长路径。
前端·javascript·vue.js·面试·electron
苦瓜若叶睦13 小时前
Vue (Official) v3.0.2 新特性 为非类npm环境引入 globalTypesPath 选项
vue.js
springfe010114 小时前
模块与组件区别
javascript·vue.js
结衣结衣.14 小时前
Vue3入门-计算属性+监听器
前端·javascript·vue.js·vue·js
哎呦薇15 小时前
从开发到发布:手把手教你将Vue组件上传npm
前端·vue.js
用户38022585982415 小时前
vue3源码解析:生命周期
前端·vue.js·源码阅读