@kyan-du/agent-wechat-wechaty-puppet 0.12.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +107 -0
- package/dist/mod.d.ts +3 -0
- package/dist/mod.js +5225 -0
- package/dist/poll-guard.d.ts +14 -0
- package/dist/puppet-agent-wechat.d.ts +111 -0
- package/dist/send-confirmation.d.ts +3 -0
- package/dist/type-map.d.ts +26 -0
- package/package.json +50 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type PollLifecycle = {
|
|
2
|
+
generation: number;
|
|
3
|
+
inFlight?: Promise<boolean>;
|
|
4
|
+
};
|
|
5
|
+
export type PollContext = {
|
|
6
|
+
isCurrent: () => boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare function startPollLifecycle(lifecycle: PollLifecycle): number;
|
|
9
|
+
/** Run one poll at a time; interval ticks arriving while busy are dropped. */
|
|
10
|
+
export declare function runPollIfIdle(lifecycle: PollLifecycle, generation: number, poll: (context: PollContext) => Promise<void>): Promise<boolean>;
|
|
11
|
+
export declare function invalidatePollLifecycle(lifecycle: PollLifecycle): void;
|
|
12
|
+
/** Invalidate the current generation and wait for its active poll to settle. */
|
|
13
|
+
export declare function stopPollLifecycle(lifecycle: PollLifecycle): Promise<void>;
|
|
14
|
+
//# sourceMappingURL=poll-guard.d.ts.map
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import * as PUPPET from 'wechaty-puppet';
|
|
2
|
+
import { FileBox } from 'file-box';
|
|
3
|
+
export interface PuppetAgentWeChatOptions extends PUPPET.PuppetOptions {
|
|
4
|
+
serverUrl?: string;
|
|
5
|
+
token?: string;
|
|
6
|
+
pollIntervalMs?: number;
|
|
7
|
+
}
|
|
8
|
+
export declare class PuppetAgentWeChat extends PUPPET.Puppet {
|
|
9
|
+
static readonly VERSION: any;
|
|
10
|
+
private client;
|
|
11
|
+
private pollTimer?;
|
|
12
|
+
private pollLifecycle;
|
|
13
|
+
private loginHandle?;
|
|
14
|
+
private loginTerminalSeen;
|
|
15
|
+
private loginFailureEmitted;
|
|
16
|
+
private lastSeenId;
|
|
17
|
+
private contactStore;
|
|
18
|
+
private roomStore;
|
|
19
|
+
private messageStore;
|
|
20
|
+
private rawMessageStore;
|
|
21
|
+
private get serverUrl();
|
|
22
|
+
private get token();
|
|
23
|
+
private get pollIntervalMs();
|
|
24
|
+
constructor(options?: PuppetAgentWeChatOptions);
|
|
25
|
+
name(): string;
|
|
26
|
+
version(): any;
|
|
27
|
+
onStart(): Promise<void>;
|
|
28
|
+
onStop(): Promise<void>;
|
|
29
|
+
private startLoginSubscription;
|
|
30
|
+
private emitLoginFailure;
|
|
31
|
+
private handleLoginEvent;
|
|
32
|
+
private onLoginSuccess;
|
|
33
|
+
private snapshotBaseline;
|
|
34
|
+
private startPolling;
|
|
35
|
+
private stopPolling;
|
|
36
|
+
private pollMessages;
|
|
37
|
+
private processUnreadChat;
|
|
38
|
+
private loadContacts;
|
|
39
|
+
ding(data?: string): void;
|
|
40
|
+
contactList(): Promise<string[]>;
|
|
41
|
+
contactRawPayload(contactId: string): Promise<PUPPET.payloads.Contact>;
|
|
42
|
+
contactRawPayloadParser(rawPayload: PUPPET.payloads.Contact): Promise<PUPPET.payloads.Contact>;
|
|
43
|
+
contactAlias(contactId: string): Promise<string>;
|
|
44
|
+
contactAlias(contactId: string, alias: string | null): Promise<void>;
|
|
45
|
+
contactAvatar(contactId: string): Promise<FileBox>;
|
|
46
|
+
contactAvatar(contactId: string, file: FileBox): Promise<void>;
|
|
47
|
+
contactPhone(contactId: string, phoneList: string[]): Promise<void>;
|
|
48
|
+
contactCorporationRemark(contactId: string, corporationRemark: string | null): Promise<void>;
|
|
49
|
+
contactDescription(contactId: string, description: string | null): Promise<void>;
|
|
50
|
+
contactSelfQRCode(): Promise<string>;
|
|
51
|
+
contactSelfName(name: string): Promise<void>;
|
|
52
|
+
contactSelfSignature(signature: string): Promise<void>;
|
|
53
|
+
messageRawPayload(messageId: string): Promise<PUPPET.payloads.Message>;
|
|
54
|
+
messageRawPayloadParser(rawPayload: PUPPET.payloads.Message): Promise<PUPPET.payloads.Message>;
|
|
55
|
+
/** Explicit operator path for retrying one reviewed similar-content send. */
|
|
56
|
+
messageSendTextConfirmed(conversationId: string, text: string, confirmed: true): Promise<void | string>;
|
|
57
|
+
messageSendText(conversationId: string, text: string, _mentionIdList?: string[]): Promise<void | string>;
|
|
58
|
+
messageSendFile(conversationId: string, file: FileBox): Promise<void | string>;
|
|
59
|
+
messageImage(messageId: string, imageType: PUPPET.types.Image): Promise<FileBox>;
|
|
60
|
+
messageFile(messageId: string): Promise<FileBox>;
|
|
61
|
+
private messageMediaToFileBox;
|
|
62
|
+
messageContact(messageId: string): Promise<string>;
|
|
63
|
+
messageMiniProgram(messageId: string): Promise<PUPPET.payloads.MiniProgram>;
|
|
64
|
+
messageUrl(messageId: string): Promise<PUPPET.payloads.UrlLink>;
|
|
65
|
+
messageLocation(messageId: string): Promise<PUPPET.payloads.Location>;
|
|
66
|
+
messageForward(conversationId: string, messageId: string): Promise<void | string>;
|
|
67
|
+
messageRecall(messageId: string): Promise<boolean>;
|
|
68
|
+
messageSendContact(conversationId: string, contactId: string): Promise<void | string>;
|
|
69
|
+
messageSendUrl(conversationId: string, urlLinkPayload: PUPPET.payloads.UrlLink): Promise<void | string>;
|
|
70
|
+
messageSendMiniProgram(conversationId: string, miniProgramPayload: PUPPET.payloads.MiniProgram): Promise<void | string>;
|
|
71
|
+
messageSendLocation(conversationId: string, locationPayload: PUPPET.payloads.Location): Promise<void | string>;
|
|
72
|
+
messageSendPost(conversationId: string, postPayload: PUPPET.payloads.Post): Promise<void | string>;
|
|
73
|
+
conversationReadMark(conversationId: string, hasRead?: boolean): Promise<void | boolean>;
|
|
74
|
+
roomList(): Promise<string[]>;
|
|
75
|
+
roomRawPayload(roomId: string): Promise<PUPPET.payloads.Room>;
|
|
76
|
+
roomRawPayloadParser(rawPayload: PUPPET.payloads.Room): Promise<PUPPET.payloads.Room>;
|
|
77
|
+
roomAdd(roomId: string, contactId: string): Promise<void>;
|
|
78
|
+
roomDel(roomId: string, contactId: string): Promise<void>;
|
|
79
|
+
roomCreate(contactIdList: string[], topic?: string): Promise<string>;
|
|
80
|
+
roomQuit(roomId: string): Promise<void>;
|
|
81
|
+
roomQRCode(roomId: string): Promise<string>;
|
|
82
|
+
roomTopic(roomId: string): Promise<string>;
|
|
83
|
+
roomTopic(roomId: string, topic: string): Promise<void>;
|
|
84
|
+
roomAnnounce(roomId: string): Promise<string>;
|
|
85
|
+
roomAnnounce(roomId: string, text: string): Promise<void>;
|
|
86
|
+
roomAvatar(roomId: string): Promise<FileBox>;
|
|
87
|
+
roomMemberList(roomId: string): Promise<string[]>;
|
|
88
|
+
roomMemberRawPayload(roomId: string, contactId: string): Promise<PUPPET.payloads.RoomMember>;
|
|
89
|
+
roomMemberRawPayloadParser(rawPayload: PUPPET.payloads.RoomMember): Promise<PUPPET.payloads.RoomMember>;
|
|
90
|
+
roomInvitationAccept(roomInvitationId: string): Promise<void>;
|
|
91
|
+
roomInvitationRawPayload(roomInvitationId: string): Promise<PUPPET.payloads.RoomInvitation>;
|
|
92
|
+
roomInvitationRawPayloadParser(rawPayload: PUPPET.payloads.RoomInvitation): Promise<PUPPET.payloads.RoomInvitation>;
|
|
93
|
+
friendshipAccept(friendshipId: string): Promise<void>;
|
|
94
|
+
friendshipAdd(contactId: string, option?: PUPPET.types.FriendshipAddOptions): Promise<void>;
|
|
95
|
+
friendshipSearchPhone(phone: string): Promise<null | string>;
|
|
96
|
+
friendshipSearchHandle(handle: string): Promise<null | string>;
|
|
97
|
+
friendshipRawPayload(friendshipId: string): Promise<PUPPET.payloads.Friendship>;
|
|
98
|
+
friendshipRawPayloadParser(rawPayload: PUPPET.payloads.Friendship): Promise<PUPPET.payloads.Friendship>;
|
|
99
|
+
tagContactAdd(tagId: string, contactId: string): Promise<void>;
|
|
100
|
+
tagContactRemove(tagId: string, contactId: string): Promise<void>;
|
|
101
|
+
tagContactDelete(tagId: string): Promise<void>;
|
|
102
|
+
tagContactList(contactId: string): Promise<string[]>;
|
|
103
|
+
tagContactList(): Promise<string[]>;
|
|
104
|
+
postPublish(payload: PUPPET.payloads.Post): Promise<void | string>;
|
|
105
|
+
postSearch(filter: PUPPET.filters.Post, pagination?: PUPPET.filters.PaginationRequest): Promise<PUPPET.filters.PaginationResponse<string[]>>;
|
|
106
|
+
postRawPayload(postId: string): Promise<PUPPET.payloads.Post>;
|
|
107
|
+
postRawPayloadParser(rawPayload: PUPPET.payloads.Post): Promise<PUPPET.payloads.Post>;
|
|
108
|
+
tap(postId: string, type?: PUPPET.types.Tap, tap?: boolean): Promise<void | boolean>;
|
|
109
|
+
tapSearch(postId: string, query?: PUPPET.filters.Tap, pagination?: PUPPET.filters.PaginationRequest): Promise<PUPPET.filters.PaginationResponse<PUPPET.payloads.Tap>>;
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=puppet-agent-wechat.d.ts.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as PUPPET from 'wechaty-puppet';
|
|
2
|
+
import type { Chat, Contact, Message } from '@kyan-du/agent-wechat-shared';
|
|
3
|
+
/**
|
|
4
|
+
* Map WeChat message type numbers to Wechaty MessageType.
|
|
5
|
+
*
|
|
6
|
+
* WeChat types: 1=Text, 3=Image, 34=Voice, 42=ShareCard, 43=Video,
|
|
7
|
+
* 47=Emoticon, 48=Location, 49=App(varies), 62=MicroVideo, 10000=Sys
|
|
8
|
+
*/
|
|
9
|
+
export declare function wechatTypeToMessageType(wechatType: number): PUPPET.types.Message;
|
|
10
|
+
/**
|
|
11
|
+
* Convert an agent-wechat Chat (non-group) to a Wechaty ContactPayload.
|
|
12
|
+
*/
|
|
13
|
+
export declare function chatToContactPayload(chat: Chat): PUPPET.payloads.Contact;
|
|
14
|
+
/**
|
|
15
|
+
* Convert a server Contact to a Wechaty ContactPayload.
|
|
16
|
+
*/
|
|
17
|
+
export declare function contactToContactPayload(contact: Contact): PUPPET.payloads.Contact;
|
|
18
|
+
/**
|
|
19
|
+
* Convert an agent-wechat Chat (group) to a Wechaty RoomPayload.
|
|
20
|
+
*/
|
|
21
|
+
export declare function chatToRoomPayload(chat: Chat): PUPPET.payloads.Room;
|
|
22
|
+
/**
|
|
23
|
+
* Convert an agent-wechat Message to a Wechaty MessagePayload.
|
|
24
|
+
*/
|
|
25
|
+
export declare function messageToPayload(msg: Message, selfId: string): PUPPET.payloads.Message;
|
|
26
|
+
//# sourceMappingURL=type-map.d.ts.map
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kyan-du/agent-wechat-wechaty-puppet",
|
|
3
|
+
"version": "0.12.0-next.0",
|
|
4
|
+
"description": "Wechaty Puppet for agent-wechat — bridges Wechaty bots to WeChat via the agent-wechat REST/WebSocket server",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/mod.js",
|
|
7
|
+
"types": "./dist/mod.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/mod.js",
|
|
11
|
+
"types": "./dist/mod.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"!dist/**/*.d.ts.map",
|
|
17
|
+
"!dist/.release-metafile.json"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "esbuild src/mod.ts --bundle --format=esm --platform=node --outfile=dist/mod.js --metafile=dist/.release-metafile.json --external:wechaty-puppet --external:file-box && tsc --emitDeclarationOnly",
|
|
21
|
+
"typecheck": "tsc --noEmit",
|
|
22
|
+
"test": "node --import tsx --test src/*.test.ts",
|
|
23
|
+
"test:puppet": "node --import tsx scripts/test-puppet.ts",
|
|
24
|
+
"test:contacts": "node --import tsx scripts/test-contacts.ts",
|
|
25
|
+
"test:ding-dong": "node --import tsx scripts/test-ding-dong.ts"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"wechaty-puppet": "^1.10.2"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"file-box": "^1.4.15"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@kyan-du/agent-wechat-shared": "workspace:*",
|
|
35
|
+
"@types/node": "^22",
|
|
36
|
+
"esbuild": "^0.25.0",
|
|
37
|
+
"tsx": "^4.19.0",
|
|
38
|
+
"typescript": "^5.4.5",
|
|
39
|
+
"wechaty-puppet": "^1.20.2"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public",
|
|
43
|
+
"provenance": true
|
|
44
|
+
},
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "git+https://github.com/kyan-du/agent-wechat.git",
|
|
48
|
+
"directory": "packages/wechaty-puppet"
|
|
49
|
+
}
|
|
50
|
+
}
|