generated from wechaty/puppet-mock
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 3.9.2.23 init (#180) * 3.9.2.23 initt * Update init-agent-script.js * 3.9.2.23 adapter * 3.9.2.23 init (#182) * 3.9.2.23 initt * Update init-agent-script.js * 3.9.2.23 adapter * 适配3.9.2.23 * Delete agent-script-3.9.2.23-new.js * 适配3.9.2.23 (#185) * 3.9.2.23 initt * Update init-agent-script.js * 3.9.2.23 adapter * 适配3.9.2.23 * Delete agent-script-3.9.2.23-new.js * 适配3.9.2.23 --------- Co-authored-by: LuChao <[email protected]> * add 1.3.0 illustrate * Update README.md * Update README.md * add demo * 1.13.1 * 1.13.1 * 1.13.2 dev * 增加扫码登录、检测登录状态 * 增加登入登出事件 * 增加ts改造init * 1.13.2 * 1.13.2 * 1.13.2 * 1.13.2 * 1.13.2 1. 修复获取群成员昵称乱码 * Update .npmignore * Update .gitignore * 1.13.2删除agent的ts文件 * 1.13.4 * 1.13.5 * Update init-agent-script.ts * 1.13.5 * 1.13.6 --------- Co-authored-by: choogoo <[email protected]>
- Loading branch information
Showing
21 changed files
with
3,208 additions
and
3,020 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
const rules = { | ||
"no-shadow": "off" | ||
} | ||
|
||
module.exports = { | ||
extends: '@chatie', | ||
"ignorePatterns": ["src/init-agent-script.ts", "src/init-agent-script.js"], | ||
rules, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,3 +65,6 @@ typings/ | |
t/ | ||
t.* | ||
cache/* | ||
# src/init-agent-script.ts | ||
examples/file/* | ||
examples/media/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
docs/ | ||
src/init-agent-script.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,17 +26,21 @@ wechaty-puppet-xp is a local puppet for Wechaty: | |
## GETTING STARTED | ||
|
||
- STEP 1: Install wechat client in your Windows computer. | ||
- STEP 2: Login the wechat client on the computer. | ||
- STEP 3: Getting Started with TypeScript/JavaScript (RECOMMENDED). | ||
|
||
## QUICK START | ||
> 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.12.0+ is the latest version, only support WeChat v3.6.0.18, 1.11.14 is the last version base WeChat v3.3.0.115. 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). | ||
|
||
```sh | ||
git clone https://github.com/wechaty/wechaty-puppet-xp.git | ||
cd wechaty-puppet-xp | ||
|
||
# 安装依赖 | ||
npm install | ||
|
||
# 启动程序 | ||
npm start | ||
# | ||
# Do not forget to install WeChat with requried version and login. | ||
# | ||
|
@@ -48,46 +52,51 @@ npm install | |
| `npm run start:ripe` | [examples/ripe-wechaty.ts](examples/ripe-wechaty.ts) | Wechaty ding/dong | | ||
| `npm run start:raw` | [examples/raw-sidecar.ts](examples/raw-sidecar.ts) | Sidecar ding/dong | | ||
|
||
## RUNNING WHITH NPM | ||
|
||
puppet-xp also have already released the installation package on NPM. Running with NPM and more examples can be referred to [wechaty-puppet-xp-getting-started](https://github.com/atorber/wechaty-puppet-xp-getting-started). | ||
|
||
## PUPPET COMPARISON | ||
|
||
XP is a young puppet,it keeps growing and improving. | ||
|
||
Puppet|xp👍| | ||
:---|:---| | ||
支持账号|个人微信| | ||
版本|3.3.0.115|3.6.0.18|3.9.2.23| | ||
:---|:---|:---|:---| | ||
**<消息>**| | ||
接收文本|✅ | ||
接收图片|✅ | ||
接收文件|✅ | ||
接收动图|✅ | ||
接收表情|✅ | ||
接收小程序卡片|✅ | ||
接收联系人卡片|✅ | ||
接收位置卡片|✅ | ||
发送文本|✅ | ||
发送图片|✅ | ||
发送文件|✅ | ||
发送动图|✅(以文件形式发送) | ||
接收文本|✅|✅|✅ | ||
接收图片|✅|✅|✅ | ||
接收文件|✅|✅|✅ | ||
接收动图|✅|✅|✅ | ||
接收表情|✅|✅|✅ | ||
接收小程序卡片|✅|✅|✅ | ||
接收联系人卡片|✅|✅|✅ | ||
接收位置卡片|✅|✅|✅ | ||
发送文本|✅|✅|✅ | ||
发送图片|✅|✅|✅ | ||
发送文件|✅|✅|✅ | ||
发送动图|✅|✅|✅ | ||
**<群组>**| | ||
@群成员|✅ | ||
群列表|✅ | ||
群成员列表|✅ | ||
群详情|✅ | ||
进群提示|✅ | ||
@群成员|✅|✅|✅ | ||
群列表|✅|✅|✅ | ||
群成员列表|✅|✅|✅ | ||
群详情|✅|✅|✅ | ||
进群提示|✅|✅|✅ | ||
**<联系人>**| | ||
好友列表|✅ | ||
好友详情|✅ | ||
好友列表|✅|✅|✅ | ||
好友详情|✅|✅|✅ | ||
**<其他>**| | ||
登录事件|✅ | ||
依赖协议|Windows | ||
登录事件|✅|✅|✅ | ||
扫码登录|||✅ | ||
|
||
## VERSION SUPPORT | ||
|
||
puppet-xp|wechat| | ||
|:---|:---| | ||
|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)| | ||
|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)| | ||
|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)| | ||
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| | ||
|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 [email protected]| | ||
|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 [email protected]| | ||
|
||
## HISTORY | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,265 @@ | ||
#!/usr/bin/env -S node --no-warnings --loader ts-node/esm | ||
/** | ||
* wechaty-puppet-xp示例代码,可以作为模版编写自己的业务逻辑. | ||
* | ||
**/ | ||
import 'dotenv/config.js' | ||
|
||
import { | ||
Contact, | ||
Message, | ||
ScanStatus, | ||
WechatyBuilder, | ||
log, | ||
types, | ||
} from 'wechaty' | ||
|
||
import qrcodeTerminal from 'qrcode-terminal' | ||
import { FileBox } from 'file-box' | ||
import { PuppetXp } from '../src/puppet-xp.js' | ||
|
||
const onScan = (qrcode: string, status: ScanStatus) => { | ||
if (status === ScanStatus.Waiting || status === ScanStatus.Timeout) { | ||
const qrcodeImageUrl = [ | ||
'https://wechaty.js.org/qrcode/', | ||
encodeURIComponent(qrcode), | ||
].join('') | ||
log.info('onScan: %s(%s) - %s', ScanStatus[status], status, qrcodeImageUrl) | ||
|
||
qrcodeTerminal.generate(qrcode, { small: true }) // show qrcode on console | ||
|
||
} else { | ||
log.info('onScan: %s(%s)', ScanStatus[status], status) | ||
} | ||
} | ||
|
||
const onLogin = async (user: Contact) => { | ||
log.info('onLogin', '%s login', user) | ||
// 登录成功后调用bot | ||
main() | ||
} | ||
|
||
const onLogout = (user: Contact) => { | ||
log.info('onLogout', '%s logout', user) | ||
} | ||
|
||
const onMessage = async (msg: Message) => { | ||
log.info('onMessage', JSON.stringify(msg)) | ||
// Message doc : https://wechaty.js.org/docs/api/message#messageage--number | ||
|
||
const talker = msg.talker() // 发消息人 | ||
const listener = msg.listener() // 接收消息人 | ||
const room = msg.room() // 是否是群消息 | ||
const text = msg.text() // 消息内容 | ||
const type = msg.type() // 消息类型 | ||
const self = msg.self() // 是否自己发给自己的消息 | ||
|
||
log.info('talker', JSON.stringify(talker)) | ||
log.info('listener', listener||'undefined') | ||
log.info('room', room || 'undefined') | ||
log.info('text', text) | ||
log.info('type', type) | ||
log.info('self', self?'true':'false') | ||
|
||
try { | ||
switch (text) { | ||
case 'ding': // 接收到的消息是ding,回复dong | ||
await msg.say('dong') | ||
break | ||
case 'send text': // 接收到的消息是send text,发送文本消息 | ||
await msg.say('this is a test text') | ||
break | ||
case 'send image': // 接收到的消息是send image,发送图片 | ||
const image = FileBox.fromUrl('https://wechaty.js.org/assets/logo.png') | ||
await msg.say(image) | ||
break | ||
case 'send file': // 接收到的消息是send file,发送文件 | ||
const fileBox = FileBox.fromUrl('https://wechaty.js.org/assets/logo.png') | ||
await msg.say(fileBox) | ||
break | ||
case 'send video': // 接收到的消息是send video,发送视频 | ||
const video = FileBox.fromUrl('http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4') | ||
await msg.say(video) | ||
break | ||
case 'send audio': // 接收到的消息是send audio,发送音频 | ||
const audio = FileBox.fromUrl('http://www.zhongguoyinhang.com/upload/2018-11/201811161154314128.mp3') | ||
await msg.say(audio) | ||
break | ||
case 'send emotion': // 接收到的消息是send emotion,发送表情 | ||
const emotion = FileBox.fromUrl('https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/0.gif') | ||
await msg.say(emotion) | ||
break | ||
default: | ||
break | ||
} | ||
} catch (e) { | ||
console.log('回复消息失败...', e) | ||
} | ||
|
||
try{ | ||
switch (type) { | ||
case types.Message.Text: // 接收到的消息是文本 | ||
log.info('接收到的消息是文本') | ||
log.info('消息内容:', text) | ||
break | ||
case types.Message.Image: // 接收到的消息是图片 | ||
log.info('接收到的消息是图片') | ||
const image = await msg.toImage().thumbnail() // Save the media message as a FileBox | ||
const filePath = 'examples/file/' + image.name | ||
try { | ||
image.toFile(filePath, true) | ||
log.info(`Saved file: ${filePath}`) | ||
} catch (e) { | ||
log.error('保存文件错误:', e) | ||
} | ||
break | ||
case types.Message.Attachment: // 接收到的消息是附件 | ||
log.info('接收到的消息是附件') | ||
break | ||
case types.Message.Video: // 接收到的消息是视频 | ||
log.info('接收到的消息是视频') | ||
break | ||
case types.Message.Audio: // 接收到的消息是音频 | ||
log.info('接收到的消息是音频') | ||
break | ||
case types.Message.Emoticon: // 接收到的消息是表情 | ||
log.info('接收到的消息是表情') | ||
break | ||
case types.Message.Url: // 接收到的消息是链接 | ||
log.info('接收到的消息是链接') | ||
break | ||
case types.Message.MiniProgram: // 接收到的消息是小程序 | ||
log.info('接收到的消息是小程序') | ||
break | ||
case types.Message.Transfer: // 接收到的消息是转账 | ||
log.info('接收到的消息是转账') | ||
break | ||
case types.Message.RedEnvelope: // 接收到的消息是红包 | ||
log.info('接收到的消息是红包') | ||
break | ||
case types.Message.Recalled: // 接收到的消息是撤回的消息 | ||
log.info('接收到的消息是撤回的消息') | ||
break | ||
default: | ||
break | ||
} | ||
}catch(e){ | ||
console.log('处理消息失败...', e) | ||
} | ||
// 关键词回复,同时也是发送消息的方法 | ||
} | ||
|
||
// const bot = WechatyBuilder.build({ | ||
// name: 'ding-dong-bot', | ||
// puppet: 'wechaty-puppet-xp', | ||
// puppetOptions: { | ||
// version: '3.9.2.23', | ||
// } | ||
// }) | ||
|
||
const puppet = new PuppetXp({wechatVersion:'0.0.0.0'}) | ||
const bot = WechatyBuilder.build({ | ||
name: 'ding-dong-bot', | ||
puppet, | ||
}) | ||
|
||
bot.on('scan', onScan) | ||
bot.on('login', onLogin) | ||
bot.on('logout', onLogout) | ||
bot.on('message', onMessage) | ||
|
||
bot.start() | ||
.then(async () => { | ||
log.info('StarterBot', 'Starter Bot Started.') | ||
}) | ||
.catch(e => log.error('StarterBot', e)) | ||
|
||
const main = async () => { | ||
|
||
// 获取当前登录微信信息 | ||
try { | ||
const self = bot.currentUser | ||
log.info('当前登录账号信息:', self) | ||
} catch (e) { | ||
log.error('get user failed', e) | ||
} | ||
|
||
// 通过微信号搜索联系人 | ||
try { | ||
const contactById = await bot.Contact.find({ | ||
id: 'filehelper' | ||
}) | ||
log.info('微信号查找联系人:', contactById) | ||
// 向联系人发送消息 | ||
contactById?.say('向指定好友微信号发送消息') | ||
} catch (e) { | ||
log.error('contactByWeixin', e) | ||
} | ||
|
||
// 通过昵称搜索联系人 | ||
try { | ||
const contactByName = await bot.Contact.find({ | ||
name: '文件传输助手' | ||
}) | ||
log.info('昵称查找联系人:', contactByName) | ||
// 向联系人发送消息 | ||
contactByName?.say('向指定好友昵称发送消息') | ||
} catch (e) { | ||
log.error('contactByName', e) | ||
} | ||
|
||
// 通过备注搜索联系人 | ||
try { | ||
const contactByAlias = await bot.Contact.find({ | ||
alias: '超哥' | ||
}) | ||
log.info('备注名称查找联系人:', contactByAlias || '没有找到联系人') | ||
// 向联系人发送消息 | ||
contactByAlias?.say('向指定好友备注好友发送消息') | ||
} catch (e) { | ||
log.error('contactByAlias', e) | ||
} | ||
|
||
try { | ||
// 通过群ID搜索群 | ||
const roomById = await bot.Room.find({ | ||
id: '21341182572@chatroom' | ||
}) | ||
log.info('群ID查找群:', roomById) | ||
// 向群里发送消息 | ||
roomById?.say('向指定群ID发送消息') | ||
} catch (e) { | ||
log.error('roomById', e) | ||
} | ||
|
||
try { | ||
// 通过群名称搜索群 | ||
const roomByName = await bot.Room.find({ | ||
topic: '大师是群主' | ||
}) | ||
log.info('群名称查找群:', roomByName || '没有找到群') | ||
// 向群里发送消息 | ||
roomByName?.say('向指定群名称发送消息') | ||
} catch (e) { | ||
console.log('roomByName', e) | ||
} | ||
|
||
try { | ||
// 获取所有联系人 | ||
const contactList = await bot.Contact.findAll() | ||
// log.info('获取联系人列表:', contactList) | ||
log.info('联系人数量:', contactList.length) | ||
} catch (e) { | ||
log.error('contactList', e) | ||
} | ||
|
||
try { | ||
// 获取所有群 | ||
const roomList = await bot.Room.findAll() | ||
// log.info('获取群列表:', roomList) | ||
log.info('群数量:', roomList.length) | ||
} catch (e) { | ||
log.error('roomList', e) | ||
} | ||
|
||
} |
Oops, something went wrong.