getting-started
getting-started copied to clipboard
ding-dong-bot.js can't be started with wechaty-puppet-mock
Important:Please file the issue follow the template, or we won't help you to solve the problem.
0. Report Issue Guide
- Please run the following command and check whether the problem has been fixed:
rm -rf package-lock.json
rm -rf node_modules
npm install
Not fixed.
- Please search in FAQ List first, and make sure your problem has not been solved before.
Done.
- Please search in the issue first, and make sure your problem had not been reported before
Done.
1. Versions
- What is your wechaty version?
- What is your wechaty-puppet-XXX(padchat/puppeteer/) version?
npm ls wechaty wechaty-puppet wechaty-puppet-mock wechaty-puppet-padplus
[email protected] /path/to/wechaty-examples
├─┬ [email protected]
│ └── UNMET PEER DEPENDENCY [email protected] deduped
├── UNMET PEER DEPENDENCY [email protected]
├── [email protected]
└─┬ [email protected]
└─┬ [email protected]
└── [email protected]
-
Which puppet are you using for wechaty? (padchat/puppeteer/padpro/...) Answer:
wechaty-puppet-mock -
What is your node version? (run
node --version) Answer: v10.21.0 -
What os are you using Answer:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04 LTS
Release: 20.04
Codename: focal
2. Describe the bug
ding-dong-bot.js can't be started with wechaty-puppet-mock
3. To Reproduce
Steps to reproduce the behavior:
-
remove
require('./.util/helper')line fromding-dong-bot.js -
under
wechaty-getting-started, runWECHATY_PUPPET=wechaty-puppet-mock WECHATY_LOG=silly node examples/ding-dong-bot.js
4. Expected behavior
Received mock messages continuously.
5. Actual behavior
Mock messages not received.
6. Full Output Logs
Show Logs
$ WECHATY_PUPPET=wechaty-puppet-mock WECHATY_LOG=silly node examples/ding-dong-bot.js
19:43:45 SILL Puppet Config: WECHATY_LOG set level to silly
19:43:45 INFO Config registering process.on("unhandledRejection") for development/debug
19:43:45 VERB Config constructor()
19:43:46 VERB Wechaty constructor()
19:43:46 VERB StateSwitch constructor(Wechaty, "{"log":{"enableTimestamp":true,"logLevel":5,"prefixFilter":{}}}")
19:43:46 VERB StateSwitch constructor(WechatyReady, "{"log":{"enableTimestamp":true,"logLevel":5,"prefixFilter":{}}}")
19:43:46 VERB Wechaty on(scan, listener) registered
19:43:46 VERB Wechaty on(login, listener) registered
19:43:46 VERB Wechaty on(logout, listener) registered
19:43:46 VERB Wechaty on(message, listener) registered
19:43:46 VERB Wechaty <wechaty-puppet-mock>(ding-dong-bot) start() v0.41.17 is starting...
19:43:46 VERB Wechaty id: ckeovwwjo0000vefu2rmm1lwz
19:43:46 SILL StateSwitch <Wechaty> on() is false
19:43:46 SILL StateSwitch <WechatyReady> off() is true
19:43:46 VERB StateSwitch <WechatyReady> off(true) <- (true)
19:43:46 SILL StateSwitch <Wechaty> on() is false
19:43:46 VERB StateSwitch <Wechaty> on(pending) <- (false)
19:43:46 VERB MemoryCard constructor("ding-dong-bot")
19:43:46 VERB MemoryCard getStorage() for storage type: N/A
19:43:46 VERB getStorage name: ding-dong-bot, options: {"type":"file"}
19:43:46 VERB StorageFile constructor(ding-dong-bot, ...)
19:43:46 VERB StorageBackend constructor(ding-dong-bot, { type: file })
19:43:46 VERB MemoryCard load() from storage: StorageFile</path/to/wechaty-getting-started/ding-dong-bot.memory-card.json>
19:43:46 VERB StorageFile load() from /path/to/wechaty-getting-started/ding-dong-bot.memory-card.json
19:43:46 VERB Wechaty initPuppet()
19:43:46 VERB MemoryCard multiplex(puppet)
19:43:46 VERB MemoryCard static multiplex(MemoryCard<ding-dong-bot>, puppet)
19:43:46 VERB MemoryCard constructor({"name":"ding-dong-bot","multiplex":{"name":"puppet","parent":{"options":{"name":"ding-dong-bot"},"name":"ding-dong-bot","payload":{"\rpuppet\nPUPPET_PUPPETEER":[{"name":"mm_lang","value":"en","domain":".wx.qq.com","path":"/","expires":1586873706,"size":9,"httpOnly":false,"secure":true,"session":false},{"name":"MM_WX_NOTIFY_STATE","value":"1","domain":"wx.qq.com","path":"/","expires":-1,"size":19,"httpOnly":false,"secure":false,"session":true},{"name":"MM_WX_SOUND_STATE","value":"1","domain":"wx.qq.com","path":"/","expires":-1,"size":18,"httpOnly":false,"secure":false,"session":true}]},"multiplexNameList":[],"storage":{"name":"ding-dong-bot","options":{"type":"file"},"absFileName":"/path/to/wechaty-getting-started/ding-dong-bot.memory-card.json"}}}})
19:43:46 VERB PuppetManager resolve({puppet: wechaty-puppet-mock, puppetOptions: undefined})
19:43:46 VERB PuppetManager resolveName(wechaty-puppet-mock)
19:43:46 VERB PuppetManager checkModule(wechaty-puppet-mock)
19:43:46 SILL PuppetManager checkModule() wechaty-puppet-mock installed version 0.22.31 satisfied range ^0.22.3
19:43:46 VERB Puppet constructor({}) #0
19:43:46 VERB StateSwitch constructor(PuppetMock, "{"log":{"enableTimestamp":true,"logLevel":5,"prefixFilter":{}}}")
19:43:46 VERB MemoryCard constructor(undefined)
19:43:46 VERB MemoryCard getStorage() for storage type: N/A
19:43:46 VERB MemoryCard load() from storage: N/A
19:43:46 VERB MemoryCard load() no storage
19:43:46 VERB Puppet constructor() watchdog timeout set to 60 seconds
19:43:46 VERB HotImport callerResolve(., /path/to/wechaty-getting-started/node_modules/wechaty-puppet/dist/src/puppet.js)
19:43:46 SILL HotImport callerResolve() callsites() file=/path/to/wechaty-getting-started/node_modules/hot-import/dist/src/hot-import.js, type=Object
19:43:46 SILL HotImport callerResolve() callsites() file=/path/to/wechaty-getting-started/node_modules/wechaty-puppet/dist/src/puppet.js, type=null
19:43:46 SILL HotImport callerResolve() callsites() file=/path/to/wechaty-getting-started/node_modules/wechaty/node_modules/wechaty-puppet-mock/dist/src/puppet-mock.js, type=null
19:43:46 SILL HotImport callerResolve() callerFile=/path/to/wechaty-getting-started/node_modules/wechaty/node_modules/wechaty-puppet-mock/dist/src/puppet-mock.js
19:43:46 VERB Puppet constructor() childClassPath=/path/to/wechaty-getting-started/node_modules/wechaty/node_modules/wechaty-puppet-mock/dist/src
19:43:46 VERB PuppetMock constructor()
19:43:46 VERB PuppetMock constructor() creating the default mocker
19:43:46 VERB Mocker constructor()
19:43:46 SILL MockAccessory <MockContact> static set mocker = "Mocker<ckeovwwrw0000vefufra2fyd4>"
19:43:46 SILL MockAccessory <MockMessage> static set mocker = "Mocker<ckeovwwrw0000vefufra2fyd4>"
19:43:46 SILL MockAccessory <MockRoom> static set mocker = "Mocker<ckeovwwrw0000vefufra2fyd4>"
19:43:46 VERB Puppet constructor() memory.load() done
19:43:46 VERB Puppet setMemory()
19:43:46 VERB Wechaty initPuppetEventBridge(Puppet#0<PuppetMock>(ding-dong-bot))
19:43:46 VERB Wechaty initPuppetEventBridge() puppet.on(friendship) (listenerCount:0) registering...
19:43:46 VERB Wechaty initPuppetEventBridge() puppet.on(login) (listenerCount:0) registering...
19:43:46 VERB Wechaty initPuppetEventBridge() puppet.on(logout) (listenerCount:0) registering...
19:43:46 VERB Wechaty initPuppetEventBridge() puppet.on(message) (listenerCount:0) registering...
19:43:46 VERB Wechaty initPuppetEventBridge() puppet.on(room-invite) (listenerCount:0) registering...
19:43:46 VERB Wechaty initPuppetEventBridge() puppet.on(room-join) (listenerCount:0) registering...
19:43:46 VERB Wechaty initPuppetEventBridge() puppet.on(room-leave) (listenerCount:0) registering...
19:43:46 VERB Wechaty initPuppetEventBridge() puppet.on(room-topic) (listenerCount:0) registering...
19:43:46 VERB Wechaty initPuppetEventBridge() puppet.on(scan) (listenerCount:0) registering...
19:43:46 VERB Wechaty initPuppetEventBridge() puppet.on(dong) (listenerCount:0) registering...
19:43:46 VERB Wechaty initPuppetEventBridge() puppet.on(error) (listenerCount:0) registering...
19:43:46 VERB Wechaty initPuppetEventBridge() puppet.on(heartbeat) (listenerCount:1) registering...
19:43:46 VERB Wechaty initPuppetEventBridge() puppet.on(ready) (listenerCount:0) registering...
19:43:46 VERB Wechaty initPuppetEventBridge() puppet.on(reset) (listenerCount:1) registering...
19:43:46 VERB Wechaty initAccessory(Puppet#0<PuppetMock>(ding-dong-bot))
19:43:46 SILL Accessory <Contact> static set wechaty = "Wechaty#ckeovwwjo0000vefu2rmm1lwz<>(ding-dong-bot)"
19:43:46 SILL Accessory <ContactSelf> static set wechaty = "Wechaty#ckeovwwjo0000vefu2rmm1lwz<>(ding-dong-bot)"
19:43:46 SILL Accessory <Friendship> static set wechaty = "Wechaty#ckeovwwjo0000vefu2rmm1lwz<>(ding-dong-bot)"
19:43:46 SILL Accessory <Image> static set wechaty = "Wechaty#ckeovwwjo0000vefu2rmm1lwz<>(ding-dong-bot)"
19:43:46 SILL Accessory <Message> static set wechaty = "Wechaty#ckeovwwjo0000vefu2rmm1lwz<>(ding-dong-bot)"
19:43:46 SILL Accessory <Room> static set wechaty = "Wechaty#ckeovwwjo0000vefu2rmm1lwz<>(ding-dong-bot)"
19:43:46 SILL Accessory <RoomInvitation> static set wechaty = "Wechaty#ckeovwwjo0000vefu2rmm1lwz<>(ding-dong-bot)"
19:43:46 SILL Accessory <Tag> static set wechaty = "Wechaty#ckeovwwjo0000vefu2rmm1lwz<>(ding-dong-bot)"
19:43:46 SILL Accessory <Contact> static set puppet = "Puppet#0<PuppetMock>(ding-dong-bot)"
19:43:46 SILL Accessory <ContactSelf> static set puppet = "Puppet#0<PuppetMock>(ding-dong-bot)"
19:43:46 SILL Accessory <Friendship> static set puppet = "Puppet#0<PuppetMock>(ding-dong-bot)"
19:43:46 SILL Accessory <Image> static set puppet = "Puppet#0<PuppetMock>(ding-dong-bot)"
19:43:46 SILL Accessory <Message> static set puppet = "Puppet#0<PuppetMock>(ding-dong-bot)"
19:43:46 SILL Accessory <Room> static set puppet = "Puppet#0<PuppetMock>(ding-dong-bot)"
19:43:46 SILL Accessory <RoomInvitation> static set puppet = "Puppet#0<PuppetMock>(ding-dong-bot)"
19:43:46 SILL Accessory <Tag> static set puppet = "Puppet#0<PuppetMock>(ding-dong-bot)"
19:43:46 VERB PuppetMock start()
19:43:46 SILL StateSwitch <PuppetMock> on() is false
19:43:46 SILL StateSwitch <PuppetMock> on() is false
19:43:46 VERB StateSwitch <PuppetMock> on(pending) <- (false)
19:43:46 SILL StateSwitch <PuppetMock> on() is pending
19:43:46 VERB StateSwitch <PuppetMock> on(true) <- (pending)
19:43:46 VERB Wechaty on(heartbeat, listener) registered
19:43:46 SILL StateSwitch <Wechaty> on() is pending
19:43:46 VERB StateSwitch <Wechaty> on(true) <- (pending)
19:43:46 INFO StarterBot Starter Bot Started.
19:43:46 VERB Mocker start()
19:43:46 SILL MockAccessory <MockContact> static set mocker = "Mocker<ckeovwwrw0000vefufra2fyd4>"
19:43:46 SILL MockAccessory <MockMessage> static set mocker = "Mocker<ckeovwwrw0000vefufra2fyd4>"
19:43:46 SILL MockAccessory <MockRoom> static set mocker = "Mocker<ckeovwwrw0000vefufra2fyd4>"
^C
7. Additional context
N.A.
[bug]
The wechaty-puppet-mock now will not emit any message any more by default.
You need to specify an Environment for our mocking if you want the mocking environment to interact with your bot.
See: https://github.com/wechaty/wechaty-puppet-mock#mocker--environment
OK. Thanks.
So, how to make use of the wechaty-puppet-mock now?
Looking from the source, it seems to me that I need to launch a "Mocker & Environment" instant first, then start the "Puppet Mock" instant, as my normal client, is it? Apart from SimpleEnvironment(), what else Environment() can we choose?
Also, can we still change the puppet on the fly from out side as it used to be?
I.e., previously it was only a matter of switching to WECHATY_PUPPET=wechaty-puppet-mock from ipad or puppeteer, to start
node examples/ding-dong-bot.js
without changing/touch the script at all. Can we still do that now? Thx!
Bump, Can we still do that now? Thx!
Also, can we still change the puppet on the fly from outside as it used to be?
Currently, we can only change puppet to wechaty-puppet-mock on the fly from outside, but if you want to emit auto-generated messages, it can not be set on the fly yet. (PR will be welcome!)
We can start to receive the auto-generated message from puppet mock by the following code:
import {
PuppetMock,
Mocker,
SimpleEnvironment,
} from 'wechaty-puppet-mock'
const mocker = new Mocker()
mocker.use(SimpleEnvironment())
const puppet = new PuppetMock({ mocker })
const wechaty = new Wechaty({ puppet })
wechaty.start()
// The Mocker will start perform the SimpleEnvironment...