diff --git a/.gitignore b/.gitignore index d9592b4..a259d9a 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ # Dependency directories (remove the comment below to include it) # vendor/ .idea/ +go.sum diff --git a/go.mod b/go.mod index 5f98e12..06b570b 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/wechaty/go-wechaty +require github.com/otiai10/opengraph v1.1.1 + go 1.14 diff --git a/src/wechaty-puppet/schemas/contact.go b/src/wechaty-puppet/schemas/contact.go new file mode 100644 index 0000000..5461394 --- /dev/null +++ b/src/wechaty-puppet/schemas/contact.go @@ -0,0 +1,40 @@ +package schemas + +type ContactGender uint8 + +const ( + ContactGenderUnknown ContactGender = 0 + ContactGenderMale ContactGender = 1 + ContactGenderFemale ContactGender = 2 +) + +type ContactType uint8 + +const ( + ContactTypeUnknown ContactType = 0 + ContactTypePersonal ContactType = 1 + ContactTypeOfficial ContactType = 2 +) + +type ContactQueryFilter struct { + Alias string + Id string + Name string + WeiXin string +} + +type ContactPayload struct { + Id string + Gender ContactGender + Type ContactType + Name string + Avatar string + Address string + Alias string + City string + Friend bool + Province string + Signature string + Start bool + WeiXin string +} diff --git a/src/wechaty-puppet/schemas/events.go b/src/wechaty-puppet/schemas/events.go new file mode 100644 index 0000000..5b965d2 --- /dev/null +++ b/src/wechaty-puppet/schemas/events.go @@ -0,0 +1,75 @@ +package schemas + +type ScanStatus uint8 + +const ( + ScanStatusUnknown ScanStatus = 0 + ScanStatusCancel ScanStatus = 1 + ScanStatusWaiting ScanStatus = 2 + ScanStatusScanned ScanStatus = 3 + ScanStatusConfirmed ScanStatus = 4 + ScanStatusTimeout ScanStatus = 5 +) + +type EventFriendshipPayload struct { + FriendshipId string +} + +type EventLoginPayload struct { + ContactId string +} + +type EventLogoutPayload struct { + ContactId string + Data string +} + +type EventMessagePayload struct { + MessageId string +} + +type EventRoomInvitePayload struct { + RoomInvitationId string +} + +type EventRoomJoinPayload struct { + InviteeIdList []string + InviterId string + RoomId string + Timestamp int64 +} + +type EventRoomLeavePayload struct { + RemoveIdList []string + RemoverId string + RoomId string + Timestamp int64 +} + +type EventRoomTopicPayload struct { + ChangerId string + NewTopic string + OldTopic string + RoomId string + Timestamp int64 +} + +type EventScanPayload struct { + BaseEventPayload + Status ScanStatus + QrCode string +} + +type BaseEventPayload struct { + Data string +} + +type EventDongPayload = BaseEventPayload + +type EventErrorPayload = BaseEventPayload + +type EventReadyPayload = BaseEventPayload + +type EventResetPayload = BaseEventPayload + +type EventHeartbeatPayload = BaseEventPayload diff --git a/src/wechaty-puppet/schemas/friendship.go b/src/wechaty-puppet/schemas/friendship.go new file mode 100644 index 0000000..af9195b --- /dev/null +++ b/src/wechaty-puppet/schemas/friendship.go @@ -0,0 +1,57 @@ +package schemas + +type FriendshipType uint8 + +const ( + FriendshipTypeUnknown FriendshipType = 0 + FriendshipTypeConfirm FriendshipType = 1 + FriendshipTypeReceive FriendshipType = 2 + FriendshipTypeVerify FriendshipType = 3 +) + +type FriendshipSceneType uint8 + +const ( + FriendshipSceneTypeUnknown FriendshipSceneType = 0 + FriendshipSceneTypeQQ FriendshipSceneType = 1 + FriendshipSceneTypeEmail FriendshipSceneType = 2 + FriendshipSceneTypeWeiXin FriendshipSceneType = 3 + FriendshipSceneTypeQQTBD FriendshipSceneType = 12 // QQ号搜索 + FriendshipSceneTypeRoom FriendshipSceneType = 14 + FriendshipSceneTypePhone FriendshipSceneType = 15 + FriendshipSceneTypeCard FriendshipSceneType = 17 // 名片分享 + FriendshipSceneTypeLocation FriendshipSceneType = 18 + FriendshipSceneTypeBottle FriendshipSceneType = 25 + FriendshipSceneTypeShaking FriendshipSceneType = 29 + FriendshipSceneTypeQRCode FriendshipSceneType = 30 +) + +type FriendshipPayloadBase struct { + Id string + ContactId string + Hello string + Timestamp int64 +} + +type FriendshipPayloadConfirm struct { + FriendshipPayloadBase + Type FriendshipType // FriendshipTypeConfirm +} + +type FriendshipPayloadReceive struct { + FriendshipPayloadBase + Type FriendshipType // FriendshipTypeReceive + Scene FriendshipSceneType + Stranger string + Ticket string +} + +type FriendshipPayloadVerify struct { + FriendshipPayloadBase + Type FriendshipType // FriendshipTypeVerify +} + +type FriendshipSearchCondition struct { + Phone string + WeiXin string +} diff --git a/src/wechaty-puppet/schemas/image.go b/src/wechaty-puppet/schemas/image.go index 827debf..17dfad4 100644 --- a/src/wechaty-puppet/schemas/image.go +++ b/src/wechaty-puppet/schemas/image.go @@ -3,8 +3,8 @@ package schemas type ImageType uint8 const ( - Unknown ImageType = 0 - Thumbnail = 1 - HD = 2 - Artwork = 3 + Unknown ImageType = 0 + Thumbnail ImageType = 1 + HD ImageType = 2 + Artwork ImageType = 3 ) diff --git a/src/wechaty-puppet/schemas/message.go b/src/wechaty-puppet/schemas/message.go new file mode 100644 index 0000000..e450b69 --- /dev/null +++ b/src/wechaty-puppet/schemas/message.go @@ -0,0 +1,104 @@ +package schemas + +type MessageType uint8 + +const ( + MessageTypeUnknown MessageType = 0 + MessageTypeAttachment MessageType = 1 + MessageTypeAudio MessageType = 2 + MessageTypeContact MessageType = 3 + MessageTypeChatHistory MessageType = 4 + MessageTypeEmoticon MessageType = 5 + MessageTypeImage MessageType = 6 + MessageTypeText MessageType = 7 + MessageTypeLocation MessageType = 8 + MessageTypeMiniProgram MessageType = 9 + MessageTypeTransfer MessageType = 10 + MessageTypeRedEnvelope MessageType = 11 + MessageTypeRecalled MessageType = 12 + MessageTypeUrl MessageType = 13 + MessageTypeVideo MessageType = 14 +) + +type WeChatAppMessageType int + +const ( + WeChatAppMessageTypeText WeChatAppMessageType = 1 + WeChatAppMessageTypeImg WeChatAppMessageType = 2 + WeChatAppMessageTypeAudio WeChatAppMessageType = 3 + WeChatAppMessageTypeVideo WeChatAppMessageType = 4 + WeChatAppMessageTypeUrl WeChatAppMessageType = 5 + WeChatAppMessageTypeAttach WeChatAppMessageType = 6 + WeChatAppMessageTypeOpen WeChatAppMessageType = 7 + WeChatAppMessageTypeEmoji WeChatAppMessageType = 8 + WeChatAppMessageTypeVoiceRemind WeChatAppMessageType = 9 + WeChatAppMessageTypeScanGood WeChatAppMessageType = 10 + WeChatAppMessageTypeGood WeChatAppMessageType = 13 + WeChatAppMessageTypeEmotion WeChatAppMessageType = 15 + WeChatAppMessageTypeCardTicket WeChatAppMessageType = 16 + WeChatAppMessageTypeRealtimeShareLocation WeChatAppMessageType = 17 + WeChatAppMessageTypeChatHistory WeChatAppMessageType = 19 + WeChatAppMessageTypeMiniProgram WeChatAppMessageType = 33 + WeChatAppMessageTypeTransfers WeChatAppMessageType = 2000 + WeChatAppMessageTypeRedEnvelopes WeChatAppMessageType = 2001 + WeChatAppMessageTypeReaderType WeChatAppMessageType = 100001 +) + +type WeChatMessageType int + +const ( + WeChatMessageTypeText WeChatMessageType = 1 + WeChatMessageTypeImage WeChatMessageType = 3 + WeChatMessageTypeVoice WeChatMessageType = 34 + WeChatMessageTypeVerifyMsg WeChatMessageType = 37 + WeChatMessageTypePossibleFriendMsg WeChatMessageType = 40 + WeChatMessageTypeShareCard WeChatMessageType = 42 + WeChatMessageTypeVideo WeChatMessageType = 43 + WeChatMessageTypeEmoticon WeChatMessageType = 47 + WeChatMessageTypeLocation WeChatMessageType = 48 + WeChatMessageTypeApp WeChatMessageType = 49 + WeChatMessageTypeVOIPMsg WeChatMessageType = 50 + WeChatMessageTypeStatusNotify WeChatMessageType = 51 + WeChatMessageTypeVOIPNotify WeChatMessageType = 52 + WeChatMessageTypeVOIPInvite WeChatMessageType = 53 + WeChatMessageTypeMicroVideo WeChatMessageType = 62 + WeChatMessageTypeTransfer WeChatMessageType = 2000 // 转账 + WeChatMessageTypeRedEnvelope WeChatMessageType = 2001 // 红包 + WeChatMessageTypeMiniProgram WeChatMessageType = 2002 // 小程序 + WeChatMessageTypeGroupInvite WeChatMessageType = 2003 // 群邀请 + WeChatMessageTypeFile WeChatMessageType = 2004 // 文件消息 + WeChatMessageTypeSysNotice WeChatMessageType = 9999 + WeChatMessageTypeSys WeChatMessageType = 10000 + WeChatMessageTypeRecalled WeChatMessageType = 10002 +) + +type MessagePayloadBase struct { + Id string + MentionIdList []string + Filename string + Text string + Timestamp string + Type MessageType +} + +type MessagePayloadRoom struct { + FromId string + RoomId string + ToId string +} + +type MessagePayloadTo = MessagePayloadRoom + +type MessagePayload struct { + MessagePayloadBase + MessagePayloadRoom +} + +type MessageQueryFilter struct { + FromId string + Id string + RoomId string + Text string + ToId string + Type MessageType +} diff --git a/src/wechaty-puppet/schemas/mini_program.go b/src/wechaty-puppet/schemas/mini_program.go new file mode 100644 index 0000000..7051520 --- /dev/null +++ b/src/wechaty-puppet/schemas/mini_program.go @@ -0,0 +1,11 @@ +package schemas + +type MiniProgramPayload struct { + AppId string + Description string + PagePath string + ThumbUrl string + Title string + Username string + ThumbKey string +} diff --git a/src/wechaty-puppet/schemas/puppet.go b/src/wechaty-puppet/schemas/puppet.go new file mode 100644 index 0000000..7a11956 --- /dev/null +++ b/src/wechaty-puppet/schemas/puppet.go @@ -0,0 +1,7 @@ +package schemas + +type PuppetOptions struct { + endpoint string + timeout int64 + token string +} diff --git a/src/wechaty-puppet/schemas/room.go b/src/wechaty-puppet/schemas/room.go new file mode 100644 index 0000000..c1cb810 --- /dev/null +++ b/src/wechaty-puppet/schemas/room.go @@ -0,0 +1,29 @@ +package schemas + +type RoomMemberQueryFilter struct { + Name string + RoomAlias string + ContactAlias string +} + +type RoomQueryFilter struct { + Id string + Topic string +} + +type RoomPayload struct { + Id string + Topic string + Avatar string + MemberIdList []string + OwnerId string + AdminIdList []string +} + +type RoomMemberPayload struct { + Id string + RoomAlias string + InviterId string + Avatar string + Name string +} diff --git a/src/wechaty-puppet/schemas/room_invitation.go b/src/wechaty-puppet/schemas/room_invitation.go new file mode 100644 index 0000000..4bf2a81 --- /dev/null +++ b/src/wechaty-puppet/schemas/room_invitation.go @@ -0,0 +1,13 @@ +package schemas + +type RoomInvitationPayload struct { + Id string + InviterId string + Topic string + Avatar string + Invitation string + MemberCount int + MemberIdList []string + Timestamp int64 + ReceiverId string +} diff --git a/src/wechaty-puppet/schemas/url_link.go b/src/wechaty-puppet/schemas/url_link.go new file mode 100644 index 0000000..43902d8 --- /dev/null +++ b/src/wechaty-puppet/schemas/url_link.go @@ -0,0 +1,8 @@ +package schemas + +type UrlLinkPayload struct { + Description string + ThumbnailUrl string + Title string + Url string +} diff --git a/src/wechaty/user/contact.go b/src/wechaty/user/contact.go new file mode 100644 index 0000000..de207e1 --- /dev/null +++ b/src/wechaty/user/contact.go @@ -0,0 +1,7 @@ +package user + +import "github.com/wechaty/go-wechaty/src/wechaty" + +type Contact struct { + wechaty.Accessory +} diff --git a/src/wechaty/user/image.go b/src/wechaty/user/image.go index 09974f8..bb9b04e 100644 --- a/src/wechaty/user/image.go +++ b/src/wechaty/user/image.go @@ -14,7 +14,7 @@ type Images struct { // NewImages create image struct func NewImages(id string, accessory wechaty.Accessory) *Images { if accessory.Puppet == nil { - panic("Image class can not be instanciated without a puppet!") + panic("Image class can not be instantiated without a puppet!") } return &Images{accessory, id} } diff --git a/src/wechaty/user/tag.go b/src/wechaty/user/tag.go new file mode 100644 index 0000000..d3bdc94 --- /dev/null +++ b/src/wechaty/user/tag.go @@ -0,0 +1,17 @@ +package user + +import ( + "github.com/wechaty/go-wechaty/src/wechaty" +) + +type Tag struct { + wechaty.Accessory + TagId string +} + +func NewTag(id string, accessory wechaty.Accessory) *Tag { + if accessory.Puppet == nil { + panic("Tag class can not be instantiated without a puppet!") + } + return &Tag{accessory, id} +} diff --git a/src/wechaty/user/user_link.go b/src/wechaty/user/user_link.go new file mode 100644 index 0000000..1166385 --- /dev/null +++ b/src/wechaty/user/user_link.go @@ -0,0 +1,74 @@ +package user + +import ( + "errors" + "fmt" + "github.com/otiai10/opengraph" + "github.com/wechaty/go-wechaty/src/wechaty-puppet/schemas" +) + +var ( + ErrImageUrlOrDescNotFound = errors.New("imgUrl.or.desc.not.found") +) + +type UrlLink struct { + payload *schemas.UrlLinkPayload +} + +func NewUrlLink(payload *schemas.UrlLinkPayload) *UrlLink { + return &UrlLink{payload: payload} +} + +func (ul *UrlLink) String() string { + return fmt.Sprintf("UrlLink<%s>", ul.Url()) +} + +func (ul *UrlLink) Url() string { + if ul.payload == nil { + return "" + } + return ul.payload.Url +} + +func (ul *UrlLink) Title() string { + if ul.payload == nil { + return "" + } + return ul.payload.Title +} + +func (ul *UrlLink) ThumbnailUrl() string { + if ul.payload == nil { + return "" + } + return ul.payload.ThumbnailUrl +} + +func (ul *UrlLink) Description() string { + if ul.payload == nil { + return "" + } + return ul.payload.Description +} + +func CreateUrlLink(url string) (*UrlLink, error) { + var og, err = opengraph.Fetch(url) + if err != nil { + return nil, err + } + var payload = &schemas.UrlLinkPayload{ + Url: url, + Title: og.Title, + Description: og.Description, + } + + if len(og.Image) != 0 { + payload.ThumbnailUrl = og.Image[0].URL + } + + if payload.ThumbnailUrl == "" || payload.Description == "" { + return nil, ErrImageUrlOrDescNotFound + } + + return NewUrlLink(payload), nil +}