1.0.1 • Published 8 months ago

qywechat v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

qywechat

向企业微信群组发送消息

Features

  • 🚀 支持文本、markdown、图片、图文、文件、语音、模板卡片七种消息类型。
  • 🤖️ 完善的类型提示

Install

npm install --save qywechat

Usage

import { sendText } from 'qywechat';

await sendText({
  url: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=<yourkey>',
  content: '广州今日天气:29度,大部分多云,降雨概率:60%',
});

API

sendText

发送文本类型消息,详细可查看企业微信文档

sendText({
  url: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=<yourkey>',
  content: '广州今日天气:29度,大部分多云,降雨概率:60%',
  mentioned_list: ['wangqing', '@all'],
  mentioned_mobile_list: ['13800001111', '@all'],
});
参数类型是否必填说明
urlString机器人的 webhook 地址
contentString文本内容,最长不超过 2048 个字节,必须是 utf8 编码
mentioned_listString[]userid 的列表,提醒群中的指定成员(@某个成员),@all 表示提醒所有人,如果开发者获取不到 userid,可以使用 mentioned_mobile_list
mentioned_mobile_listString[]手机号列表,提醒手机号对应的群成员(@某个成员),@all 表示提醒所有人

sendMarkdown

发送 markdown 消息,详细可查看企业微信文档

sendMarkdown({
  url: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=<yourkey>',
  content:
    '实时新增用户反馈<font color="warning">132例</font>,请相关同事注意。',
});
参数类型是否必填说明
urlString机器人的 webhook 地址
contentStringmarkdown 内容,最长不超过 4096 个字节,必须是 utf8 编码

sendImage

发送图片类型消息,详细可查看企业微信文档

sendImage({
  url: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=<yourkey>',
  base64: 'DATA',
  md5: 'MD5',
});
参数类型是否必填说明
urlString机器人的 webhook 地址
base64String图片内容的 base64 编码
md5String图片内容(base64 编码前)的 md5 值

sendNews

发送图文类型消息,详细可查看企业微信文档

sendNews({
  url: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=<yourkey>',
  articles: [
    {
      title: '中秋节礼品领取',
      description: '今年中秋节公司有豪礼相送',
      url: 'www.qq.com',
      picurl: 'http://xxx.png',
    },
  ],
});
参数类型是否必填说明
urlString机器人的 webhook 地址
articlesObject[]图文消息,一个图文消息支持 1 到 8 条图文
articles.titleString标题,不超过 128 个字节,超过会自动截断
articles.descriptionString描述,不超过 512 个字节,超过会自动截断
articles.urlString点击后跳转的链接
articles.picurlString图文消息的图片链接,支持 JPG、PNG 格式,较好的效果为大图 1068✖️455,小图 150✖️150

sendFile

发送文件类型消息,详细可查看企业微信文档

sendFile({
  url: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=<yourkey>',
  media_id: '3a8asd892asd8asd',
});
参数类型是否必填说明
urlString机器人的 webhook 地址
media_idString文件 id,通过下文的文件上传接口获取

sendVoice

发送语音类型消息,详细可查看企业微信文档

sendVoice({
  url: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=<yourkey>',
  media_id: 'MEDIA_ID',
});
参数类型是否必填说明
urlString机器人的 webhook 地址
media_idString语音文件 id,通过下文的文件上传接口获取

sendTextNoticeCard

发送文本通知模版卡片消息,详细可查看企业微信文档

