[todo] allow Wechaty to be multi-instance
Created by: 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