-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Closed
Description
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:
- we have to instanciated a
Message
class handly - we have to construct the
content
string for mention someone - we have to get instance of
Wechaty
for callsend()
, 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:
- Room instance:
room.say()
- Message instance:
msg.say()
- Contact instance:
contact.say()
this
inside some of Wechaty global events callback(which has no room/message/contact instance to callsay
):error
event callbackheartbeat
event callbacklogin
event callbacklogout
event callbackscan
event callback
Be aware of say(content: string)
inside events callback, what they behave is:
- If wechaty is not login yet, the only latest
content
will be stored, for to be sent after login. content
will be send tofilehelper
, just for convenience logging.