sendTextNoticeCard({
  url: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=<yourkey>',
  source: {
    icon_url:
      'https://wework.qpic.cn/wwpic/252813_jOfDHtcISzuodLa_1629280209/0',
    desc: '企业微信',
    desc_color: 0,
  },
  main_title: {
    title: '欢迎使用企业微信',
    desc: '您的好友正在邀请您加入企业微信',
  },
  emphasis_content: {
    title: '100',
    desc: '数据含义',
  },
  quote_area: {
    type: 1,
    url: 'https://work.weixin.qq.com/?from=openApi',
    appid: 'APPID',
    pagepath: 'PAGEPATH',
    title: '引用文本标题',
    quote_text: 'Jack:企业微信真的很好用~\nBalian:超级好的一款软件!',
  },
  sub_title_text: '下载企业微信还能抢红包!',
  horizontal_content_list: [
    {
      keyname: '邀请人',
      value: '张三',
    },
    {
      keyname: '企微官网',
      value: '点击访问',
      type: 1,
      url: 'https://work.weixin.qq.com/?from=openApi',
    },
    {
      keyname: '企微下载',
      value: '企业微信.apk',
      type: 2,
      media_id: 'MEDIAID',
    },
  ],
  jump_list: [
    {
      type: 1,
      url: 'https://work.weixin.qq.com/?from=openApi',
      title: '企业微信官网',
    },
    {
      type: 2,
      appid: 'APPID',
      pagepath: 'PAGEPATH',
      title: '跳转小程序',
    },
  ],
  card_action: {
    type: 1,
    url: 'https://work.weixin.qq.com/?from=openApi',
    appid: 'APPID',
    pagepath: 'PAGEPATH',
  },
});
参数类型是否必填说明
urlString机器人的 webhook 地址
sourceObject卡片来源样式信息,不需要来源样式可不填写
source.icon_urlString来源图片的 url
source.descString来源图片的描述,建议不超过 13 个字
source.desc_colorNumber来源文字的颜色,目前支持:0 (默认) 灰色,1 黑色,2 红色,3 绿色
main_titleObject模版卡片的主要内容,包括一级标题和标题辅助信息
main_title.titleString一级标题,建议不超过 26 个字。模版卡片主要内容的一级标题 main_title.title 和二级普通文本 s ub_title_text 必须有一项填写
main_title.descString标题辅助信息,建议不超过 30 个字
emphasis_contentObject关键数据样式
emphasis_content.titleString关键数据样式的数据内容,建议不超过 10 个字
emphasis_content.descString关键数据样式的数据描述内容,建议不超过 15 个字
quote_areaObject引用文献样式,建议不与关键数据共用
quote_area.typeNumber引用文献样式区域点击事件,0 或不填代表没有点击事件,1 代表跳转 url,2 代表跳转小程序
quote_area.urlString点击跳转的 url,quote_area.type 是 1 时必填
quote_area.appidString点击跳转的小程序的 appid,quote_area.type 是 2 时必填
quote_area.pagepathString点击跳转的小程序的 pagepath,quote_area.type 是 2 时选填
quote_area.titleString引用文献样式的标题
quote_area.quote_textString引用文献样式的引用文案
sub_title_textString二级普通文本,建议不超过 112 个字。模版卡片主要内容的一级标题 main_title.title 和二级普通文本 sub_title_text 必须有一项填写
horizontal_content_listObject[]二级标题+文本列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过 6
horizontal_content_list.typeNumber模版卡片的二级标题信息内容支持的类型,1 是 url,2 是文件附件,3 代表点击跳转成员详情
horizontal_content_list.keynameString二级标题,建议不超过 5 个字
horizontal_content_list.valueString二级文本,如果 horizontal_content_list.type 是 2,该字段代表文件名称(要包含文件类型),建议不超过 26 个字
horizontal_content_list.urlString链接跳转的 url,horizontal_content_list.type 是 1 时必填
horizontal_content_list.media_idString附件的 media_id,horizontal_content_list.type 是 2 时必填
horizontal_content_list.useridString成员详情的 userid,horizontal_content_list.type 是 3 时必填
jump_listObject[]跳转指引样式的列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过 3
jump_list.typeNumber跳转链接类型,0 或不填代表不是链接,1 代表跳转 url,2 代表跳转小程序
jump_list.titleString跳转链接样式的文案内容,建议不超过 13 个字
jump_list.urlString跳转链接的 url,jump_list.type 是 1 时必填
jump_list.appidString跳转链接的小程序的 appid,jump_list.type 是 2 时必填
jump_list.pagepathString跳转链接的小程序的 pagepath,jump_list.type 是 2 时选填
card_actionObject整体卡片的点击跳转事件,text_notice 模版卡片中该字段为必填项
card_action.typeNumber卡片跳转类型,1 代表跳转 url,2 代表打开小程序。text_notice 模版卡片中该字段取值范围为1,2
card_action.urlString跳转事件的 url,card_action.type 是 1 时必填
card_action.appidString跳转事件的小程序的 appid,card_action.type 是 2 时必填
card_action.pagepathString跳转事件的小程序的 pagepath,card_action.type 是 2 时选填

sendNewsNoticeCard

发送图文展示模版卡片消息,详细可查看企业微信文档

