Skip to content

Commit 45289fc

Browse files
authored
add wxxd schemas, function, event
2 parents 52f939a + 14ad2cb commit 45289fc

File tree

14 files changed

+249
-7
lines changed

14 files changed

+249
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@juzi/wechaty-puppet",
3-
"version": "1.0.127",
3+
"version": "1.0.128",
44
"description": "Abstract Puppet for Wechaty",
55
"type": "module",
66
"exports": {

src/mixins/im-specific-mixin.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import {
55
import type { PuppetSkeleton } from '../puppet/puppet-skeleton.js'
66
import type { ConsultCardListRequest, ConsultCardListResponse, ContactIdExternalUserIdPair, IntentCommentPayload, PaginationRequest, PaginationResponse, PremiumOnlineAppointmentCardListRequest, PremiumOnlineAppointmentCardListResponse } from '../schemas/mod.js'
77
import type { CorpMessageInterceptionStrategy, RoomAntiSpamStrategy } from '../schemas/wecom.js'
8+
import type { WxxdShopPayload } from '../schemas/wxxd-shop.js'
9+
import type { WxxdProductPayload } from '../schemas/wxxd-product.js'
10+
import type { WxxdOrderPayload } from '../schemas/wxxd-order.js'
811

912
const imSpecificMixin = <MixinBase extends typeof PuppetSkeleton>(mixinBase: MixinBase) => {
1013

@@ -24,14 +27,23 @@ const imSpecificMixin = <MixinBase extends typeof PuppetSkeleton>(mixinBase: Mix
2427

2528
abstract getCorpMessageInterceptionStrategies (): Promise<CorpMessageInterceptionStrategy[]>
2629

27-
// douyin
30+
// 抖音
2831
abstract listConsultCards (query: ConsultCardListRequest) : Promise<ConsultCardListResponse>
2932
abstract listPremiumOnlineAppointmentCards (query: PremiumOnlineAppointmentCardListRequest) : Promise<PremiumOnlineAppointmentCardListResponse>
3033

31-
// xiaohongshu
34+
// 小红书
3235
abstract listIntentComments (query: PaginationRequest): Promise<PaginationResponse<IntentCommentPayload[]>>
3336
abstract intentCommentPayload (id: string): Promise<IntentCommentPayload>
3437

38+
// 微信小店
39+
abstract wxxdShopPayload(): Promise<WxxdShopPayload>
40+
41+
abstract listWxxdProducts(query: PaginationRequest): Promise<PaginationResponse<WxxdProductPayload[]>>
42+
abstract wxxdProductPayload(productId: string): Promise<WxxdProductPayload>
43+
44+
abstract listWxxdOrders(query: PaginationRequest): Promise<PaginationResponse<WxxdOrderPayload[]>>
45+
abstract wxxdOrderPayload(orderId: string): Promise<WxxdOrderPayload>
46+
3547
}
3648

3749
return ImSpecificMixin

src/mixins/message-mixin.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ import type {
5050
} from '../schemas/consult-card.js'
5151
import type { CallRecordPayload } from '../schemas/call.js'
5252
import type { ChatHistoryPayload } from '../schemas/chat-history.js'
53+
import type { WxxdProductPayload } from '../schemas/wxxd-product.js'
54+
import type { WxxdOrderPayload } from '../schemas/wxxd-order.js'
5355

5456
const filebox = (filebox: string | FileBoxInterface) => typeof filebox === 'string' ? FileBox.fromJSON(filebox) : filebox
5557

@@ -84,6 +86,8 @@ const messageMixin = <MinxinBase extends typeof PuppetSkeleton & CacheMixin>(bas
8486
abstract messageChannelCard (messageId: string) : Promise<ChannelCardPayload>
8587
abstract messageConsultCard (messageId: string) : Promise<ConsultCardPayload>
8688
abstract messagePremiumOnlineAppointmentCard (messageId: string) : Promise<PremiumOnlineAppointmentCardPayload>
89+
abstract messageWxxdProduct (messageId: string) : Promise<WxxdProductPayload>
90+
abstract messageWxxdOrder (messageId: string) : Promise<WxxdOrderPayload>
8791
abstract messageCallRecord (messageId: string) : Promise<CallRecordPayload>
8892
abstract messageChatHistory (messageId: string) : Promise<ChatHistoryPayload[]>
8993

@@ -102,6 +106,8 @@ const messageMixin = <MinxinBase extends typeof PuppetSkeleton & CacheMixin>(bas
102106
// im-specific
103107
abstract messageSendPremiumOnlineAppointmentCard (conversationId: string, premiumOnlineAppointmentCardSendPayload : PremiumOnlineAppointmentCardSendPayload) : Promise<void | string>
104108
abstract messageSendDouyinOneClickPhoneCollection(conversationId: string, douyinOneClickPhoneCollectionSendPayload: {}) : Promise<void | string>
109+
abstract messageSendWxxdProduct(conversationId: string, productId: string) : Promise<void | string>
110+
abstract messageSendWxxdOrder(conversationId: string, orderId: string) : Promise<void | string>
105111

106112
abstract messageRecall (messageId: string) : Promise<boolean>
107113

@@ -334,6 +340,10 @@ const messageMixin = <MinxinBase extends typeof PuppetSkeleton & CacheMixin>(bas
334340
return this.messageSendChannelCard(conversationId, sayable.payload)
335341
case sayableTypes.PremiumOnlineAppointmentCard:
336342
return this.messageSendPremiumOnlineAppointmentCard(conversationId, sayable.payload)
343+
case sayableTypes.WxxdProduct:
344+
return this.messageSendWxxdProduct(conversationId, sayable.payload.productId)
345+
case sayableTypes.WxxdOrder:
346+
return this.messageSendWxxdOrder(conversationId, sayable.payload.orderId)
337347
default:
338348
throw new Error('unsupported sayable payload: ' + JSON.stringify(sayable))
339349
}

src/mixins/sayable-mixin.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ const sayableMixin = <MixinBase extends typeof PuppetSkeleton & MessageMixin & P
7878
const premiumOnlineAppointmentCardPayload = await this.messagePremiumOnlineAppointmentCard(sayableId)
7979
return sayablePayloads.premiumOnlineAppointmentCard(premiumOnlineAppointmentCardPayload)
8080
}
81+
case MessageType.WxxdProduct: {
82+
const productId = await this.messageWxxdProduct(sayableId)
83+
return sayablePayloads.wxxdProduct(productId)
84+
}
85+
case MessageType.WxxdOrder: {
86+
const orderId = await this.messageWxxdOrder(sayableId)
87+
return sayablePayloads.wxxdOrder(orderId)
88+
}
8189
default:
8290
log.warn('PuppetSayableMixin',
8391
'sayablePayload() can not convert not re-sayable type: %s(%s) for %s\n%s',

src/puppet/events.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import type {
2929
EventIntentCommentPayload,
3030
EventContactEnterConversationPayload,
3131
EventContactLeadFilledPayload,
32+
EventWxxdProductPayload,
33+
EventWxxdOrderPayload,
3234
} from '../schemas/event.js'
3335

3436
export type PuppetDirtyListener = (payload: EventDirtyPayload) => void | Promise<void>
@@ -58,7 +60,9 @@ export type PuppetLoginUrlListener = (payload: EventLoginUrlPayload) => v
5860
export type PuppetIntentCommentListener = (payload: EventIntentCommentPayload) => void | Promise<void>
5961
export type PuppetContactEnterConversationListener = (payload: EventContactEnterConversationPayload) => void | Promise<void>
6062
export type PuppetContactLeadFilledListener = (payload: EventContactLeadFilledPayload) => void | Promise<void>
61-
63+
export type PuppetWxxdShopListener = () => void | Promise<void>
64+
export type PuppetWxxdProductListener = (payload: EventWxxdProductPayload) => void | Promise<void>
65+
export type PuppetWxxdOrderListener = (payload: EventWxxdOrderPayload) => void | Promise<void>
6266
export type PuppetStartListener = () => void | Promise<void>
6367
export type PuppetStopListener = () => void | Promise<void>
6468

@@ -92,6 +96,9 @@ interface PuppetEventListener {
9296
'verify-slide' : PuppetVerifySlideListener,
9397
'contact-enter-conversation' : PuppetContactEnterConversationListener,
9498
'contact-lead-filled' : PuppetContactLeadFilledListener,
99+
'wxxd-shop' : PuppetWxxdShopListener,
100+
'wxxd-product' : PuppetWxxdProductListener,
101+
'wxxd-order' : PuppetWxxdOrderListener,
95102
}
96103

97104
const PuppetEventEmitter = EventEmitter as unknown as new () =>

src/schemas/event.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ export interface EventContactLeadFilledPayload {
186186
}[],
187187
timestamp: number,
188188
}
189+
export interface EventWxxdProductPayload {
190+
productId: string,
191+
}
192+
193+
export interface EventWxxdOrderPayload {
194+
orderId: string,
195+
}
189196

190197
export type EventPayload =
191198
| EventDirtyPayload
@@ -215,3 +222,5 @@ export type EventPayload =
215222
| EventIntentCommentPayload
216223
| EventContactEnterConversationPayload
217224
| EventContactLeadFilledPayload
225+
| EventWxxdProductPayload
226+
| EventWxxdOrderPayload

src/schemas/message.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export enum MessageType {
2929
ChannelCard = 23, // Channel Card
3030
ConsultCard = 24, // Consult Card
3131
PremiumOnlineAppointmentCard = 25, // Premium Online Appointment Card
32+
WxxdProduct = 26, // Wxxd Product
33+
WxxdOrder = 27, // Wxxd Order
3234
}
3335

3436
/**

src/schemas/mod.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ import type {
8484
EventIntentCommentPayload,
8585
EventContactEnterConversationPayload,
8686
EventContactLeadFilledPayload,
87+
EventWxxdProductPayload,
88+
EventWxxdOrderPayload,
8789
} from './event.js'
8890
import {
8991
type RoomPayload,
@@ -185,6 +187,10 @@ import type {
185187
IntentCommentPayload,
186188
} from './xiaohongshu.js'
187189

190+
import type { WxxdShopPayload } from './wxxd-shop.js'
191+
import type { WxxdProductPayload } from './wxxd-product.js'
192+
import type { WxxdOrderPayload } from './wxxd-order.js'
193+
188194
export {
189195
CHAT_EVENT_DICT,
190196
ContactGender,
@@ -302,6 +308,11 @@ export {
302308
type TextContent,
303309
type CorpMessageInterceptionStrategy,
304310
type IntentCommentPayload,
311+
type WxxdShopPayload,
312+
type WxxdProductPayload,
313+
type WxxdOrderPayload,
314+
type EventWxxdProductPayload,
315+
type EventWxxdOrderPayload,
305316
TagEventType,
306317
TagGroupEventType,
307318
TextContentType,

src/schemas/puppet.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ export const CHAT_EVENT_DICT = {
3737
'verify-slide' : 'a verify slide is required',
3838
'contact-enter-conversation' : 'a contact enters the conversation',
3939
'contact-lead-filled' : 'a contact fills the lead card',
40+
'wxxd-shop' : 'received a new wxxd shop',
41+
'wxxd-product' : 'received a new wxxd product',
42+
'wxxd-order' : 'received a new wxxd order',
4043
}
4144
export type ChatEventName = keyof typeof CHAT_EVENT_DICT
4245

src/schemas/sayable.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import type {
1313
SayablePayloadPost,
1414
} from './post.js'
1515
import type { ConsultCardPayload, PremiumOnlineAppointmentCardPayload } from './consult-card.js'
16+
import type { WxxdProductPayload } from './wxxd-product.js'
17+
import type { WxxdOrderPayload } from './wxxd-order.js'
1618

1719
const payloadContact = (contactId: string) => ({ contactId })
1820
const payloadFilebox = (filebox: string | FileBoxInterface) => ({ filebox })
@@ -32,7 +34,8 @@ const payloadConsultCard = (consultCardPayload: ConsultCardPayl
3234
const payloadPremiumOnlineAppointmentCard = (premiumOnlineAppointmentCardPayload: PremiumOnlineAppointmentCardPayload) => ({
3335
...premiumOnlineAppointmentCardPayload,
3436
})
35-
37+
const payloadWxxdProduct = (wxxdProductPayload: WxxdProductPayload) => ({ ...wxxdProductPayload })
38+
const payloadWxxdOrder = (wxxdOrderPayload: WxxdOrderPayload) => ({ ...wxxdOrderPayload })
3639
/**
3740
* using `types` as a static typed string name list for `createAction`
3841
*
@@ -78,7 +81,8 @@ const channel = createAction(sayableTypes.Channel,
7881
const channelCard = createAction(sayableTypes.ChannelCard, payloadChannelCard)()
7982
const consultCard = createAction(sayableTypes.ConsultCard, payloadConsultCard)()
8083
const premiumOnlineAppointmentCard = createAction(sayableTypes.PremiumOnlineAppointmentCard, payloadPremiumOnlineAppointmentCard)()
81-
84+
const wxxdProduct = createAction(sayableTypes.WxxdProduct, payloadWxxdProduct)()
85+
const wxxdOrder = createAction(sayableTypes.WxxdOrder, payloadWxxdOrder)()
8286
/**
8387
* Huan(202201): Recursive type references
8488
* @link https://github.com/microsoft/TypeScript/pull/33050#issuecomment-1002455128
@@ -100,6 +104,8 @@ const sayablePayloadsNoPost = {
100104
channelCard,
101105
consultCard,
102106
premiumOnlineAppointmentCard,
107+
wxxdProduct,
108+
wxxdOrder,
103109
} as const
104110

105111
/**

0 commit comments

Comments
 (0)