Skip to content
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

[FEAT] New System Level Events #2529

Closed
hcfw007 opened this issue Apr 26, 2023 · 2 comments
Closed

[FEAT] New System Level Events #2529

hcfw007 opened this issue Apr 26, 2023 · 2 comments

Comments

@hcfw007
Copy link
Member

hcfw007 commented Apr 26, 2023

By system level events, I mean events like 'SCAN', 'LOGIN', 'FRIENDSHIP', etc.
In my opinion, current event system requires some updates.

  • Event name and classification is not unified. e.g. There are different events for room, like 'Room-Join', 'Room-Leave', etc, but there is only one 'Friendship' event。
  • Event types did not cover important notifications, espiecally info change.

We do have 'Dirty' events to invalid cache, that is working well. However you cannot listen to 'Dirty' event in bot level. So if want to know if and when some contact info has changed, there's nothing I can do. If it's a room, I can listen to 'Room-Topic' event, so there should also be a 'Contact-Name' event.

Giving more thoughts, there might be more notifications that cannot be classified into any current event. Especially for 'Wecom', because it's too closed to 'Wechat' there are lots of identification checks that you need to do with 'Wechat' on your phone.

So here's my proposal:
Step 1: Implement more events for important contact and room info changes, like, 'Room-Owner', 'Contact-Name', 'Contact-ALias', etc.
Step 2: Going further on this route, we could have an 'Update' event for any payload change on classes. It's like kinda like dirty. The listener, on my opinion, should be like this:

type WechatyEventListenerUpdate             = (info: InfoUpdateInterface) => void | Promise<void>

export const ContactImportantFields = [
  'name', 'tags', 'alias', 'phone', 'description', 'corporation',
] as const

export const RoomImportantFields = [
  'topic', 'memberIdList', 'ownerId',
] as const

type ContactImportantKeys = typeof ContactImportantFields[number]
type RoomImportantKeys = typeof RoomImportantFields[number]

type ContactUpdatableKeys = Omit<PUPPET.payloads.Contact, ContactImportantKeys>
type RoomUpdateableKeys = Omit<PUPPET.payloads.Room, RoomImportantKeys>

type PayloadTypeToUpdateInterface<U> = {
  [SubType in keyof U]: {
    type: SubType,
    id: string,
    updates: InfoUpdateValuePair<U[SubType]>[],
  }
}[keyof U]

export type InfoUpdateValuePair<U> = {
  [SubType in keyof U]: {
    key: SubType,
    oldValue?: U[SubType],
    newValue?: U[SubType],
  }
}[keyof U]

export type InfoUpdateInterface = PayloadTypeToUpdateInterface<{
  [PUPPET.types.Payload.Contact]: ContactUpdatableKeys,
  [PUPPET.types.Payload.Room]: RoomUpdateableKeys,
}>

export type ContactUpdatableValuePair = InfoUpdateValuePair<ContactUpdatableKeys>
export type RoomUpdatableValuePair = InfoUpdateValuePair<RoomUpdateableKeys>

export type ContactValuePair = InfoUpdateValuePair<PUPPET.payloads.Contact>
export type RoomValuePair = InfoUpdateValuePair<PUPPET.payloads.Room>

Step 3: I haven't think it through, but there should be a more generic system level event for those events that cannot be classified. These events usually will not kick you offline entirely, but will limit the ability of your account. e.g. You might not be able to post moments before you check your identity on your phone with 'Wechat'

@hcfw007
Copy link
Member Author

hcfw007 commented May 5, 2023

After discussion in Wechaty Community Meeting (brief here)
We believe the best way is to make system events for those that come with an IM system notification, and expose dirty events to bot level.

TODO:

  1. Emit dirty event when receiving such event from puppet
  2. Decide which notification should be made into new wechaty events. Candidates including:
  • Room Announce
  • Room Owner
  • System Notification*
  • ... To be appended

I'd like to explain a bit for System Notification. When developing puppet for Wecom, we found some actions (e.g. moment publishing) may request authorization from Wechat client. This may due to one mobile number may have mutiple Wecom account (in different orginzations), but can only have 1 Wechat account. In this way, we might need a way to notify the bot owner to check one's phone for authorization.

Copy link

dosubot bot commented Nov 19, 2023

Hi, @hcfw007! I'm Dosu, and I'm helping the Wechaty team manage their backlog. I wanted to let you know that we are marking this issue as stale.

From what I understand, you suggested implementing new system level events to improve the current event system. The proposal includes adding events for important contact and room information changes, as well as a more generic system level event for unclassified events. After discussion in the Wechaty Community Meeting, it was decided to accept this proposal. The resolution includes adding the suggested events and exposing dirty events to the bot level. The suggestion to notify the bot owner to check their phone for authorization in certain cases will also be considered.

Before we close this issue, we wanted to check with you if it is still relevant to the latest version of the Wechaty repository. If it is, please let us know by commenting on this issue. Otherwise, feel free to close the issue yourself or it will be automatically closed in 7 days.

Thank you for your contribution and we look forward to hearing from you!

@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Nov 19, 2023
@dosubot dosubot bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 26, 2023
@dosubot dosubot bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Nov 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant