getting-started icon indicating copy to clipboard operation
getting-started copied to clipboard

ERR StarterBot TypeError: The "listener" argument must be of type function. Received undefined

Open JustinKyo opened this issue 3 years ago • 9 comments

Today, I ran the demo wechaty-getting-started with the default configuration, it was successful

But when I ran the demo with the latest versions of [email protected] and [email protected]

npm run start:wechat:padlocal

there is a bug report

21:33:56 VERB user/mixins/wechatify wechatifyUserClass(DelayImpl)(Wechaty#596d451d-a87b-4367-ad3d-340f4817231f<>(ding-dong-bot))
21:33:56 VERB user/mixins/wechatify wechatifyUserClass(TagImpl)
21:33:56 VERB user/mixins/wechatify wechatifyUserClass(TagImpl)(Wechaty#596d451d-a87b-4367-ad3d-340f4817231f<>(ding-dong-bot))
21:33:56 VERB user/mixins/wechatify wechatifyUserClass(UrlLinkImpl)
21:33:56 VERB user/mixins/wechatify wechatifyUserClass(UrlLinkImpl)(Wechaty#596d451d-a87b-4367-ad3d-340f4817231f<>(ding-dong-bot))
21:33:56 VERB user/mixins/wechatify wechatifyUserClass(LocationImpl)
21:33:56 VERB user/mixins/wechatify wechatifyUserClass(LocationImpl)(Wechaty#596d451d-a87b-4367-ad3d-340f4817231f<>(ding-dong-bot))
21:33:56 ERR StarterBot TypeError: The "listener" argument must be of type function. Received undefined
ubuntu@VM-24-16-ubuntu:/data/app/wechaty-getting-started$ 

JustinKyo avatar Nov 15 '21 13:11 JustinKyo

The PadLocal currently (v0.4) has not been adapted to Wechaty v1.x API yet.

Please use Wechaty v0.x branch at https://github.com/wechaty/getting-started/blob/v0.x/package.json

Link to:

  • https://github.com/padlocal/wechaty-puppet-padlocal/issues/104

huan avatar Nov 15 '21 14:11 huan

I have the following npm packages installed, but still have the same error:

Output from npm list

[email protected] /root/gitrepo/wechaty-puppet-padlocal-demo ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] └── [email protected]

paulhybryant avatar Dec 15 '21 07:12 paulhybryant

Workaround: use [email protected]

$ [email protected]:wechaty/getting-started.git
$ cd getting-started
$ git checkout v0.x
$ npm install
$ npm start

Details

I have just confirmed that the [email protected] can work with PadLocal without any problem:

$ git remote -v
origin  [email protected]:wechaty/wechaty-getting-started.git (fetch)
origin  [email protected]:wechaty/wechaty-getting-started.git (push)

$ git checkout v0.x
Switched to branch 'v0.x'
Your branch is up to date with 'origin/v0.x'.

$ rm -fr node_modules/  && npm install
added 1168 packages, and audited 1330 packages in 2m

$ npm ls wechaty-puppet-padlocal
[email protected] /home/huan/git/wechaty/getting-started
└── [email protected]

$ WECHATY_PUPPET=wechaty-puppet-padlocal WECHATY_PUPPET_PADLOCAL_TOKEN=puppet_padlocal_XXX npm start

> [email protected] start
> cross-env NODE_OPTIONS="--no-warnings --loader=ts-node/esm" node examples/ding-dong-bot.ts

14:57:56 VERB Puppet constructor({}) #0
14:57:56 VERB StateSwitch constructor(PuppetPadlocal, "{"log":{"enableTimestamp":true,"logLevel":4,"prefixFilter":{}}}")
14:57:56 VERB MemoryCard constructor(undefined)
14:57:56 VERB MemoryCard getStorage() for storage type: N/A
14:57:56 VERB MemoryCard load() from storage: N/A
14:57:56 VERB MemoryCard load() no storage
14:57:56 VERB Puppet constructor() watchdog timeout set to 60 seconds
14:57:56 VERB Puppet setMemory()
14:57:56 VERB StateSwitch <PuppetPadlocal> on(pending) <- (false)
14:57:57 INFO 
      ============================================================
       Welcome to Wechaty PadLocal puppet!

       - wechaty-puppet-padlocal version: 0.47.8
       - padlocal-ts-client version: 0.4.1
      ============================================================
     
14:57:57 INFO StarterBot Starter Bot Started.
14:57:58 INFO [PuppetPadlocal] start login with type: QrLogin
14:57:59 INFO StarterBot onScan: Waiting(2) - https://wechaty.js.org/qrcode/http%3A%2F%2Fweixin.qq.com%2Fx%2F4cRgClPKg7ZLeyWUDs0H
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
█ ▄▄▄▄▄ ██▄▄ ▀███▀▀▄█▄█ ▄▄▄▄▄ █
█ █   █ █▀▄  ██▄▄ ▀▀▀██ █   █ █
█ █▄▄▄█ █▄▀ █▄▀ █▄██▄ █ █▄▄▄█ █
█▄▄▄▄▄▄▄█▄▀▄█ █ █ █ ▀ █▄▄▄▄▄▄▄█
█  ▀█▀▄▄ ▀▄ █▄█▄██▄▀ ▀██▀ ▄▀▀██
█▄ █▄▀ ▄█▀▄▀ ▄█  █▄▄█ █ ▄▄█████
█ ▀ ▄▄ ▄▀▀  █▀▄██▀▄█▀ ▄  ▀█▀▀ █
█▄▄▀▄  ▄▄▀▄▀█▀█  ▄▄ ▀▄█▄█▄█ █▀█
█    ██▄ ▄█▀█▄▄  ▄▄▀ ▀▀▀ ▀▀ ▀▀█
█ ▄ ▀█ ▄  ██▀▄█  ▀██ █ ▄█▄███▄█
█▄█▄██▄▄▄▀▀▀▄▀▄█ ██▀█ ▄▄▄ ▀▄▄▄█
█ ▄▄▄▄▄ █ ▄▀█▀██ ▄▄▄  █▄█  ▄▀▀█
█ █   █ ███▄▄▄ ██ ▀▀▄  ▄▄▄▀█▄▀█
█ █▄▄▄█ █▀   ▄█▀▄▀█▀▄▄█     ▄▀█
█▄▄▄▄▄▄▄█▄▄▄▄▄██▄▄██████▄▄█▄███

^C14:58:00 VERB StateSwitch <PuppetPadlocal> off(pending) <- (false)
14:58:00 WARN [PuppetPadlocal] stop() is called on a OFF puppet. await ready(off) and return.
14:58:00 VERB StateSwitch <PuppetPadlocal> ready(off, noCross=false)
14:58:00 VERB StateSwitch <PuppetPadlocal> off(true) <- (pending)

huan avatar Dec 19 '21 07:12 huan

和题主相同错误: ERR StarterBot TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type function. Received undefined

package.json文件内容如下: { "name": "ds_bot", "version": "1.0.0", "type": "module", "description": "", "main": "index.js", "engines": { "node": ">=16", "npm": ">=7" }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "node bot.js" }, "author": "", "license": "ISC", "dependencies": { "node-schedule": "^2.1.0", "qrcode-terminal": "^0.12.0", "wechaty": "^0.73.8", "wechaty-puppet-padlocal": "^0.4.2", "wechaty-puppet-wechat": "^1.10.5" } }

Bot,js内容如下: `import { Wechaty, ScanStatus, log } from 'wechaty' import qrcodeTerminal from 'qrcode-terminal' import * as schedule from 'node-schedule';

//扫码 async function onScan (qrcode, status) { if (status === ScanStatus.Waiting || status === ScanStatus.Timeout) { const qrcodeImageUrl = [ 'https://wechaty.js.org/qrcode/', encodeURIComponent(qrcode), ].join('') log.info('StarterBot', 'onScan: %s(%s) - %s', ScanStatus[status], status, qrcodeImageUrl)

    qrcodeTerminal.generate(qrcode, { small: true })  // show qrcode on console

} else {
    log.info('StarterBot', 'onScan: %s(%s)', ScanStatus[status], status)
}

}

//登录 function onLogin (user) { log.info('StarterBot', '%s login', user)

const date = new Date()
console.log(`当前容器时间:${date}`);

// 登陆后创建定时任务
initDay();

}

//登出 function onLogout (user) { schedule.cancelJob('wechat-bot'); log.info('Bot', '%s 退出登录', user) }

//信息 async function onMessage (msg) { const contact = msg.talker(); // 发消息人 const content = msg.text().trim(); // 消息内容 const room = msg.room(); // 是否是群消息 const alias = await contact.alias() || contact.name(); // 发消息人备注 const isText = msg.type() === bot.Message.Type.Text; //是否文本文档

if (msg.self() || !isText) {
    return;
}

if(room){
    const roomId = room.id;
    room.roomAlias()

    console.log(`群聊消息: ${roomId}`)
    console.log(`发消息人: ${alias} 消息内容: ${content}`, '群消息');

} else {
    console.log(`发消息人: ${alias} 消息内容: ${content}`, '个人消息');
    //设置备注名
    if (content.substr(0, 7) === 'remakes'){
        let alias = ''
        let rgs = content.match(/(?<=【)(.+?)(?=】)/g);

        if(rgs !== null && typeof rgs === 'object' && rgs.length > 0){
            alias = rgs[0] || ''
        }

        //不为空即设置
        if(alias !== undefined && alias !== ''){
            await contact.alias(alias)
            await msg.say(`你的备注已设置为:${alias}`)
        }
    }

}

}

const bot = new Wechaty({ name: 'ding-dong-bot',

//wechaty-puppet-service    wechaty-puppet-padlocal
puppet: 'wechaty-puppet-padlocal',
puppetOptions: {
  token: 'puppet_padlocal_9fdcdf65d843a8aafa7dd2d7dc5632',
}

})

bot.on('scan', onScan) bot.on('login', onLogin) bot.on('logout', onLogout) bot.on('message', onMessage)

//设置群聊邀请 bot.on('room-invite', async roomInvitation => { const topic = await roomInvitation.topic() //群聊名 const inviter = await roomInvitation.inviter() //邀请者 const name = inviter.name() const alias = inviter.alias()

console.log(`加入群聊:${topic},邀请者; ${name},备注:${alias}`)

//加入群聊
// try {
//   await roomInvitation.accept()
// } catch (e) {
//   console.error(e)
// }

})

//有人加入群聊 room 群聊 inviteeList 所有人 inviter 邀请者 bot.on('room-join', async function(room, inviteeList, inviter) { const topic = await room.topic() //所有人昵称拼接 inviteeList.map(c => c.name()).join(','), const inviterName = inviter.name() || inviter.alias() const name = inviteeList[0] !== undefined ? inviteeList[0].name() : ''

console.log(`欢迎 ${inviterName} 邀请 ${name},加入群聊 ${topic}`)

//await room.say(`welcome to "${topic}"!`, inviteeList[0])

})

// 创建微信定时任务 async function initDay() { schedule.cancelJob('wechat-bot');

 schedule.scheduleJob('wechat-bot','*/5 * * * * *', async () => {
//   /*console.log('你的贴心小助理开始工作啦!');
//   let logMsg;
//   let contact =
//     (await bot.Contact.find({ name: config.NICKNAME })) ||
//     (await bot.Contact.find({ alias: config.NAME })); // 获取你要发送的联系人
//
//   // after logged in
//   //const roomList = await bot.Room.findAll()                    // 获取机器人的房间列表
//   //const roomList = await bot.Room.findAll({topic: 'wechaty'})  // find all of the rooms with name 'wechaty'
//
//   try {
//     await contact.say(str); // 发送消息
//   } catch (e) {
//     logMsg = e.message;
//   }*/
//   const contact = await bot.Contact.find({alias: 'master'});
//
//   try {
//     if(contact !== undefined){
//       console.log(contact.name() || contact.alias())
//       //await contact.say('定时信息');
//     }
//   } catch (e) {
//     console.log(e, 'error')
//   }
//
   const date = new Date()
   console.log(`定时器记录:${date}`);
 });

}

bot.start() //.then(() => log.info('StarterBot', 'Starter Bot Started.')) .catch(e => log.error('StarterBot', e)) // .catch(e => console.log(e, '错误日志!'))`

haibaiDS avatar Dec 19 '21 07:12 haibaiDS

Workaround: use [email protected]

TL;DR:

$ [email protected]:wechaty/getting-started.git
$ cd getting-started
$ git checkout v0.x
$ npm install
$ npm start

huan avatar Dec 20 '21 08:12 huan

According to "黑白毒师" from the group chat. You can use this workaround for now: Add "wechaty-puppet": "^0.47.8", to package.json - "dependencies"

I verified locally, it is working now.

YipZong avatar Jan 07 '22 02:01 YipZong

to follow up on this: does PadLocal support Wechaty 1.X now?

BurgerBurglar avatar May 26 '22 14:05 BurgerBurglar

It does. There was an update earlier this month. However, I have tried and it was not stable yet I think (at least if you are using it overseas). I have reverted back to 0.x

YipZong avatar May 26 '22 14:05 YipZong

I just tried with the "Getting started" repo, and it still says:

ERR StarterBot TypeError: The "listener" argument must be of type function. Received undefined

BurgerBurglar avatar May 26 '22 14:05 BurgerBurglar