引入
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)
描述:
给机器人发送普通消息
参数:
| 参数名 | 类型 | 描述 |
|---|---|---|
| config | Object | 配置内容 |
| config.webhookUrl | string | 钩子链接 |
| config.chatId | string | 会话id |
| config.alias | string | 别名 |
| config.content | string | 内容 |
返回: Promise.<object>
Promise
示例
typescript
sendWxRobotMsg({
webhookUrl: 'xxx',
chatId: 'xxx',
content: 'xxx',
alias: 'xxx',
}).then(() => {
})sendWxRobotMarkdown(config)
描述:
给机器人发送Markdown消息
参数:
| 参数名 | 类型 | 描述 |
|---|---|---|
| config | Object | 配置内容 |
| config.webhookUrl | string | 钩子链接 |
| config.chatId | string | 会话id |
| config.content | string | 内容 |
| config.attachments | Array<object> | 附加内容 |
返回: Promise.<object>
请求Promise
示例
typescript
sendWxRobotMarkdown({
webhookUrl: 'xxx',
chatId: 'xxx',
content: 'xxx',
attachments: []
}).then(() => {
})sendWxRobotImg(config)
描述:
给机器人发送图片
参数:
| 参数名 | 类型 | 描述 |
|---|---|---|
| config | Object | 配置参数 |
| config.webhookUrl | string | 钩子链接 |
| config.chatId | string | 会话id |
| config.content | string | 内容 |
| config.md5Val | string | md5内容 |
返回: Promise.<object>
请求Promise
示例
typescript
sendWxRobotImg({
webhookUrl: 'xxx',
chatId: 'xxx',
content: 'xxx',
md5Val: 'xxx'
}).then(() => {
})batchSendWxRobotBase64Img(config)
描述:
批量发送企业微信机器人base64图片
参数:
| 参数名 | 类型 | 描述 |
|---|---|---|
| config | object | 配置信息 |
| config.img | string | base64图片 |
| config.chatId | string | 会话Id |
| config.webhookUrl | string | webhook地址 |
返回: Promise.<object>
请求Promise
示例
typescript
batchSendWxRobotBase64Img({
img: 'xxx',
chatId: 'xxx', // or ['xxx], or ['ALL'], or 'ALL'
webhookUrl: 'xxx',
}).then(() => {
})sendWxRobotBase64Img(config)
描述:
发送企业微信机器人base64图片,其实就是先保存到本地,然后生成md5,最后发送
参数:
| 参数名 | 类型 | 描述 |
|---|---|---|
| config | object | 配置信息 |
| config.img | string | base64图片 |
| config.chatId | string | 会话Id |
| config.webhookUrl | string | webhook地址 |
返回: Promise.<object>
请求Promise
示例
typescript
sendWxRobotBase64Img({
img: 'xxx',
chatId: 'xxx',
webhookUrl: 'xxx',
}).then(() => {
})