puppet-mock icon indicating copy to clipboard operation
puppet-mock copied to clipboard

bot receives messages that are not sent to him

Open panlina opened this issue 2 years ago • 1 comments

In the following code, I create 3 contacts:

  • user, which represents the bot, and
  • contactA, contactB which represent his 2 contacts.

Then I let contactA send a message to contactB. I suppose bot will not receive this message event because it's not sent to user or any room that he is in, but actually it receives this message event. Why?

var { Wechaty, Message } = require('wechaty')
var { PuppetMock, mock: { Mocker } } = require('wechaty-puppet-mock');

async function main() {
	var mocker = new Mocker();

	var puppet = new PuppetMock({ mocker });
	var bot = new Wechaty({ puppet });

	bot.on('message', message => {
		console.log(`bot received ${message.text()} from ${message.talker().payload.id}`);
	});

	await bot.start();

	mocker.scan('https://github.com/wechaty', 1);
	var user = mocker.createContact({ id: 'user' });
	mocker.login(user);

	var contactA = mocker.createContact({ id: 'contactA' });
	var contactB = mocker.createContact({ id: 'contactB' });

	contactA.say("a").to(contactB);
};

main();

The consequence is that, if I use() a Wechaty plugin, it will not work, because Wechaty plugin never suppose it will receive any messages that is not sent to the logged-in user, isn't it?

panlina avatar Nov 25 '23 11:11 panlina

Hi Panlina,

It's great to read your issue!

Very few people will do bot testing in our community, and you are one of them. ;-)

Can you join our Discord community and DM me? I'd love to work with you to improve the puppet-mock for Wechaty!

https://discord.gg/7q8NBZbQzt

huan avatar Mar 05 '24 07:03 huan