Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I use this function keyroom.add(contact),it doesn't work #1601

Closed
jimmywangzhiping opened this issue Sep 21, 2018 · 1 comment
Closed

I use this function keyroom.add(contact),it doesn't work #1601

jimmywangzhiping opened this issue Sep 21, 2018 · 1 comment

Comments

@jimmywangzhiping
Copy link

jimmywangzhiping commented Sep 21, 2018

'use strict';
const { Wechaty } = require('wechaty');

const bot = Wechaty.instance();
bot.on('scan', url => {
  const loginurl = url.replace('qrcode', 'l');
  require('qrcode-terminal').generate(loginurl);
  console.log(url);
})
  .on('login', user => {
    console.log(`${user} login`);
  })
  .on('friend', async function name(contact, request) {
    if (request) {
      await request.accept();
      console.log(`Contact: ${contact.name()} send Request ${request.hello}`);
    }
  })
  .on('message', async function(m) {
    const contact = m.from();
    const content = m.content();
    const room = m.room();
    if (room) {
      console.log(`Room:${room.topic()}  Contact:${contact.name()}  Content: ${content}`);
    } else {
      console.log(`Contact: ${contact.name()} Content:${content}`);
    }
    if (m.self()) {
      return;
    }
    if (/hello/.test(content)) {
      m.say('hello how are you');
    }
    if (/room/.test(content)) {
      const keyroom = await bot.Room.find({ topic: 'test' });
      if (keyroom) {
        try {
          // console.log(contact);
          // await keyroom.add(contact);
          const roResult = await keyroom.add(contact);
          console.log(`roResult is ${roResult}`);
        } catch (error) {
          console.error(error);
        }
        await keyroom.say('welcome', contact);
      }
    }
    if (/out/.test(content)) {
      const keyroom = await bot.Room.find({ topic: 'test' });
      if (keyroom) {
        await keyroom.say('Remove from room', contact);
        await keyroom.del(contact);
      }
    }
  })
  .init();
const roResult = await keyroom.add(contact);

the roResult is undefined;it doesn't join the keyroom.

@lijiarui
Copy link
Member

Need More Information

Sorry, you did not follow the ISSUE Template, and there's not enough information about your problem.

In order to help us to find the problem out, you should provide all the detail information about the issue. Please make sure you are following the ISSUE Template, answer all the question, and the more important: provide the steps to reproduce the problem.

I'll close this issue. Please re-submit a new issue to provide the information that needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants