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),
    });
  }
}
相关推荐
_zxd3 分钟前
TypeScript 类型树
前端·typescript
wdssmq2 小时前
「折腾」Vue 简单的状态管理实践
vue.js
某不知名網友2 小时前
ROS2入门:命令行启动节点与Launch程序
c++·机器人
海盗12343 小时前
AI 新闻日报 2026-10-07:智能体迁往云端 / SDK 支持运行中改向 / 机器人进柜台与景区
人工智能·机器人·人工智能aigc
Q26433650234 小时前
【有源码】基于Spring Boot和Vue的在线考试与交流系统-教育信息化背景下在线考试与交流一体化平台
java·vue.js·spring boot·mysql·spring·毕业设计·课程设计
workflower6 小时前
AI 产业链带动效应加速,催生AI 原生企业
人工智能·机器学习·机器人·云计算·无人机
苹果二6 小时前
使用Vue的指南
前端·javascript·vue.js
hughnz6 小时前
部署基于云的钻井自动化:7 条实践经验
人工智能·机器人
害人终害己6 小时前
‘vue-cli-service‘ 不是内部或外部命令,也不是可运行的程序或批处理文件。
前端·javascript·vue.js