Closed suntong closed 4 years ago
If I understand you right, you want to control the messages that emit from the mocked puppet.
Currently, the wechaty-puppet-mock just send a text message periodly, that's because it's not fully implemented yet.
In order to let us control what message wechaty can receive(so that we could do unit tests), there was an idea in my head and I'd like to share it with you.
The sample code should look like this:
import { PuppetMock } from `wechaty-puppet-mock`
import { Wechaty } from 'wechaty'
const puppet = new PuppetMock()
const bot = new Wechaty({ puppet })
bot.on('message', msg => console.log(msg))
await bot.start()
const from = await bot.Contact.find({ name: 'huan' })
const to = await bot.userSelf()
puppet.mockMessage(from, to, ';)')
puppet.mockMessage(from, to, 'https://chatie.io/wechaty/images/bot-qr-code.png')
puppet.mockMessage(from, to, 'hello - https://chatie.io/wechaty/images/bot-qr-code.png')
puppet.mockMessage(from, to, FileBox.fromUrl('https://chatie.io/wechaty/images/bot-qr-code.png'))
Oh, then it is harder than I thought, which was to alter this loop,
to send from/loop through a predefined message array, instead of sending a pre-cached one.
OK. I'll wait for your first move then.
BTW, as for the smiley, this is what I meant:
'<img class="emoji emoji1f4a4" text="[流汗]_web" src="/zh_CN/htmledition/v2/images/spacer.gif" />',
'<img class="qqemoji qqemoji13" text="[呲牙]_web" src="/zh_CN/htmledition/v2/images/spacer.gif" />',
'<img class="emoji emoji1f44d" text="_web" src="/zh_CN/htmledition/v2/images/spacer.gif" />',
'<span class="emoji emoji1f334"></span>',
It's not hard but we need to clarify your use case first.
Why do you care about this XML <img class="emoji emoji1f4a4" text="[流汗]_web" src="/zh_CN/htmledition/v2/images/spacer.gif" />
? It's a little tricky because that the wechaty has no standard for this kind of message yet. It might be [流汗]
or 😅
dependes on the puppet implementation.
Could you explain your use case in detail?
Those are what I actually received when using the wechaty-puppet-puppeteer, although what appeared on the phone are different. Here are some more real examples in my log (via console.log(msg.toString())
):
能抗得住<img class="qqemoji qqemoji20" text="[偷笑]_web" src="/...
死机了<img class="qqemoji qqemoji10" text="[尴尬]_web" src="/zh_CN/...
万全之策?<img class="qqemoji qqemoji13" text="[呲牙]_web...
<img class="qqemoji qqemoji81" text="[握手]_web" src="/zh_CN/htmledition/v2/images/spacer.gif" /><img class="qqemoji qqemoji81" text="[握手]_web" src="/zh_CN/htmledition/v2/images/spacer.gif" /><img class="qqemoji qqemoji81" text="[握手]_web" src="/zh_CN/htmledition/v2/images/spacer.gif" />
<img class="qqemoji qqemoji81" text="[Shake]_web" src="/zh_CN/htmledition/v2/images/spacer.gif" />早<img class="qqemoji qqemoji0" text="[Smile]_web" src="/zh_CN/htmledition/v2/images/spacer.gif" />'
踢! <img class="emoji emoji26bd" text="_web" src="/zh_CN/htmle...
<a target="_blank" href="/cgi-bin/mmwebwx-bin/webwxcheckurl?requrl=htt...
Thus, I'm trying to simulate those actual raw messages so that I can better filter/handle them.
async function onMessage (msg) {
console.log(msg.toString())
}
Understood.
So if you can create a new mock message as you want, and you can let wechaty emit it as a new message, does that fulfill your requirement?
Hmm... as long as there is a place in wechaty-puppet-mock/src/puppet-mock.ts that I/people can add new extra messages that wechaty-puppet-mock
can emit, besides all existing ones, say for e.g., by just adding to the predefined array etc, then I'm happy.
I.e., it can be predefined and no need for any dynamically creating new mock messages.
I believe the latest PR #36 is related to this discussion.
Closed due to inactivity for years.
Originally posted in dev chat group:
Basically I'm planning to add more mock cases to mock output. Instead of outputting merely
mock text
, it'll loop through a predefined array, so the mock output message will be something like this:Would that be a good idea?
However, there is a big problem, I'm thinking, which is that, the
wechaty-puppet-puppeteer
and thewechaty-puppet-padpro
have different output formats, e.g., smiley raw string will be different between the two, IIRC. I.e., we might needwechaty-puppet-mock
to be the base class, and define/usewechaty-puppet-mock-puppeteer
andwechaty-puppet-mock-padpro
instead.Just a thought. Comments?