8000 [todo] allow Wechaty to be multi-instance · Issue #518 · wechaty/wechaty · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
[todo] allow Wechaty to be multi-instance #518
Closed
@huan

Description

@huan

Are there any friends know what's the good design pattern to do this under ES6/TypeScript?

UPDATE on Apr 28, 2018: It's a Delegation pattern

const bot1 = new Wechaty({ profile: 'bot1' })
await bot1.init()
const contact1 = await bot1.Contact.Find('name1')
// or Wechaty.Contact(bot1).Find('name1') ?

const bot2 = new Wechaty({ profile: 'bot2' })
await bot2.init()
const contact2 = await bot2.Contact.Find('name1')

bot1.on('message', async msg => {
  await bot2.say('bot1 received: ' + msg)
})

I get this idea from Google Firebase App:

P.S. today we can only use Wechaty by singleton, which means we can not get the second one. This is limited by the current design pattern: Contact/Room/etc need a global puppet instance.

const bot = Wechaty.instance()
const contact = await Contact.Find('name')

Related Classes

  • Wechaty
  • Contact
  • Room
  • FriendRequest
  • Message

See Also

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0