Skip to content

[New Feature] send message by branding new method: say() #41

@huan

Description

@huan

Problem

When we want to send message, we need to use Wechaty.send().

If you send a lot, you will feel it a bit complicated:

const m = new Message()
m.room(room)
m.to(contact)
m.content('@' + contact.name() + ' hello')

wechaty.send(m)

It's complicated because:

  1. we have to instanciated a Message class handly
  2. we have to construct the content string for mention someone
  3. we have to get instance of Wechaty for call send(), sometimes the only way to get it is from a global variable.

Solution

Then I decide to create a new method: say(content: string, replyTo?: Contact|Contact[]): void

say() will exist in the following instances:

  1. Room instance: room.say()
  2. Message instance: msg.say()
  3. Contact instance: contact.say()
  4. this inside some of Wechaty global events callback(which has no room/message/contact instance to call say):
    1. error event callback
    2. heartbeat event callback
    3. login event callback
    4. logout event callback
    5. scan event callback

Be aware of say(content: string) inside events callback, what they behave is:

  1. If wechaty is not login yet, the only latest content will be stored, for to be sent after login.
  2. content will be send to filehelper, just for convenience logging.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions