-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from atorber/main
v1.14.3 修复接收视频消息bug及增加wechaty运行示例
- Loading branch information
Showing
7 changed files
with
246 additions
and
5 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
text |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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,87 @@ | ||
# WECHATY-PUPPET-WECHAT4U [![NPM](https:/wechaty/wechaty-puppet-wechat4u/actions/workflows/npm.yml/badge.svg)](https:/wechaty/wechaty-puppet-wechat4u/actions/workflows/npm.yml) | ||
|
||
[![Powered by Wechaty](https://img.shields.io/badge/Powered%20By-Wechaty-blue.svg)](https:/chatie/wechaty) | ||
[![NPM Version](https://badge.fury.io/js/wechaty-puppet-wechat4u.svg)](https://badge.fury.io/js/wechaty-puppet-wechat4u) | ||
[![npm (tag)](https://img.shields.io/npm/v/wechaty-puppet-wechat4u/next.svg)](https://www.npmjs.com/package/wechaty-puppet-wechat4u?activeTab=versions) | ||
[![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-blue.svg)](https://www.typescriptlang.org/) | ||
[![ES Modules](https://img.shields.io/badge/ES-Modules-brightgreen)](https:/Chatie/tsconfig/issues/16) | ||
|
||
![wechaty puppet wechat4u](https://wechaty.github.io/puppet-wechat4u/images/wechat4u-logo.png) | ||
|
||
Wechat4u Puppet for Wechaty | ||
|
||
See: [New Puppet - Plan to support `WECHATY_HEAD=WECHAT4U` #69](https:/Chatie/wechaty/issues/69) | ||
|
||
## ABOUT WECHAT4U | ||
|
||
[Wechat4U](https:/nodeWechat/wechat4u) is an excellent wechat bot framework that supports both Node.js & Browser, with rich features and an active community of experienced contributors. | ||
|
||
## KNOWN LIMITATIONS | ||
|
||
~~1. WeChat Account that registered after 2017 mignt not be able to login Web Wechat, so it can not use PuppetPuppeteer with Wechaty. Please make sure your WeChat Account can be able to login by visiting <https://wx.qq.com>~~ | ||
~~1. Web API can not create room and invite members to room since 2018.~~ | ||
|
||
UOS has support | ||
|
||
更新 - 2023/02/10 | ||
目前使用 1.13.14 大多数使用者可能出现微信被官方封禁提醒,从已知收集的封禁情况,暂未有可解决方案。 | ||
|
||
猜测可能与近期ChatGPT结合本仓库实现个性化机器人导致相关封禁,请合理,谨慎使用本仓库。 | ||
|
||
If you want to break the above limitations, please consider to use a Wechaty Puppet other than using Web API, like [wechaty-puppet-padchat](https:/lijiarui/wechaty-puppet-padchat). | ||
|
||
Learn more about the Puppet at [Wechaty wiki: Puppet](https:/Chatie/wechaty/wiki/Puppet) | ||
|
||
## HISTORY | ||
|
||
### v1.14.0 (April 21, 2023) | ||
|
||
1.Stable version | ||
|
||
2.Fix Contact isFriend | ||
|
||
### v1.13.8 (Nov 22, 2022) | ||
|
||
1.Fix Contact update | ||
|
||
### v1.13.1 (Nov 18, 2022) | ||
|
||
1.Support uos login | ||
|
||
2.Refactor the code to support more event | ||
|
||
### master v1.0 (Oct 30, 2021) | ||
|
||
Release 1.0 of Wechaty Puppet for Wechat4u | ||
|
||
### v0.20 (Sep 14, 2021) | ||
|
||
1. ES Modules support | ||
|
||
### v0.18 (Feb 20, 2021) | ||
|
||
Fix `wechaty-puppet` dependencies | ||
|
||
### v0.0.1 (Jun 30, 2018) | ||
|
||
Init version | ||
|
||
## MAINTAINERS | ||
|
||
- [Leo Chen](https://wechaty.js.org/contributors/leochen-g/), [Project Admin](https:/wechaty/puppet-wechat4u/pull/42#issuecomment-1324436596) | ||
- [Huan](https://wechaty.js.org/contributors/huan/), Author of Puppet WeChat4U | ||
|
||
## AUTHOR | ||
|
||
[Huan LI](http://linkedin.com/in/zixia) \<[email protected]\> | ||
|
||
<!-- markdownlint-disable MD033 --> | ||
<a href="https://stackexchange.com/users/265499"> | ||
<img src="https://stackexchange.com/users/flair/265499.png" width="208" height="58" alt="profile for zixia on Stack Exchange, a network of free, community-driven Q&A sites" title="profile for zixia on Stack Exchange, a network of free, community-driven Q&A sites"> | ||
</a> | ||
|
||
## COPYRIGHT & LICENSE | ||
|
||
- Code & Docs © 2018 Huan LI \<[email protected]\> | ||
- Code released under the Apache-2.0 License | ||
- Docs released under Creative Commons |
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,148 @@ | ||
/** | ||
* Wechaty - Conversational RPA SDK for Chatbot Makers. | ||
* - https:/wechaty/wechaty | ||
*/ | ||
import { | ||
Contact, | ||
Message, | ||
ScanStatus, | ||
WechatyBuilder, | ||
log, | ||
types, | ||
} from 'wechaty' | ||
import { FileBox } from 'file-box' | ||
|
||
import { PuppetWechat4u } from '../src/puppet-wechat4u.js' | ||
import qrcodeTerminal from 'qrcode-terminal' | ||
import fs from 'fs' | ||
|
||
function onScan (qrcode: string, status: ScanStatus) { | ||
if (qrcode) { | ||
const qrcodeImageUrl = [ | ||
'https://wechaty.js.org/qrcode/', | ||
encodeURIComponent(qrcode), | ||
].join('') | ||
console.info('StarterBot', 'onScan: %s(%s) - %s', status, qrcodeImageUrl) | ||
|
||
qrcodeTerminal.generate(qrcode, { small: true }) // show qrcode on console | ||
console.info(`[${status}] ${qrcode}\nScan QR Code above to log in: `) | ||
} else { | ||
console.info(`[${status}]`) | ||
} | ||
} | ||
|
||
async function onLogin (user: Contact) { | ||
log.info('StarterBot', '%s login', user) | ||
const roomList = await bot.Room.findAll() | ||
console.info(roomList.length) | ||
const contactList = await bot.Contact.findAll() | ||
console.info(contactList.length) | ||
} | ||
|
||
function onLogout (user: Contact) { | ||
log.info('StarterBot', '%s logout', user) | ||
} | ||
|
||
async function onMessage (msg: Message) { | ||
log.info('StarterBot', msg.toString()) | ||
if (msg.text() === 'ding') { | ||
await msg.say('dong') | ||
} | ||
|
||
const basepath = 'examples/media/' | ||
/** | ||
* 发送文件 | ||
*/ | ||
if (msg.text() === 'txt') { | ||
const newpath = basepath + 'test.txt' | ||
const fileBox = FileBox.fromFile(newpath) | ||
await msg.say(fileBox) | ||
} | ||
|
||
/** | ||
* 发送图片 | ||
*/ | ||
if (msg.text() === 'jpg') { | ||
const newpath = 'https:/wechaty/wechaty/blob/main/docs/images/bot-qr-code.png' | ||
const fileBox = FileBox.fromUrl(newpath) | ||
await msg.say(fileBox) | ||
} | ||
|
||
/** | ||
* 发送表情 | ||
*/ | ||
if (msg.text() === 'gif') { | ||
const newpath = basepath + 'test.gif' | ||
const fileBox = FileBox.fromFile(newpath) | ||
await msg.say(fileBox) | ||
} | ||
|
||
/** | ||
* 发送视频 | ||
*/ | ||
if (msg.text() === 'mp4') { | ||
const newpath = basepath + 'test.mp4' | ||
const fileBox = FileBox.fromFile(newpath) | ||
await msg.say(fileBox) | ||
} | ||
|
||
try { | ||
if (msg.type() === types.Message.Image || msg.type() === types.Message.Attachment || msg.type() === types.Message.Video || msg.type() === types.Message.Audio || msg.type() === types.Message.Emoticon) { | ||
const file = await msg.toFileBox() // Save the media message as a FileBox | ||
const filePath = 'examples/file/' + file.name | ||
file.toFile(filePath) | ||
log.info(`Saved file: ${filePath}`) | ||
} else { | ||
// Log other non-text messages | ||
const logData = { | ||
date: new Date(), | ||
from: msg.talker().name(), | ||
text: msg.text(), | ||
type: msg.type(), | ||
} | ||
const logPath = 'examples/log/message.log' | ||
fs.appendFileSync(logPath, JSON.stringify(logData, null, 2) + '\n') | ||
log.info(`Logged message data to ${logPath}`) | ||
} | ||
} catch (e) { | ||
console.error(`Error handling message: ${e}`) | ||
} | ||
|
||
} | ||
|
||
const puppet = new PuppetWechat4u() | ||
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.on('room-join', async (room, inviteeList, inviter) => { | ||
const nameList = inviteeList.map(c => c.name()).join(',') | ||
log.info(`Room ${await room.topic()} got new member ${nameList}, invited by ${inviter}`) | ||
}) | ||
bot.on('room-leave', async (room, leaverList, remover) => { | ||
const nameList = leaverList.map(c => c.name()).join(',') | ||
log.info(`Room ${await room.topic()} lost member ${nameList}, the remover is: ${remover}`) | ||
}) | ||
bot.on('room-topic', async (room, topic, oldTopic, changer) => { | ||
log.info(`Room ${await room.topic()} topic changed from ${oldTopic} to ${topic} by ${changer.name()}`) | ||
}) | ||
bot.on('room-invite', async roomInvitation => { | ||
log.info(JSON.stringify(roomInvitation)) | ||
try { | ||
log.info('received room-invite event.') | ||
await roomInvitation.accept() | ||
} catch (e) { | ||
console.error(e) | ||
} | ||
}) | ||
|
||
bot.start() | ||
.then(() => { | ||
return log.info('StarterBot', 'Starter Bot Started.') | ||
}) | ||
.catch(console.error) |
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
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