Skip to content

bot receives messages that are not sent to him #50

Open
@panlina

Description

@panlina

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions