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),
    });
  }
}
相关推荐
踩着两条虫5 分钟前
VTJ.PRO AI + 低代码实战:接入高德地图
前端·vue.js·ai编程
xiaotao1319 分钟前
Vite 与 Webpack 开发/打包时环境变量对比
前端·vue.js·webpack
博主花神27 分钟前
【TypeScript】梳理
javascript·ubuntu·typescript
qq_526099131 小时前
PCIe8122 高可靠性图像采集卡 适配多场景工业图像传输 稳定高效更省心
数码相机·机器人·自动化
xwz小王子1 小时前
智元发布 GO-2:动作空间推理 + 全生命周期闭环,让机器人稳定可靠落地
开发语言·golang·机器人
前端摸鱼匠1 小时前
Vue 3 的defineProps编译器宏:详解<script setup>中defineProps的使用
前端·javascript·vue.js·前端框架·ecmascript
天外天-亮1 小时前
Vue2.0 + jsmind:开发思维导图
javascript·vue.js·jsmind
挖稀泥的工人2 小时前
能够插入 DOM 的输入框
前端·javascript·vue.js
没有故事、有酒2 小时前
Vue2中el-table修改表头高度和行高
javascript·vue.js·elementui
Jason_zhao_MR2 小时前
机器人主控方案米尔RK3576 + ROS2,NPU加速实现目标跟随与机械臂抓取
人工智能·嵌入式硬件·机器人·嵌入式