-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
175 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from chatie_grpc.wechaty import ContactPayloadResponse | ||
from chatie_grpc.wechaty import ContactGender as ChatieContactGender | ||
from chatie_grpc.wechaty import ContactType as ChatieContactType | ||
|
||
from wechaty_puppet import ContactPayload, ContactGender, ContactType | ||
from wechaty_puppet_hostie.utils import get_common_attributes | ||
|
||
CONTACT_GENDER_MAP = { | ||
ChatieContactGender.CONTACT_GENDER_FEMALE.name: ContactGender.Female, | ||
ChatieContactGender.CONTACT_GENDER_MALE.name: ContactGender.Male, | ||
ChatieContactGender.CONTACT_GENDER_UNSPECIFIED.name: ContactGender.Unknown | ||
} | ||
|
||
CONTACT_TYPE_MAP = { | ||
ChatieContactType.CONTACT_TYPE_PERSONAL.name: ContactType.Personal, | ||
ChatieContactType.CONTACT_TYPE_OFFICIAL.name: ContactType.Official, | ||
ChatieContactType.CONTACT_TYPE_UNSPECIFIED.name: ContactType.Unknown | ||
} | ||
|
||
|
||
def get_contact_payload_from_response(response: ContactPayloadResponse | ||
) -> ContactPayload: | ||
""" | ||
:param response: | ||
:return: | ||
""" | ||
payload_data = response.to_dict() | ||
common_attributes = get_common_attributes(payload_data, ContactPayload) | ||
common_attributes['type'] = CONTACT_TYPE_MAP[payload_data['type']] | ||
common_attributes['gender'] = CONTACT_GENDER_MAP[payload_data['gender']] | ||
return ContactPayload(**common_attributes) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from typing import Dict | ||
|
||
from chatie_grpc.wechaty import MessageType as ChatieMessageType, \ | ||
MessagePayloadResponse | ||
|
||
from wechaty_puppet import EventMessagePayload, MessageType | ||
|
||
|
||
# TODO -> this should be improved later | ||
from wechaty_puppet_hostie.utils import get_common_attributes | ||
|
||
MESSAGE_TYPE_MAP: Dict[ChatieMessageType, MessageType] = { | ||
ChatieMessageType.MESSAGE_TYPE_MINI_PROGRAM.name: MessageType.MiniProgram, | ||
ChatieMessageType.MESSAGE_TYPE_LOCATION.name: MessageType.Location, | ||
ChatieMessageType.MESSAGE_TYPE_URL.name: MessageType.Url, | ||
ChatieMessageType.MESSAGE_TYPE_CONTACT.name: MessageType.Contact, | ||
ChatieMessageType.MESSAGE_TYPE_TEXT.name: MessageType.Text, | ||
ChatieMessageType.MESSAGE_TYPE_AUDIO.name: MessageType.Audio | ||
} | ||
|
||
|
||
def get_message_payload_from_response(response: MessagePayloadResponse | ||
) -> EventMessagePayload: | ||
""" | ||
:param response: | ||
:return: | ||
""" | ||
payload_data = response | ||
common_attributes = get_common_attributes( | ||
payload_data, EventMessagePayload) | ||
|
||
common_attributes['message_id'] = payload_data.get( | ||
'id', None) | ||
message_type = payload_data.get('type', None) | ||
if message_type is None: | ||
raise ValueError('message response data is invalid, ' | ||
'not contains type field <%s>', | ||
payload_data) | ||
common_attributes['type'] = MESSAGE_TYPE_MAP[message_type] | ||
payload = EventMessagePayload(**common_attributes) | ||
return payload | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.