-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
add wechaty document #725
add wechaty document #725
Conversation
Thanks! Please get at least three votes(approved) from our contributor team first, because the document needs to be improved heavily and continuously. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all those hard works for the documentation, I believe it will help other developers a lot after published.
There have two additional jobs of this PR:
- Please also generate the MarkDown file for the jsdoc by run
npm run doc
and make sure the generated document file atdocs/index.md
is what we want. - Please add
@private
to all the methods/functions which are not listed at the README API Reference section because they are just for internal use and should not be treat as published API
I also post all my reviews to the PR, please follow them as well.
src/room.ts
Outdated
@@ -547,9 +766,51 @@ export class Room extends EventEmitter implements Sayable { | |||
} | |||
|
|||
/** | |||
* @todo document me | |||
* Find member by name | roomAlias(alias) | contactAlias. | |||
* It got many, return the first |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It -> If
return -> returns
src/room.ts
Outdated
* @returns {(Contact | null)} | ||
* @example | ||
* ```ts | ||
* // change 'wechaty' to any room in your wechat |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any room -> any room name
src/room.ts
Outdated
* @example | ||
* ```ts | ||
* // change 'wechaty' to any room in your wechat | ||
* const room = await Room.find({topic: wechaty}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- const room = await Room.find({topic: wechaty})
+ const room = await Room.find({topic: 'wechaty'})
src/room.ts
Outdated
* @example | ||
* ```ts | ||
* // change 'wechaty' to any room in your wechat | ||
* const room = await Room.find({topic: wechaty}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'wechaty'
src/room.ts
Outdated
@@ -611,7 +893,18 @@ export class Room extends EventEmitter implements Sayable { | |||
} | |||
|
|||
/** | |||
* @todo document me | |||
* Find room by topic, return all the match room |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all the matched room
src/room.ts
Outdated
* Get room leave event, emitted when bot remove someone from the room or someone remove the bot from the room. | ||
* If both personA and personB are not the bot itselt, the event cannot be fired if personA remove personB from the room | ||
* This is Sayable for all listeners. | ||
* Which means there will be a this.say() the method inside listener call, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.say()
src/room.ts
Outdated
/** | ||
* @todo document me | ||
* Get room join event, emitted when someone join the room | ||
* This is Sayable for all listeners. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need not to document the this
is sayable so many times.
One time is enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I think it should document on each function because not all of the developers will read the whole doc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So do you mean that if something is important, then we should put it everywhere?
I have to disagree with you.
src/room.ts
Outdated
/** | ||
* @todo document me | ||
* Get EVENT_PARAM_ERROR event |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The EVENT_PARAM_ERROR
is just a guard for IDE Intelligence.
Need not be documented, and should be set to @private
src/room.ts
Outdated
/** | ||
* @todo document me | ||
* Get RoomEventName event |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is the implementation of all the event listeners above.
No need to be documented too.
src/room.ts
Outdated
* @example | ||
* ```ts | ||
* const room = await Room.find({name: 'wechaty'}) // change 'wechaty' to any of your room in wechat | ||
* await room.say('/test.jpg') // put the filePath you want to send here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await room.say(new MediaMessage('/test.jpg'))
here is the auto generate doc: https://github.com/lijiarui/wechaty/blob/new-doc/docs/index.md not sure why it has double wechaty intro.... will keep on dig in it, or anyone can help? @ax4 |
src/message.ts
Outdated
* | ||
* Enum for MsgType values. | ||
* @enum {number} | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should include message type in to documentation
update: I saw you write below. then should we just private this in documentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about the latest one?
https://github.com/lijiarui/wechaty/blob/master/docs/index.md#msgtype--enum
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks nice:)
maybe we should add all return promise type with notice "await" |
In our current implementation of the doc generator script BTW: I saw lots of |
Thanks, @kis87988, I had fixed that by removing the LICENSE info. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update, it looks better now.
Could you please include the docs/index.md
in the next PR?
Please make sure that the index.md file content is expected.
Have a nice weekend!
src/contact.ts
Outdated
@@ -651,6 +679,9 @@ export class Contact implements Sayable { | |||
}) | |||
} | |||
|
|||
/** | |||
* @deprecated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also @private
for @deprecated
, please.
src/message.ts
Outdated
* Set the destination as Contact for the message | ||
* | ||
* @param {Contact} contact | ||
* @returns {void} | ||
*/ | ||
public to(contact: Contact): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method should be marked as @private
because normally use should not use Wechaty API to set the destination of the message by call to()
.
We use Sayable
s to send message to contact, like contact.say()
and room.say()
src/message.ts
Outdated
/** | ||
* Set the destination as Contact by 'weixinID', eg: 'filehelper', for the message | ||
* | ||
* @param {string} id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be marked as @private
src/message.ts
Outdated
/** | ||
* Set the destination as Contact by 'weixinID', eg: 'filehelper', for the message | ||
* | ||
* @param {string} id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be marked as @private
src/message.ts
Outdated
* Set the room for a message | ||
* | ||
* @param {Room} room | ||
* @returns {void} | ||
*/ | ||
public room(room: Room): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be marked as @private
src/message.ts
Outdated
@@ -667,12 +858,34 @@ export class Message implements Sayable { | |||
// Message.initType() | |||
|
|||
export class MediaMessage extends Message { | |||
/** | |||
* @private |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if the class property is already private
, then we will not need to use @private
in jsdoc again?
src/message.ts
Outdated
* | ||
* @returns {string} | ||
* @example | ||
* ```ts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please help me to find a button with resolve
text on it, near this review message?
Because @binsee also need that button... thanks.
src/message.ts
Outdated
* | ||
* @returns {string} | ||
* @example | ||
* ```ts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please mark the review as resolved
by GitHub button.
src/room.ts
Outdated
@@ -440,7 +667,9 @@ export class Room extends EventEmitter implements Sayable { | |||
} | |||
|
|||
/** | |||
* @todo document me | |||
* Get room's owner from the room. | |||
* Not recommend, because cannot always get the owner |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add @deprecated
because it is very useless, almost no use.
src/wechaty.ts
Outdated
* const nameList = leaverList.map(c => c.name()).join(',') | ||
* console.log(`Room ${room.topic()} lost member ${nameList}`) | ||
* }) | ||
* ``` | ||
*/ | ||
public on(event: 'room-leave' , listener: (this: Wechaty, room: Room, leaverList: Contact[]) => void): this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a notice about the silent leave:
If someone leaves the room by themselves, wechat will not notice other people in the room, so the bot will never get the "leave" event.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are too many unrelated changes in the diff.
Please only keep the related change in PR.
docs/index.md
Outdated
if (ret) { | ||
console.log(`change ${contact.name()}'s alias successfully!`) | ||
} else { | ||
console.error('failed to change ${contact.name()}'s alias!') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- console.error('failed to change ${contact.name()}'s alias!')
+ console.error(`failed to change ${contact.name()}`s alias!')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
??
src/contact.ts
Outdated
@@ -1,7 +1,8 @@ | |||
/** | |||
* @ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we move @ignore
to the end of the comment, instead of at the beginning of?
src/message.ts
Outdated
public typeApp(): AppMsgType { | ||
if (!this.rawObj) { | ||
throw new Error('no rawObj') | ||
public say(textOrMedia: string | MediaMessage, replyTo?: Contact|Contact[]): Promise<any> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you rewrite so many original methods, could you get rid of all the unrelated changes?
Because it makes the diff shows lots of mess, and make the review becomes a hard job.
src/message.ts
Outdated
* @see {@link MsgType} | ||
* @returns {MsgType} | ||
*/ | ||
public type(): MsgType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same question as above: your diff should not include unrelated changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The jsdoc looks better to me now, thank you very much for all the work of writing the documents and examples!
I have some minor reviews. After resolved them, I'll be able to vote for my approvement.
docs/index.md
Outdated
if (ret) { | ||
console.log(`change ${contact.name()}'s alias successfully!`) | ||
} else { | ||
console.error('failed to change ${contact.name()}'s alias!') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
??
* @example | ||
* ```ts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could please confirm it for me that we do not need "```ts" block inside @example
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I looked into the doc and confirmed, then changed all ``` inside @example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks.
@@ -277,52 +278,40 @@ export class Contact implements Sayable { | |||
/** | |||
* Contact gender | |||
* | |||
* @returns Gender.Male(2) | Gender.Female(1) | Gender.Unknown(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just use Gender.Male
Gender.Female
and Gender.Unknown
, there's no need to refer the number value of them because that's why ENUM type exists: Do not rely on the magic numbers.
So does the other ENUM types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, m.type() return too much type, are you sure use like this?
https://github.com/lijiarui/wechaty/blob/master/docs/index.md#Message+type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Just use the ENUM names please.
src/contact.ts
Outdated
* The way to search Contact | ||
* | ||
* @typedef ContactQueryFilter | ||
* @property {string} name -the name-string set by user-self, should be called name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-the name
to - The name
?
src/contact.ts
Outdated
*/ | ||
public async say(text: string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why you deleted the overloading function declaration?
They should be kept because those are for TypeScript IDE Intelligence.
src/message.ts
Outdated
* Enum for AppMsgType values. | ||
* | ||
* @enum {number} | ||
* @property {number} TEXT - 1 for TEXT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should just let users know AppMsgType.IMG, without the exact number.
When we use Wechaty, we should just use AppMsgType.IMG instead of 2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mean change 1
to AppMsgType .TEXT
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so if there's no other problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After I thought more if any want to know the number for more development, such as ipad protocol or xposed, maybe we should tell them the wechat raw number, So I add both AppMsgType .TEXT
and 1
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll not argue with you about that, It's ok.
But I'd like to assume that the other protocols are different with the Web.
src/message.ts
Outdated
*/ | ||
public content(): string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep the overloading method declaration.
src/room.ts
Outdated
* @todo document me | ||
* @desc Room Class Event Function | ||
* @typedef RoomEventFunction | ||
* @property {Function} room-join -(this: Room, inviteeList: Contact[] , inviter: Contact) => void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a space? - (this...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job! The documentation looks good to me.
There might be something need to be modified, but I would suggest merge this PR and do these updates in successor PRs.
* Wechaty - https://github.com/chatie/wechaty | ||
* | ||
* Copyright 2016-2017 Huan LI <zixia@zixia.net> | ||
* @copyright 2016-2017 Huan LI <zixia@zixia.net> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better if all files share the same header (copyright info, license, etc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hczhcz thanks! I'll do that later by an util script written by me at https://github.com/Chatie/wechaty/blob/master/script/update-license.ts, in case you are interested at.
look forward to merge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good job
#73 #252