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

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

Closed
huan opened this Issue Oct 9, 2016 · 2 comments

Comments

2 participants
@huan
Copy link
Member

huan commented Oct 9, 2016

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.

@huan huan added the enhancement label Oct 9, 2016

@huan huan modified the milestones: v0.4, v0.5 Oct 9, 2016

@huan huan self-assigned this Oct 9, 2016

huan added a commit that referenced this issue Oct 11, 2016

huan added a commit that referenced this issue Oct 12, 2016

huan added a commit that referenced this issue Oct 14, 2016

@huan huan closed this Oct 14, 2016

huan added a commit that referenced this issue Oct 14, 2016

@Ramonywangziyao

This comment has been minimized.

Copy link

Ramonywangziyao commented May 18, 2018

Contact is not defined error

@huan

This comment has been minimized.

Copy link
Member Author

huan commented May 18, 2018

@Ramonywangziyao Please see #1200

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment