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),
    });
  }
}
相关推荐
半仙10081 小时前
电感式编码器 IS06-18 在轮毂电机中的实战应用指南
嵌入式硬件·机器人
硅谷秋水2 小时前
WAM-Nav:用于统一视觉导航的非对称潜世界动作建模
深度学习·机器学习·计算机视觉·语言模型·机器人
宿6742 小时前
tsconfig.node.json
前端·javascript·vue.js
消失的旧时光-19432 小时前
第 2 篇:Android 控制屏为什么与机器人主控使用 TCP 长连接?
android·tcp/ip·机器人
别动我齐刘海3 小时前
“三层同步审计”判定掉帧缺失
c语言·c++·人工智能·深度学习·学习·机器学习·机器人
谷哥的小弟4 小时前
TypeScript接口
javascript·typescript
光锥智能4 小时前
地瓜机器人「地心引力DemoDay」收官,欧拉万象、巡领科技、眺月科技斩获前三
科技·机器人
lllsure4 小时前
Vue&React Router
前端·vue.js·react.js
workflower5 小时前
全球云计算产业发展态势-市场:云计算规模保持稳步增长,产业格局日趋明晰
人工智能·深度学习·机器学习·设计模式·机器人·云计算
谷哥的小弟5 小时前
TypeScript类型断言
前端·javascript·typescript