Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add messageSendText/contactSelfInfo/contactList/roomList #237

Merged
merged 9 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
run: ./scripts/npm-pack-testing.sh

publish:
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/v'))
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/3'))
name: Publish
needs: [build, pack]
runs-on: ubuntu-latest
Expand Down Expand Up @@ -85,7 +85,7 @@ jobs:
- name: Check Branch
id: check-branch
run: |
if [[ ${{ github.ref }} =~ ^refs/heads/(main|v[0-9]+\.[0-9]+.*)$ ]]; then
if [[ ${{ github.ref }} =~ ^refs/heads/(main|[0-9]+\.[0-9]+\.[0-9].*)$ ]]; then
echo ::set-output name=match::true
fi # See: https://stackoverflow.com/a/58869470/1123955
- name: Is A Publish Branch
Expand Down
42 changes: 30 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ wechaty-puppet-xp is a local puppet for Wechaty:

- STEP 1: Install wechat client in your Windows computer.

> 1.13.0+ is the latest version, only support WeChat v3.9.2.23. Note to use the npm package that matches the WeChat version.
> 1.13.+ is the latest version, only support WeChat v3.9.2.23. Note to use the npm package that matches the WeChat version.

- STEP 2: Login the wechat client on the computer.
- STEP 3: Getting Started with TypeScript/JavaScript (RECOMMENDED).
Expand Down Expand Up @@ -62,32 +62,32 @@ puppet-xp also have already released the installation package on NPM. Running wi

XP is a young puppet,it keeps growing and improving.

版本|3.3.0.115|3.6.0.18|3.9.2.23|
:---|:---|:---|:---|
版本|3.3.0.115|3.6.0.18|3.9.2.23|3.9.10.27|
:---|:---|:---|:---|:---|
**<消息>**|
接收文本|✅|✅|✅
接收文本|✅|✅|✅|✅
接收图片|✅|✅|✅
接收文件|✅|✅|✅
接收动图|✅|✅|✅
接收表情|✅|✅|✅
接收文件|✅|✅|✅|✅
接收动图|✅|✅|✅|✅
接收表情|✅|✅|✅|✅
接收小程序卡片|✅|✅|✅
接收联系人卡片|✅|✅|✅
接收位置卡片|✅|✅|✅
发送文本|✅|✅|✅
发送文本|✅|✅|✅|✅
发送图片|✅|✅|✅
发送文件|✅|✅|✅
发送动图|✅|✅|✅
**<群组>**|
@群成员|✅|✅|✅
群列表|✅|✅|✅
群列表|✅|✅|✅|✅
群成员列表|✅|✅|✅
群详情|✅|✅|✅
进群提示|✅|✅|✅
**<联系人>**|
好友列表|✅|✅|✅
好友列表|✅|✅|✅|✅
好友详情|✅|✅|✅
**<其他>**|
登录事件|✅|✅|✅
登录事件|✅|✅|✅|✅
扫码登录|||✅

## VERSION SUPPORT
Expand All @@ -96,12 +96,30 @@ Note: You need to install an NPM version that matches your WeChat client version

