Skip to content

引入

ts
import {
  sendWxRobotMsg,
  sendWxRobotMarkdown,
  sendWxRobotImg,
  batchSendWxRobotBase64Img,
  sendWxRobotBase64Img
} from 't-comm';

// 不支持 tree-shaking 的项目
import {
  sendWxRobotMsg,
  sendWxRobotMarkdown,
  sendWxRobotImg,
  batchSendWxRobotBase64Img,
  sendWxRobotBase64Img
} from 't-comm/lib/wecom-robot/index';

// 只支持 ESM 的项目
import {
  sendWxRobotMsg,
  sendWxRobotMarkdown,
  sendWxRobotImg,
  batchSendWxRobotBase64Img,
  sendWxRobotBase64Img
} from 't-comm/es/wecom-robot/index';

sendWxRobotMsg(config)

描述

给机器人发送普通消息

参数

参数名类型描述
configObject

配置内容

config.webhookUrlstring

钩子链接

config.chatIdstring

会话id

config.aliasstring

别名

config.contentstring

内容

返回: Promise.<object>

Promise

示例

typescript
sendWxRobotMsg({
  webhookUrl: 'xxx',
  chatId: 'xxx',
  content: 'xxx',
  alias: 'xxx',
}).then(() => {

})

sendWxRobotMarkdown(config)

描述

给机器人发送Markdown消息

参数

参数名类型描述
configObject

配置内容

config.webhookUrlstring

钩子链接

config.chatIdstring

会话id

config.contentstring

内容

config.attachmentsArray<object>

附加内容

返回: Promise.<object>

请求Promise

示例

typescript
sendWxRobotMarkdown({
  webhookUrl: 'xxx',
  chatId: 'xxx',
  content: 'xxx',
  attachments: []
}).then(() => {

})

sendWxRobotImg(config)

描述

给机器人发送图片

参数

参数名类型描述
configObject

配置参数

config.webhookUrlstring

钩子链接

config.chatIdstring

会话id

config.contentstring

内容

config.md5Valstring

md5内容

返回: Promise.<object>

请求Promise

示例

typescript
sendWxRobotImg({
  webhookUrl: 'xxx',
  chatId: 'xxx',
  content: 'xxx',
  md5Val: 'xxx'
}).then(() => {

})

batchSendWxRobotBase64Img(config)

描述

批量发送企业微信机器人base64图片

参数

参数名类型描述
configobject

配置信息

config.imgstring

base64图片

config.chatIdstring

会话Id

config.webhookUrlstring

webhook地址

返回: Promise.<object>

请求Promise

示例

typescript
batchSendWxRobotBase64Img({
  img: 'xxx',
  chatId: 'xxx', // or ['xxx], or ['ALL'], or 'ALL'
  webhookUrl: 'xxx',
}).then(() => {

})

sendWxRobotBase64Img(config)

描述

发送企业微信机器人base64图片,其实就是先保存到本地,然后生成md5,最后发送

参数

参数名类型描述
configobject

配置信息

config.imgstring

base64图片

config.chatIdstring

会话Id

config.webhookUrlstring

webhook地址

返回: Promise.<object>

请求Promise

示例

typescript
sendWxRobotBase64Img({
  img: 'xxx',
  chatId: 'xxx',
  webhookUrl: 'xxx',
}).then(() => {

})