Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
feat: 🎸 收消息增加@我的参数isMentioned,收到文件是unknown时优先使用buffer判断文件类型
Browse files Browse the repository at this point in the history
Closes: #38
  • Loading branch information
danni-cool committed Oct 22, 2023
1 parent 34dce0a commit 10ec2b7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ curl --location --request POST 'http://localhost:3001/webhook/msg' \
| type | <div>支持的类型</div><ul><li>✅ 文字(text)</li><li>✅ 链接卡片(urlLink)</li><li>✅ 图片(file)</li><li>✅ 视频(file)</li><li>✅ 附件(file)</li> <li>✅ 语音(file)</li></ul> refer: [wechaty类型支持列表](https://wechaty.js.org/docs/api/message#messagetype--messagetype) | `String` | `text` `file` `urlLink` | - |
| content | 传输的内容, 文本或传输的文件共用这个字段,结构映射请看示例 | `String` `Binary` | | [示例](docs/recvdApi.example.md#formdatacontent) |
| source | 消息的相关发送方数据, JSON String | `String` | | [示例](docs/recvdApi.example.md#formdatasource) |
| isMentioned | 该消息是@我的消息 | `String` |`1` `0` | - |
| isSystemEvent | 是否是来自系统消息事件(比如上线,掉线、异常事件)| `String` | `1` `0` | - |

### 3. 登录APi
Expand Down
12 changes: 9 additions & 3 deletions src/service/webhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ const sendMsg2RecvdApi = async function (msg) {
formData.append('source', JSON.stringify(source))
formData.append('isSystemEvent', msg.isSystemEvent ? '1' : '0')

//有人@我
const someoneMentionMe = ( msg.mentionSelf && await msg.mentionSelf()) /** 原版@我,wechaty web版应该都是false */
formData.append('isMentioned', someoneMentionMe ? '1' : '0')

switch (msg.type()) {

case 1: // 附件
case 2: // 语音
case 6: // 图片
Expand All @@ -74,7 +77,10 @@ const sendMsg2RecvdApi = async function (msg) {
//文件类型尝试解析
if (type) {
fileInfo = {
filename: steamFile._name || `${Date.now()}.${type.ext}`,
// _name:'unknown.txt' => unknown.jpg
filename: steamFile.mimeType === 'application/unknown' /** 截图等无法推断出文件名会变成 unknown.txt */
? `${Date.now()}.${type.ext}`
: (steamFile._name || `${Date.now()}.${type.ext}`),
ext: type.ext,
mime: type.mime
}
Expand Down Expand Up @@ -116,7 +122,7 @@ const sendMsg2RecvdApi = async function (msg) {

if (!passed) return

console.log('starting fetching api: ' + webhookUrl, msg.payload)
console.log('starting fetching api: ' + webhookUrl, formData._streams)

await fetch(webhookUrl, {
method: 'POST',
Expand Down

0 comments on commit 10ec2b7

Please sign in to comment.