Skip to content

Commit

Permalink
Merge branch 'dev' into nightly
Browse files Browse the repository at this point in the history
  • Loading branch information
chentianyu committed Oct 11, 2023
2 parents b38f3ef + bb793c5 commit cd67365
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ docker logs -f wxBotWebhook
- Url:<http://localhost:3001/webhook/msg>
- Methods: `POST`

#### Case1. 发文字或文件(json)
#### Case1. 发文字或文件(外链)
- ContentType: `application/json`
- Body: 格式见下面表格

Expand All @@ -87,7 +87,7 @@ docker logs -f wxBotWebhook
|--|--|--|--|--|--|
| to | **会话名**,发群消息填群名,发给个人填昵称 | `String` | - | N | - |
| isRoom | **是否发的群消息**,这个参数决定了找人的时候找的是群还是人,因为昵称其实和群名相同在技术处理上 | `Boolean` | `false` | Y | `true` `false` |
| type | **消息类型**,消息不支持自动拆分,请手动调多次,发送的文件 Url 在微信里长啥样,是文件后缀决定的。请使用 `fileUrl` 替代 `img`, `img` 类型将在后面版本废弃, | `String` | - | N | `text` `img` `fileUrl` | 支持 **文字****文件**|
| type | **消息类型**,消息不支持自动拆分,请手动调多次,发送的文件 Url 在微信里长啥样,是文件后缀决定的。| `String` | - | N | `text` `fileUrl` | 支持 **文字****文件**|
| content | **消息内容**,如果希望发多个Url并解析,type 指定为 fileUrl 同时,content 里填 url 以英文逗号分隔 | `String` | - | N | - |

#### Example(curl)
Expand All @@ -114,7 +114,7 @@ curl --location --request POST 'http://localhost:3001/webhook/msg' \
}'
```

#### Case2. 读文件发送(formData)
#### Case2. 读文件发送
- ContentType: `multipart/form-data`
- FormData: 格式见下面表格

Expand Down
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ app.use(express.json());
registerRoute({app, bot})

app.listen(PORT, () => {
console.log(`service is running, Port is ${PORT}`);
// console.log(`service is running`);
});
12 changes: 5 additions & 7 deletions src/route/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@ const { TextMsg } = require('../utils/msg')
// 登录
module.exports = function registerLoginCheck({ app, bot }) {
let message,
currentUser = null,
lastLoginUser = null,
logOutWhenError = false,
success = false

bot
.on('scan', qrcode => {
message = 'https://wechaty.js.org/qrcode/' + encodeURIComponent(qrcode)
success = false
currentUser = null
})
.on('login', user => {
message = user + 'is already login'
success = true
currentUser = user
lastLoginUser = user
logOutWhenError = false
Service.sendMsg2RecvdApi(new TextMsg({
text: JSON.stringify({ event: 'login', user }),
Expand All @@ -27,7 +26,6 @@ module.exports = function registerLoginCheck({ app, bot }) {
})
.on('logout', user => {
message = ''
currentUser = null
success = false
// 登出时给接收消息api发送特殊文本
Service.sendMsg2RecvdApi(new TextMsg({
Expand All @@ -38,20 +36,20 @@ module.exports = function registerLoginCheck({ app, bot }) {
.on('error', error => {
// 报错时接收特殊文本
Service.sendMsg2RecvdApi(new TextMsg({
text: JSON.stringify({ event: 'error', error, user: currentUser }),
text: JSON.stringify({ event: 'error', error, user: lastLoginUser }),
isSystemEvent: true
}))

// 处理异常错误后的登出上报,每次登录成功后掉线只上报一次
if (!logOutWhenError && !bot.isLoggedIn) {
Service.sendMsg2RecvdApi(new TextMsg({
text: JSON.stringify({ event: 'logout', user: currentUser }),
text: JSON.stringify({ event: 'logout', user: lastLoginUser }),
isSystemEvent: true
}))
success = false
message = ''
logOutWhenError = true
currentUser = null
lastLoginUser = null
}
})

Expand Down
3 changes: 1 addition & 2 deletions src/wechaty/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ module.exports = function init() {
bot
.on('scan', (qrcode) =>
console.log([
`\nAccess the URL to login: ${chalk.cyan('https://wechaty.js.org/qrcode/' + encodeURIComponent(qrcode))}`,
'You can also login by API: ' + chalk.cyan(`http://localhost:${PORT}/login?token=${Service.getLoginApiToken()}`)
'Access the URL to login: ' + chalk.cyan(`http://localhost:${PORT}/login?token=${Service.getLoginApiToken()}`)
].join('\n')))
.on('login', async user => console.log(chalk.green(`User ${user} logged in`)))
.on('logout', async user => console.log(chalk.red(`User ${user} logout`)))
Expand Down

0 comments on commit cd67365

Please sign in to comment.