sendNewsNoticeCard({
  url: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=<yourkey>',
  source: {
    icon_url:
      'https://wework.qpic.cn/wwpic/252813_jOfDHtcISzuodLa_1629280209/0',
    desc: '企业微信',
    desc_color: 0,
  },
  main_title: {
    title: '欢迎使用企业微信',
    desc: '您的好友正在邀请您加入企业微信',
  },
  card_image: {
    url: 'https://wework.qpic.cn/wwpic/354393_4zpkKXd7SrGMvfg_1629280616/0',
    aspect_ratio: 2.25,
  },
  image_text_area: {
    type: 1,
    url: 'https://work.weixin.qq.com',
    title: '欢迎使用企业微信',
    desc: '您的好友正在邀请您加入企业微信',
    image_url:
      'https://wework.qpic.cn/wwpic/354393_4zpkKXd7SrGMvfg_1629280616/0',
  },
  quote_area: {
    type: 1,
    url: 'https://work.weixin.qq.com/?from=openApi',
    appid: 'APPID',
    pagepath: 'PAGEPATH',
    title: '引用文本标题',
    quote_text: 'Jack:企业微信真的很好用~\nBalian:超级好的一款软件!',
  },
  vertical_content_list: [
    {
      title: '惊喜红包等你来拿',
      desc: '下载企业微信还能抢红包!',
    },
  ],
  horizontal_content_list: [
    {
      keyname: '邀请人',
      value: '张三',
    },
    {
      keyname: '企微官网',
      value: '点击访问',
      type: 1,
      url: 'https://work.weixin.qq.com/?from=openApi',
    },
    {
      keyname: '企微下载',
      value: '企业微信.apk',
      type: 2,
      media_id: 'MEDIAID',
    },
  ],
  jump_list: [
    {
      type: 1,
      url: 'https://work.weixin.qq.com/?from=openApi',
      title: '企业微信官网',
    },
    {
      type: 2,
      appid: 'APPID',
      pagepath: 'PAGEPATH',
      title: '跳转小程序',
    },
  ],
  card_action: {
    type: 1,
    url: 'https://work.weixin.qq.com/?from=openApi',
    appid: 'APPID',
    pagepath: 'PAGEPATH',
  },
});
参数类型是否必填说明
urlString机器人的 webhook 地址
sourceObject卡片来源样式信息,不需要来源样式可不填写
source.icon_urlString来源图片的 url
source.descString来源图片的描述,建议不超过 13 个字
source.desc_colorNumber来源文字的颜色,目前支持:0 (默认) 灰色,1 黑色,2 红色,3 绿色
main_titleObject模版卡片的主要内容,包括一级标题和标题辅助信息
main_title.titleString一级标题,建议不超过 26 个字。模版卡片主要内容的一级标题 main_title.title 和二级普通文本 s ub_title_text 必须有一项填写
main_title.descString标题辅助信息,建议不超过 30 个字
card_imageObject图片样式
card_image.urlString图片的 url
card_image.aspect_ratioNumber图片的宽高比,宽高比要小于 2.25,大于 1.3,不填该参数默认 1.3
image_text_areaObject左图右文样式
image_text_area.typeNumber左图右文样式区域点击事件,0 或不填代表没有点击事件,1 代表跳转 url,2 代表跳转小程序
image_text_area.urlString点击跳转的 url,image_text_area.type 是 1 时必填
image_text_area.appidString点击跳转的小程序的 appid,必须是与当前应用关联的小程序,image_text_area.type 是 2 时必填
image_text_area.pagepathString点击跳转的小程序的 pagepath,image_text_area.type 是 2 时选填
image_text_area.titleString左图右文样式的标题
image_text_area.descString左图右文样式的描述
image_text_area.image_urlString左图右文样式的图片 url
quote_areaObject引用文献样式,建议不与关键数据共用
quote_area.typeNumber引用文献样式区域点击事件,0 或不填代表没有点击事件,1 代表跳转 url,2 代表跳转小程序
quote_area.urlString点击跳转的 url,quote_area.type 是 1 时必填
quote_area.appidString点击跳转的小程序的 appid,quote_area.type 是 2 时必填
quote_area.pagepathString点击跳转的小程序的 pagepath,quote_area.type 是 2 时选填
quote_area.titleString引用文献样式的标题
quote_area.quote_textString引用文献样式的引用文案
vertical_content_listObject[]卡片二级垂直内容,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过 4
vertical_content_list.titleString卡片二级标题,建议不超过 26 个字
vertical_content_list.descString二级普通文本,建议不超过 112 个字
horizontal_content_listObject[]二级标题+文本列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过 6
horizontal_content_list.typeNumber模版卡片的二级标题信息内容支持的类型,1 是 url,2 是文件附件,3 代表点击跳转成员详情
horizontal_content_list.keynameString二级标题,建议不超过 5 个字
horizontal_content_list.valueString二级文本,如果 horizontal_content_list.type 是 2,该字段代表文件名称(要包含文件类型),建议不超过 26 个字
horizontal_content_list.urlString链接跳转的 url,horizontal_content_list.type 是 1 时必填
horizontal_content_list.media_idString附件的 media_id,horizontal_content_list.type 是 2 时必填
horizontal_content_list.useridString成员详情的 userid,horizontal_content_list.type 是 3 时必填
jump_listObject[]跳转指引样式的列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过 3
jump_list.typeNumber跳转链接类型,0 或不填代表不是链接,1 代表跳转 url,2 代表跳转小程序
jump_list.titleString跳转链接样式的文案内容,建议不超过 13 个字
jump_list.urlString跳转链接的 url,jump_list.type 是 1 时必填
jump_list.appidString跳转链接的小程序的 appid,jump_list.type 是 2 时必填
jump_list.pagepathString跳转链接的小程序的 pagepath,jump_list.type 是 2 时选填
card_actionObject整体卡片的点击跳转事件,text_notice 模版卡片中该字段为必填项
card_action.typeNumber卡片跳转类型,1 代表跳转 url,2 代表打开小程序。text_notice 模版卡片中该字段取值范围为1,2
card_action.urlString跳转事件的 url,card_action.type 是 1 时必填
card_action.appidString跳转事件的小程序的 appid,card_action.type 是 2 时必填
card_action.pagepathString跳转事件的小程序的 pagepath,card_action.type 是 2 时选填

LICENSE

MIT

1.0.1

8 months ago

1.0.0

8 months ago