【help】Create new group get` WXCreateChatRoom , stranger,error!`
Created by: allphfa
Provide Your Network Information
- Where is the location of your server? (i.e. City, or In/Out China)
Hong Kong
- Which cloud platform(AliYun/Qcloud/DigitalOcean/etc) are you using?
aliyun
npm run doctor
or wechaty run doctor
(for docker user), paste output here
Run Expected behavior
Add friends and immediately pull into a group chat
If the group does not exist to create, then pull into the group chat
Actual behavior
WXCreateChatRoom , stranger,error
Steps to reproduce the behavior (and fixes, if any)
ts-node main.ts
Full Output Logs
$ WECHATY_LOG=silly npm run ts-node mybot.ts
# or
$ WECHATY_LOG=silly node dist/mybot.js
Show Logs
WECHATY_LOG=silly
set
Paste the full output logs here with # PASTE FULL LOG OUTPUT AT HERE:
C:\Users\Administrator\Desktop\wx>ts-node src/main.ts
16:01:04 INFO Wechaty <Puppet#0<PuppetPadchat>()/PuppetPadchat#0> start() v0.19.
104 is starting...
Starter Bot Started.
Contact<只若初见> login
16:01:20 WARN PadchatRpc initWebSocket() ws.on(close) 1005
16:01:20 WARN PuppetPadchat startManager() manager.on(reset) for ws.on(close, 10
05. Restarting PuppetPadchat ...
Contact<只若初见> logout
16:01:20 WARN PuppetPadchatManager startCheckScan() checkScanLoop() exception: E
rror: WebSocket is not open: readyState 3 (CLOSED)
16:01:20 WARN PuppetPadchat startManager() manager.on(reset) for startCheckScan(
) checkScanLoop() exception. Restarting PuppetPadchat ...
Contact<只若初见> login
received `friend` event from 易优-雪芬
received `friend` event from 易优-雪芬
10
16:01:38 ERR Room create() exception: Error: WXCreateChatRoom , stranger,error!
canot get result from websocket server
at PadchatManager.<anonymous> (C:\Users\Administrator\Desktop\wx\node_module
s\wechaty-puppet-padchat\src\padchat-rpc.ts:991:13)
at Generator.next (<anonymous>)
at fulfilled (C:\Users\Administrator\Desktop\wx\node_modules\wechaty-puppet-
padchat\dist\src\padchat-rpc.js:4:58)
at process._tickCallback (internal/process/next_tick.js:68:7)
^CTerminate batch job (Y/N)? ^C
C:\Users\Administrator\Desktop\wx>
my code
import { Wechaty, Room, Contact, Friendship, log} from 'wechaty'
import { PuppetPadchat } from 'wechaty-puppet-padchat'
import { generate } from 'qrcode-terminal'
const WECHATY_PUPPET_PADCHAT_TOKEN = 'padchat-token-zhiruochujian6145263'
const puppet = new PuppetPadchat({
token: WECHATY_PUPPET_PADCHAT_TOKEN,
})
const bot = new Wechaty({ puppet, })
// chcp 437 修改代码页
const group_name = 'vip电视剧电影分享'
bot.on('scan', onScan)
bot.on('login', onLogin)
bot.on('logout', onLogout)
bot.on('message', onMessage)
bot.on('room-join', async function(room, inviteeList, inviter) {
/*
log.info( 'Bot', 'EVENT: room-join - Room "%s" got new member "%s", invited by "%s"',
await room.topic(),
inviteeList.map(c => c.name()).join(','),
inviter.name(),
)
*/
// console.log('bot room-join room id:', room.id)
const topic = await room.topic()
await room.say('欢迎进入 ' + topic + '\n\n发送: 搜 + 影片名 \n如: 搜复仇者联盟 \n即可观看影片', inviteeList[0]);
})
bot.on('room-leave', async function(room, leaverList) {
/*
log.info('Bot', 'EVENT: room-leave - Room "%s" lost member "%s"',
await room.topic(),
leaverList.map(c => c.name()).join(','),
)
const topic = await room.topic()
const name = leaverList[0] ? leaverList[0].name() : 'no contact!'
await room.say(`kick off "${name}" from "${topic}"!` )
*/
})
bot.on('friendship', async friendship => {
let logMsg
try {
logMsg = 'received `friend` event from ' + friendship.contact().name()
console.log(logMsg)
switch (friendship.type()) {
case Friendship.Type.Receive:
await friendship.accept()
break
case Friendship.Type.Confirm:
const _roomlist = await bot.Room.findAll();
console.log(_roomlist.length)
var insert = false;
for (let index = 0; index < _roomlist.length; index++) {
const _room = _roomlist[index];
let g_name = await _room.topic();
if (g_name.indexOf(group_name)>-1 && (await _room.memberList()).length < 500) {
insert = true;
await _room.add(friendship.contact());
await _room.say('欢迎 @' + friendship.contact().name() + '\n\n发送: 搜 + 影片名 \n如: 搜复仇者联盟 \n即可观看影片')
break;
}
}
if (!insert) {
let temp_name =group_name + Date.now().toString();
let _room = await bot.Room.create([], temp_name);
await _room.add(friendship.contact());
}
break
}
} catch (e) {
logMsg = e.message
}
})
bot.start()
.then(() => console.log('Starter Bot Started.'))
.catch(e => console.error(e))
function onScan (qrcode:any, status:any) {
generate(qrcode, { small: true }) // show qrcode on console
const qrcodeImageUrl = [
'https://api.qrserver.com/v1/create-qr-code/?data=',
encodeURIComponent(qrcode),
].join('');
console.log(qrcodeImageUrl);
}
function onLogin (user:any) {
console.log(`${user} login`);
}
function onLogout(user:any) {
console.log(`${user} logout`);
}
async function onMessage (msg:any) {
var text = msg.text();
text = text.replace((/^\s+/g), "");
text = text.replace((/\s+$/g), "");
const room = msg.room();
if (room) {
const topic = await room.topic()
if (topic.indexOf(group_name) > -1) {
await msg.say(msg.text());
}
}
}
/*
import {express} from 'express'
var app = express();
app.get('/', async function(req:any, res:any){
const contactList = await bot.Contact.findAll() ;
await res.send(contactList.map(c => c.name()).join('<br>'));
});
app.listen(3000);
*/