puppet-xp|wechat|npm install|
|:---|:---|:---|
|1.3.x|[WeChat-v3.9.2.23](https://github.com/tom-snow/wechat-windows-versions/releases/download/v3.9.2.23/WeChatSetup-3.9.2.23.exe)|npm i wechaty-puppet-xp@next|
|2.1.1|[WeChat-v3.9.10.27](https://github.com/tom-snow/wechat-windows-versions/releases/download/v3.9.10.27/WeChatSetup-3.9.10.27.exe)|npm i wechaty-puppet-xp@2.1.1|
|1.13.12|[WeChat-v3.9.2.23](https://github.com/tom-snow/wechat-windows-versions/releases/download/v3.9.2.23/WeChatSetup-3.9.2.23.exe)|npm i wechaty-puppet-xp@1.3.12|
|1.12.7|[WeChat-v3.6.0.18](https://github.com/tom-snow/wechat-windows-versions/releases/download/v3.6.0.18/WeChatSetup-3.6.0.18.exe)|npm i wechaty-puppet-xp@1.12.7|
|1.11.14|[WeChat-v3.3.0.115](https://github.com/wechaty/wechaty-puppet-xp/releases/download/v0.5/WeChatSetup-v3.3.0.115.exe)|npm i wechaty-puppet-xp@1.11.14|

## HISTORY

### v2.1.1

1. Support WeChat version 3.9.10.27
2. Support list
- getMyselfInfo
- contactList
- sendMsg
- recvMsg

### v2.0.0

1. Support WeChat version 3.9.10.19
2. Support list
- getMyselfInfo
- sendMsg
- recvMsg

### v1.13.12

1. Fixed the bug where the system crashes upon receiving a message before successful startup
Expand Down
101 changes: 101 additions & 0 deletions examples/raw-sidecar-hook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/* eslint-disable no-console */

/**
* Wechaty - https://github.com/wechaty/wechaty
*
* @copyright 2021 Wechaty Contributors <https://github.com/wechaty>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import {
attach,
detach,
} from 'sidecar'

import {
WeChatSidecar,
// XpSidecar
} from '../src/wechat-sidecar.js'

async function main () {
console.log('WeChat Sidecar starting...')

const sidecar = new WeChatSidecar()
await attach(sidecar)

console.log('WeChat Sidecar started.')

sidecar.on('hook', ({ method, args }) => {
// console.log(`onhook事件消息:${new Date().toLocaleString()}\n`, method, JSON.stringify(args))
console.log(`onhook事件消息:${new Date().toLocaleString()}`, method)
switch (method) {
case 'recvMsg':{
void onRecvMsg(args)
break
}
case 'checkQRLogin':
break
case 'loginEvent':{
break
}
case 'agentReady':
console.log('agentReady...')
break
default:
console.log('onHook没有匹配到处理方法:', method, JSON.stringify(args))
break
}
})

const onRecvMsg = async (args: any) => {
console.log('onRecvMsg事件触发:', JSON.stringify(args))

if (args instanceof Error) {
console.error('onRecvMsg: 参数错误 Error', args)
return
}

const toId = String(args[3])
const text = String(args[2])
const talkerId = String(args[1])

// const nickname = await sidecar.GetContactOrChatRoomNickname(talkerId)
// console.log('发言人昵称:', nickname)
console.log('talkerId:', talkerId)
console.log('toId:', toId)
console.log('text:', text)
if (talkerId && text === 'ding') {
console.log('叮咚测试: ding found, reply dong')
try {
await sidecar.sendMsg(talkerId || toId, 'dong')
// await sidecar.sendAtMsg(toId, 'dong',talkerId)
} catch (e) {
console.error('发送消息失败:', e)
}
}
}

const clean = () => {
console.log('Sidecar detaching...')
void detach(sidecar)
}

process.on('SIGINT', clean)
process.on('SIGTERM', clean)
}

main()
.catch(e => {
console.error('主函数运行失败:', e)
})
87 changes: 40 additions & 47 deletions examples/raw-sidecar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,22 @@ import {

import {
WeChatSidecar,
// XpSidecar
} from '../src/wechat-sidecar.js'

async function main () {
console.info('WeChat Sidecar starting...')
// new XpSidecar({ wechatVersion: '3.9.2.23' })

const sidecar = new WeChatSidecar()
await attach(sidecar)

console.info('WeChat Sidecar started.')

const ver = await sidecar.getWeChatVersion()
const verStr = await sidecar.getWechatVersionString()
const isSupported = await sidecar.checkSupported()
console.info(`\nWeChat Version: ${ver} -> ${verStr} , Supported: ${isSupported}\n`)

const isLoggedIn = await sidecar.isLoggedIn()
// const isLoggedIn = await sidecar.isLoggedIn()
const myselfInfo = await sidecar.getMyselfInfo()
console.info(`当前登陆账号信息: ${myselfInfo}`)

const loginUrl = await sidecar.getLoginUrl()
console.info(`登陆二维码地址loginUrl: ${loginUrl}`)
// const loginUrl = await sidecar.getLoginUrl()
// console.info(`登陆二维码地址loginUrl: ${loginUrl}`)

// const contact = await sidecar.getChatroomMemberInfo()
// //console.log(contact)
Expand All @@ -74,18 +67,18 @@ async function main () {
void onScan(args)
break
case 'loginEvent':{
if (!isLoggedIn) {
let loginRes = false
sidecar.isLoggedIn().then(res => {
loginRes = res
if (loginRes) {
void onLogin()
}
return res
}).catch(e => {
console.error('登录状态检查失败:', e)
})
}
// if (!isLoggedIn) {
// let loginRes = false
// sidecar.isLoggedIn().then(res => {
// loginRes = res
// if (loginRes) {
// void onLogin()
// }
// return res
// }).catch(e => {
// console.error('登录状态检查失败:', e)
// })
// }
break
}
case 'agentReady':
Expand All @@ -100,31 +93,31 @@ async function main () {
}
})

const onLogin = async () => {
console.info('登陆事件触发')
console.info(`登陆状态: ${isLoggedIn}`)
// await sidecar.sendMsg('filehelper', 'Sidecar is ready!')
const contacts = await sidecar.getContact()
// console.log(`contacts: ${contacts}`)
const contactsJSON = JSON.parse(contacts)
console.log('contacts列表:', contactsJSON.length)

for (const contact of contactsJSON) {
if (!contact.name) {
console.info('好友:', JSON.stringify(contact))
}
}
// const onLogin = async () => {
// console.info('登陆事件触发')
// console.info(`登陆状态: ${isLoggedIn}`)
// await sidecar.sendMsg('filehelper', 'Sidecar is ready!')
// const contacts = await sidecar.getContact()
// console.log(`contacts: ${contacts}`)
// const contactsJSON = JSON.parse(contacts)
// console.log('contacts列表:', contactsJSON.length)

// for (const contact of contactsJSON) {
// if (!contact.name) {
// console.info('好友:', JSON.stringify(contact))
// }
// }

const roomList = await sidecar.getChatroomMemberInfo()
// console.log(`roomList: ${roomList}`)
const roomListJSON = JSON.parse(roomList)
console.log('roomList列表:', roomListJSON.length)
// for (const room of roomListJSON) {
// console.info('room:', room)
// }
// await sidecar.sendAtMsg('21341182572@chatroom', new Date().toLocaleString(), 'atorber', '超哥');
// const roomList = await sidecar.getChatroomMemberInfo()
// console.log(`roomList: ${roomList}`)
// const roomListJSON = JSON.parse(roomList)
// console.log('roomList列表:', roomListJSON.length)
// for (const room of roomListJSON) {
// console.info('room:', room)
// }
// await sidecar.sendAtMsg('21341182572@chatroom', new Date().toLocaleString(), 'atorber', '超哥');

}
// }

const onLogout = (bySrv: number) => {
console.info('登出事件触发:', bySrv)
Expand Down Expand Up @@ -170,8 +163,8 @@ async function main () {
// const nickname = await sidecar.GetContactOrChatRoomNickname(talkerId)
// console.log('发言人昵称:', nickname)

const talker = await sidecar.getChatroomMemberNickInfo(talkerId, toId)
console.log('发言人:', talker)
// const talker = await sidecar.getChatroomMemberNickInfo(talkerId, toId)
// console.log('发言人:', talker)
if (talkerId && text === 'ding') {
console.info('叮咚测试: ding found, reply dong')
await sidecar.sendMsg(toId, 'dong')
Expand Down
13 changes: 7 additions & 6 deletions examples/ripe-wechaty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ async function onLogin (user: Contact) {
log.info('好友数量:', friends.length)

// 发送@好友消息
const room = await bot.Room.find({topic:'大师是群主'})
const contact = await bot.Contact.find({name:'luyuchao'})
log.info('room:', room)
if(room && contact){
const contacts:Contact[]= [contact]
const room = await bot.Room.find({ topic:'大师是群主' })
const contact = await bot.Contact.find({ name:'luyuchao' })
await contact?.say('你好,我是瓦力!')

if (room && contact) {
const contacts:Contact[] = [ contact ]
await room.say(new Date().toLocaleString() + ':瓦力上线了!', ...contacts)
}
}
Expand Down Expand Up @@ -140,7 +141,7 @@ async function onMessage (msg: Message) {

}

const puppet = new PuppetXp({ wechatVersion:'0.0.0.0' })
const puppet = new PuppetXp()
const bot = WechatyBuilder.build({
name: 'ding-dong-bot',
puppet,
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wechaty-puppet-xp",
"version": "1.13.12",
"version": "2.1.1",
"description": "Puppet XP for Wechaty",
"type": "module",
"exports": {
Expand All @@ -18,7 +18,7 @@
"clean": "shx rm -fr dist/*",
"dist": "npm-run-all clean build dist:copy dist:commonjs",
"build:agent": "tsc src/init-agent-script.ts --outFile src/init-agent-script.js",
"frida": "tsc tests/frida.ts --outFile tests/frida.js && frida -n WeChat.exe -l tests/frida.js --debug",
"frida": "frida -n WeChat.exe -l src/init-agent-script.js --debug",
"build": "tsc && tsc -p tsconfig.cjs.json",
"dist:commonjs": "jq -n \"{ type: \\\"commonjs\\\" }\" > dist/cjs/package.json",
"dist:copy": "npm-run-all copy:esm copy:cjs",
Expand All @@ -29,6 +29,7 @@
"start:raw": "cross-env BROLOG_LEVEL=silly NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node examples/raw-sidecar.ts",
"start:raw:nobuild": "cross-env BROLOG_LEVEL=info NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node examples/raw-sidecar.ts",
"start:raw:info": "npm run build:agent && cross-env BROLOG_LEVEL=info NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node examples/raw-sidecar.ts",
"start:raw:hook": "npm run build:agent && cross-env BROLOG_LEVEL=info NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node examples/raw-sidecar-hook.ts",
"start:ripe": "cross-env WECHATY_LOG=verbose NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node examples/ripe-wechaty.ts",
"start:ripe:info": "npm run build:agent && cross-env WECHATY_LOG=info NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node examples/ripe-wechaty.ts",
"start:ripe:demo": "npm run build:agent && cross-env WECHATY_LOG=info NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node examples/demo.ts",
Expand Down Expand Up @@ -83,8 +84,9 @@
"wechaty-puppet": "^1.10.2"
},
"dependencies": {
"@swc/core": "^1.5.25",
"cuid": "^2.1.8",
"sidecar": "^0.17.8",
"sidecar": "^1.0.19",
"xml2js": "^0.4.23",
"xmlreader": "^0.2.3"
},
Expand Down
Loading
Loading