@pacoyang/wechaty-puppet-wechat 0.28.5
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/.editorconfig +14 -0
- package/.eslintrc.js +7 -0
- package/.github/workflows/npm.yml +91 -0
- package/.markdownlintrc +13 -0
- package/.travis.yml +62 -0
- package/.vscode/settings.json +73 -0
- package/CODEOWNERS +9 -0
- package/LICENSE +201 -0
- package/NOTICE +8 -0
- package/README.md +145 -0
- package/dist/examples/demo.d.ts +20 -0
- package/dist/examples/demo.d.ts.map +1 -0
- package/dist/examples/demo.js +113 -0
- package/dist/examples/demo.js.map +1 -0
- package/dist/scripts/retry-unit-tests.d.ts +10 -0
- package/dist/scripts/retry-unit-tests.d.ts.map +1 -0
- package/dist/scripts/retry-unit-tests.js +47 -0
- package/dist/scripts/retry-unit-tests.js.map +1 -0
- package/dist/src/bridge.d.ts +100 -0
- package/dist/src/bridge.d.ts.map +1 -0
- package/dist/src/bridge.js +927 -0
- package/dist/src/bridge.js.map +1 -0
- package/dist/src/bridge.spec.d.ts +21 -0
- package/dist/src/bridge.spec.d.ts.map +1 -0
- package/dist/src/bridge.spec.js +191 -0
- package/dist/src/bridge.spec.js.map +1 -0
- package/dist/src/config.d.ts +10 -0
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/config.js +57 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/event.d.ts +23 -0
- package/dist/src/event.d.ts.map +1 -0
- package/dist/src/event.js +166 -0
- package/dist/src/event.js.map +1 -0
- package/dist/src/event.spec.d.ts +3 -0
- package/dist/src/event.spec.d.ts.map +1 -0
- package/dist/src/event.spec.js +41 -0
- package/dist/src/event.spec.js.map +1 -0
- package/dist/src/firer.d.ts +50 -0
- package/dist/src/firer.d.ts.map +1 -0
- package/dist/src/firer.js +409 -0
- package/dist/src/firer.js.map +1 -0
- package/dist/src/firer.spec.d.ts +21 -0
- package/dist/src/firer.spec.d.ts.map +1 -0
- package/dist/src/firer.spec.js +190 -0
- package/dist/src/firer.spec.js.map +1 -0
- package/dist/src/mod.d.ts +23 -0
- package/dist/src/mod.d.ts.map +1 -0
- package/dist/src/mod.js +28 -0
- package/dist/src/mod.js.map +1 -0
- package/dist/src/puppet-wechat.d.ts +164 -0
- package/dist/src/puppet-wechat.d.ts.map +1 -0
- package/dist/src/puppet-wechat.js +1287 -0
- package/dist/src/puppet-wechat.js.map +1 -0
- package/dist/src/puppet-wechat.spec.d.ts +21 -0
- package/dist/src/puppet-wechat.spec.d.ts.map +1 -0
- package/dist/src/puppet-wechat.spec.js +123 -0
- package/dist/src/puppet-wechat.spec.js.map +1 -0
- package/dist/src/pure-function-helpers/is-type.d.ts +3 -0
- package/dist/src/pure-function-helpers/is-type.d.ts.map +1 -0
- package/dist/src/pure-function-helpers/is-type.js +12 -0
- package/dist/src/pure-function-helpers/is-type.js.map +1 -0
- package/dist/src/pure-function-helpers/message-extname.d.ts +3 -0
- package/dist/src/pure-function-helpers/message-extname.d.ts.map +1 -0
- package/dist/src/pure-function-helpers/message-extname.js +44 -0
- package/dist/src/pure-function-helpers/message-extname.js.map +1 -0
- package/dist/src/pure-function-helpers/message-filename.d.ts +3 -0
- package/dist/src/pure-function-helpers/message-filename.d.ts.map +1 -0
- package/dist/src/pure-function-helpers/message-filename.js +19 -0
- package/dist/src/pure-function-helpers/message-filename.js.map +1 -0
- package/dist/src/pure-function-helpers/message-raw-payload-parser.d.ts +4 -0
- package/dist/src/pure-function-helpers/message-raw-payload-parser.d.ts.map +1 -0
- package/dist/src/pure-function-helpers/message-raw-payload-parser.js +67 -0
- package/dist/src/pure-function-helpers/message-raw-payload-parser.js.map +1 -0
- package/dist/src/pure-function-helpers/mod.d.ts +7 -0
- package/dist/src/pure-function-helpers/mod.d.ts.map +1 -0
- package/dist/src/pure-function-helpers/mod.js +23 -0
- package/dist/src/pure-function-helpers/mod.js.map +1 -0
- package/dist/src/pure-function-helpers/normalize-scan-status.d.ts +3 -0
- package/dist/src/pure-function-helpers/normalize-scan-status.d.ts.map +1 -0
- package/dist/src/pure-function-helpers/normalize-scan-status.js +21 -0
- package/dist/src/pure-function-helpers/normalize-scan-status.js.map +1 -0
- package/dist/src/pure-function-helpers/normalize-scan-status.spec.d.ts +21 -0
- package/dist/src/pure-function-helpers/normalize-scan-status.spec.d.ts.map +1 -0
- package/dist/src/pure-function-helpers/normalize-scan-status.spec.js +37 -0
- package/dist/src/pure-function-helpers/normalize-scan-status.spec.js.map +1 -0
- package/dist/src/pure-function-helpers/web-message-type.d.ts +4 -0
- package/dist/src/pure-function-helpers/web-message-type.d.ts.map +1 -0
- package/dist/src/pure-function-helpers/web-message-type.js +58 -0
- package/dist/src/pure-function-helpers/web-message-type.js.map +1 -0
- package/dist/src/pure-function-helpers/xml.d.ts +14 -0
- package/dist/src/pure-function-helpers/xml.d.ts.map +1 -0
- package/dist/src/pure-function-helpers/xml.js +64 -0
- package/dist/src/pure-function-helpers/xml.js.map +1 -0
- package/dist/src/version.d.ts +6 -0
- package/dist/src/version.d.ts.map +1 -0
- package/dist/src/version.js +9 -0
- package/dist/src/version.js.map +1 -0
- package/dist/src/version.spec.d.ts +3 -0
- package/dist/src/version.spec.d.ts.map +1 -0
- package/dist/src/version.spec.js +13 -0
- package/dist/src/version.spec.js.map +1 -0
- package/dist/src/web-schemas.d.ts +249 -0
- package/dist/src/web-schemas.d.ts.map +1 -0
- package/dist/src/web-schemas.js +118 -0
- package/dist/src/web-schemas.js.map +1 -0
- package/dist/src/wechaty-bro.js +868 -0
- package/dist/tests/puppeteer-contact.spec.d.ts +21 -0
- package/dist/tests/puppeteer-contact.spec.d.ts.map +1 -0
- package/dist/tests/puppeteer-contact.spec.js +67 -0
- package/dist/tests/puppeteer-contact.spec.js.map +1 -0
- package/dist/tests/puppeteer-friendship.spec.d.ts +21 -0
- package/dist/tests/puppeteer-friendship.spec.d.ts.map +1 -0
- package/dist/tests/puppeteer-friendship.spec.js +115 -0
- package/dist/tests/puppeteer-friendship.spec.js.map +1 -0
- package/dist/tests/puppeteer-message.spec.d.ts +21 -0
- package/dist/tests/puppeteer-message.spec.d.ts.map +1 -0
- package/dist/tests/puppeteer-message.spec.js +184 -0
- package/dist/tests/puppeteer-message.spec.js.map +1 -0
- package/dist/tests/puppeteer-room.spec.d.ts +21 -0
- package/dist/tests/puppeteer-room.spec.d.ts.map +1 -0
- package/dist/tests/puppeteer-room.spec.js +129 -0
- package/dist/tests/puppeteer-room.spec.js.map +1 -0
- package/dist/tests/puppeteer.spec.d.ts +21 -0
- package/dist/tests/puppeteer.spec.d.ts.map +1 -0
- package/dist/tests/puppeteer.spec.js +213 -0
- package/dist/tests/puppeteer.spec.js.map +1 -0
- package/docs/images/puppeteer-logo.png +0 -0
- package/docs/images/wechaty-puppet-wechat.png +0 -0
- package/examples/demo.ts +130 -0
- package/package.json +94 -0
- package/scripts/generate-version.sh +18 -0
- package/scripts/npm-pack-testing.sh +49 -0
- package/scripts/package-publish-config-tag.sh +13 -0
- package/scripts/retry-unit-tests.ts +57 -0
- package/src/bridge.spec.ts +224 -0
- package/src/bridge.ts +1122 -0
- package/src/config.ts +71 -0
- package/src/event.spec.ts +41 -0
- package/src/event.ts +247 -0
- package/src/firer.spec.ts +208 -0
- package/src/firer.ts +530 -0
- package/src/mod.ts +29 -0
- package/src/puppet-wechat.spec.ts +149 -0
- package/src/puppet-wechat.ts +1659 -0
- package/src/pure-function-helpers/is-type.ts +7 -0
- package/src/pure-function-helpers/message-extname.ts +57 -0
- package/src/pure-function-helpers/message-filename.ts +25 -0
- package/src/pure-function-helpers/message-raw-payload-parser.ts +85 -0
- package/src/pure-function-helpers/mod.ts +6 -0
- package/src/pure-function-helpers/normalize-scan-status.spec.ts +44 -0
- package/src/pure-function-helpers/normalize-scan-status.ts +23 -0
- package/src/pure-function-helpers/web-message-type.ts +71 -0
- package/src/pure-function-helpers/xml.ts +79 -0
- package/src/typings.d.ts +19 -0
- package/src/version.spec.ts +10 -0
- package/src/version.ts +6 -0
- package/src/web-schemas.ts +298 -0
- package/src/wechaty-bro.js +868 -0
- package/tests/fixtures/inject-file.js +7 -0
- package/tests/fixtures/smoke-testing.ts +42 -0
- package/tests/puppeteer-contact.spec.ts +78 -0
- package/tests/puppeteer-friendship.spec.ts +157 -0
- package/tests/puppeteer-message.spec.ts +249 -0
- package/tests/puppeteer-room.spec.ts +166 -0
- package/tests/puppeteer.spec.ts +262 -0
- package/tsconfig.json +26 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Wechaty - https://github.com/chatie/wechaty
|
|
4
|
+
*
|
|
5
|
+
* @copyright 2016-2018 Huan LI <zixia@zixia.net>
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
// tslint:disable:no-console
|
|
22
|
+
const mod_1 = require("../src/mod");
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* 1. Declare your Bot!
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
const puppet = new mod_1.PuppetWeChat();
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* 2. Register event handlers for Bot
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
34
|
+
puppet
|
|
35
|
+
.on('logout', onLogout)
|
|
36
|
+
.on('login', onLogin)
|
|
37
|
+
.on('scan', onScan)
|
|
38
|
+
.on('error', onError)
|
|
39
|
+
.on('message', onMessage);
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
* 3. Start the bot!
|
|
43
|
+
*
|
|
44
|
+
*/
|
|
45
|
+
puppet.start()
|
|
46
|
+
.catch(async (e) => {
|
|
47
|
+
console.error('Bot start() fail:', e);
|
|
48
|
+
await puppet.stop();
|
|
49
|
+
process.exit(-1);
|
|
50
|
+
});
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
* 4. You are all set. ;-]
|
|
54
|
+
*
|
|
55
|
+
*/
|
|
56
|
+
/**
|
|
57
|
+
*
|
|
58
|
+
* 5. Define Event Handler Functions for:
|
|
59
|
+
* `scan`, `login`, `logout`, `error`, and `message`
|
|
60
|
+
*
|
|
61
|
+
*/
|
|
62
|
+
function onScan(payload) {
|
|
63
|
+
if (payload.qrcode) {
|
|
64
|
+
// Generate a QR Code online via
|
|
65
|
+
// http://goqr.me/api/doc/create-qr-code/
|
|
66
|
+
const qrcodeImageUrl = [
|
|
67
|
+
'https://wechaty.js.org/qrcode/',
|
|
68
|
+
encodeURIComponent(payload.qrcode),
|
|
69
|
+
].join('');
|
|
70
|
+
console.info(`[${payload.status}] ${qrcodeImageUrl}\nScan QR Code above to log in: `);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
console.info(`[${payload.status}]`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function onLogin(payload) {
|
|
77
|
+
console.info(`${payload.contactId} login`);
|
|
78
|
+
puppet.messageSendText(payload.contactId, 'Wechaty login').catch(console.error);
|
|
79
|
+
}
|
|
80
|
+
function onLogout(payload) {
|
|
81
|
+
console.info(`${payload.contactId} logouted`);
|
|
82
|
+
}
|
|
83
|
+
function onError(payload) {
|
|
84
|
+
console.error('Bot error:', payload.data);
|
|
85
|
+
/*
|
|
86
|
+
if (bot.logonoff()) {
|
|
87
|
+
bot.say('Wechaty error: ' + e.message).catch(console.error)
|
|
88
|
+
}
|
|
89
|
+
*/
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
*
|
|
93
|
+
* 6. The most important handler is for:
|
|
94
|
+
* dealing with Messages.
|
|
95
|
+
*
|
|
96
|
+
*/
|
|
97
|
+
async function onMessage(payload) {
|
|
98
|
+
const messagePayload = await puppet.messagePayload(payload.messageId);
|
|
99
|
+
console.info(JSON.stringify(messagePayload));
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
*
|
|
103
|
+
* 7. Output the Welcome Message
|
|
104
|
+
*
|
|
105
|
+
*/
|
|
106
|
+
const welcome = `
|
|
107
|
+
Puppet Version: ${puppet.version()}
|
|
108
|
+
|
|
109
|
+
Please wait... I'm trying to login in...
|
|
110
|
+
|
|
111
|
+
`;
|
|
112
|
+
console.info(welcome);
|
|
113
|
+
//# sourceMappingURL=demo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"demo.js","sourceRoot":"","sources":["../../examples/demo.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;AAEH,4BAA4B;AAE5B,oCAAyC;AAUzC;;;;GAIG;AACH,MAAM,MAAM,GAAG,IAAI,kBAAY,EAAE,CAAA;AAEjC;;;;GAIG;AACH,MAAM;KACH,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC;KACtB,EAAE,CAAC,OAAO,EAAG,OAAO,CAAC;KACrB,EAAE,CAAC,MAAM,EAAI,MAAM,CAAC;KACpB,EAAE,CAAC,OAAO,EAAG,OAAO,CAAC;KACrB,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;AAE3B;;;;GAIG;AACH,MAAM,CAAC,KAAK,EAAE;KACX,KAAK,CAAC,KAAK,EAAC,CAAC,EAAC,EAAE;IACf,OAAO,CAAC,KAAK,CAAC,mBAAmB,EAAE,CAAC,CAAC,CAAA;IACrC,MAAM,MAAM,CAAC,IAAI,EAAE,CAAA;IACnB,OAAO,CAAC,IA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OAAO,GAAG;kBACE,MAAM,CAAC,OAAO,EAAE;;;;CAIjC,CAAA;AACD,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env ts-node
|
|
2
|
+
/**
|
|
3
|
+
* https://github.com/Chatie/wechaty/issues/1084
|
|
4
|
+
* WebDriver / Puppeteer sometimes will fail(i.e. timeout) with no reason.
|
|
5
|
+
* That will cause the unit tests fail randomly.
|
|
6
|
+
* So we need to retry again when unit tests fail,
|
|
7
|
+
* and treat it's really fail after MAX_RETRY_NUM times.
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=retry-unit-tests.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry-unit-tests.d.ts","sourceRoot":"","sources":["../../scripts/retry-unit-tests.ts"],"names":[],"mappings":";AACA;;;;;;GAMG"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#!/usr/bin/env ts-node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* https://github.com/Chatie/wechaty/issues/1084
|
|
5
|
+
* WebDriver / Puppeteer sometimes will fail(i.e. timeout) with no reason.
|
|
6
|
+
* That will cause the unit tests fail randomly.
|
|
7
|
+
* So we need to retry again when unit tests fail,
|
|
8
|
+
* and treat it's really fail after MAX_RETRY_NUM times.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
// tslint:disable:no-console
|
|
12
|
+
const child_process_1 = require("child_process");
|
|
13
|
+
const MAX_RETRY_NUM = 3;
|
|
14
|
+
async function main() {
|
|
15
|
+
console.info('Safe Test: starting...');
|
|
16
|
+
let round = 0;
|
|
17
|
+
let succ = false;
|
|
18
|
+
do {
|
|
19
|
+
console.info(`Safe Test: running for round #${round}`);
|
|
20
|
+
succ = await unitTest();
|
|
21
|
+
if (succ) { // success!
|
|
22
|
+
console.info(`Safe Test: successed at round #${round}!`);
|
|
23
|
+
return 0;
|
|
24
|
+
}
|
|
25
|
+
} while (round++ < MAX_RETRY_NUM);
|
|
26
|
+
return 1; // fail finally :(
|
|
27
|
+
}
|
|
28
|
+
async function unitTest() {
|
|
29
|
+
const child = (0, child_process_1.spawn)('npm', [
|
|
30
|
+
'run',
|
|
31
|
+
'test:unit',
|
|
32
|
+
], {
|
|
33
|
+
shell: true,
|
|
34
|
+
stdio: 'inherit',
|
|
35
|
+
});
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
child.once('exit', (code) => code === 0 ? resolve(true) : resolve(false));
|
|
38
|
+
child.once('error', reject);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
main()
|
|
42
|
+
.then(process.exit)
|
|
43
|
+
.catch((e) => {
|
|
44
|
+
console.error(e);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
});
|
|
47
|
+
//# sourceMappingURL=retry-unit-tests.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry-unit-tests.js","sourceRoot":"","sources":["../../scripts/retry-unit-tests.ts"],"names":[],"mappings":";;AACA;;;;;;GAMG;;AAEH,4BAA4B;AAE5B,iDAAqC;AAErC,MAAM,aAAa,GAAG,CAAC,CAAA;AAEvB,KAAK,UAAU,IAAI;IACjB,OAAO,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAA;IAEtC,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,IAAI,IAAI,GAAG,KAAK,CAAA;IAChB,GAAG;QACD,OAAO,CAAC,IAAI,CAAC,iCAAiC,KAAK,EAAE,CAAC,CAAA;QACtD,IAAI,GAAG,MAAM,QAAQ,EAAE,CAAA;QACvB,IAAI,IAAI,EAAE,EAAE,WAAW;YACrB,OAAO,CAAC,IAAI,CAAC,kCAAkC,KAAK,GAAG,CAAC,CAAA;YACxD,OAAO,CAAC,CAAA;SACT;KACF,QAAQ,KAAK,EAAE,GAAG,aAAa,EAAC;IACjC,OAAO,CAAC,CAAA,CAAE,kBAAkB;AAC9B,CAAC;AAED,KAAK,UAAU,QAAQ;IACrB,MAAM,KAAK,GAAG,IAAA,qBAAK,EACjB,KAAK,EACL;QACE,KAAK;QACL,WAAW;KACZ,EACD;QACE,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,SAAS;KACjB,CACF,CAAA;IACD,OAAO,IAAI,OAAO,CAAU,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC9C,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAC1B,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAC5C,CAAA;QACD,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IAC7B,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,IAAI,EAAE;KACH,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;KAClB,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;IACX,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAChB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wechaty - https://github.com/chatie/wechaty
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2016-2018 Huan LI <zixia@zixia.net>
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
/// <reference types="node" />
|
|
20
|
+
import { EventEmitter } from 'events';
|
|
21
|
+
import { Browser, Dialog, LaunchOptions, Page, Protocol } from 'puppeteer';
|
|
22
|
+
import { MemoryCard } from 'memory-card';
|
|
23
|
+
import { WebContactRawPayload, WebMessageMediaPayload, WebMessageRawPayload, WebRoomRawPayload } from './web-schemas';
|
|
24
|
+
export interface InjectResult {
|
|
25
|
+
code: number;
|
|
26
|
+
message: string;
|
|
27
|
+
}
|
|
28
|
+
export interface BridgeOptions {
|
|
29
|
+
endpoint?: string;
|
|
30
|
+
head?: boolean;
|
|
31
|
+
launchOptions?: LaunchOptions;
|
|
32
|
+
memory: MemoryCard;
|
|
33
|
+
stealthless?: boolean;
|
|
34
|
+
extspam?: string;
|
|
35
|
+
}
|
|
36
|
+
export declare class Bridge extends EventEmitter {
|
|
37
|
+
options: BridgeOptions;
|
|
38
|
+
private browser;
|
|
39
|
+
private page;
|
|
40
|
+
private state;
|
|
41
|
+
constructor(options: BridgeOptions);
|
|
42
|
+
start(): Promise<void>;
|
|
43
|
+
initBrowser(): Promise<Browser>;
|
|
44
|
+
onDialog(dialog: Dialog): Promise<void>;
|
|
45
|
+
onLoad(page: Page): Promise<void>;
|
|
46
|
+
initPage(browser: Browser): Promise<Page>;
|
|
47
|
+
private uosPatch;
|
|
48
|
+
readyAngular(page: Page): Promise<void>;
|
|
49
|
+
inject(page: Page): Promise<void>;
|
|
50
|
+
logout(): Promise<any>;
|
|
51
|
+
stop(): Promise<void>;
|
|
52
|
+
getUserName(): Promise<string>;
|
|
53
|
+
contactAlias(contactId: string, alias: null | string): Promise<boolean>;
|
|
54
|
+
contactList(): Promise<string[]>;
|
|
55
|
+
roomList(): Promise<string[]>;
|
|
56
|
+
roomDelMember(roomId: string, contactId: string): Promise<number>;
|
|
57
|
+
roomAddMember(roomId: string, contactId: string): Promise<number>;
|
|
58
|
+
roomModTopic(roomId: string, topic: string): Promise<string>;
|
|
59
|
+
roomCreate(contactIdList: string[], topic?: string): Promise<string>;
|
|
60
|
+
verifyUserRequest(contactId: string, hello: string): Promise<boolean>;
|
|
61
|
+
verifyUserOk(contactId: string, ticket: string): Promise<boolean>;
|
|
62
|
+
send(toUserName: string, text: string): Promise<void>;
|
|
63
|
+
getMsgImg(id: string): Promise<string>;
|
|
64
|
+
getMsgEmoticon(id: string): Promise<string>;
|
|
65
|
+
getMsgVideo(id: string): Promise<string>;
|
|
66
|
+
getMsgVoice(id: string): Promise<string>;
|
|
67
|
+
getMsgPublicLinkImg(id: string): Promise<string>;
|
|
68
|
+
getMessage(id: string): Promise<WebMessageRawPayload>;
|
|
69
|
+
getContact(id: string): Promise<WebContactRawPayload | WebRoomRawPayload>;
|
|
70
|
+
getBaseRequest(): Promise<string>;
|
|
71
|
+
getPassticket(): Promise<string>;
|
|
72
|
+
getCheckUploadUrl(): Promise<string>;
|
|
73
|
+
getUploadMediaUrl(): Promise<string>;
|
|
74
|
+
sendMedia(mediaData: WebMessageMediaPayload): Promise<boolean>;
|
|
75
|
+
forward(baseData: WebMessageRawPayload, patchData: WebMessageRawPayload): Promise<boolean>;
|
|
76
|
+
/**
|
|
77
|
+
* Proxy Call to Wechaty in Bridge
|
|
78
|
+
*/
|
|
79
|
+
proxyWechaty(wechatyFunc: string, ...args: any[]): Promise<any>;
|
|
80
|
+
ding(data: any): void;
|
|
81
|
+
preHtmlToXml(text: string): string;
|
|
82
|
+
innerHTML(): Promise<string>;
|
|
83
|
+
/**
|
|
84
|
+
* Throw if there's a blocked message
|
|
85
|
+
*/
|
|
86
|
+
testBlockedMessage(text?: string): Promise<string | false>;
|
|
87
|
+
clickSwitchAccount(page: Page): Promise<boolean>;
|
|
88
|
+
hostname(): Promise<string | null>;
|
|
89
|
+
cookies(cookieList: Cookie[]): Promise<void>;
|
|
90
|
+
cookies(): Promise<Cookie[]>;
|
|
91
|
+
/**
|
|
92
|
+
* name
|
|
93
|
+
*/
|
|
94
|
+
entryUrl(cookieList?: Protocol.Network.Cookie[]): string;
|
|
95
|
+
reload(): Promise<void>;
|
|
96
|
+
evaluate(fn: () => any, ...args: any[]): Promise<any>;
|
|
97
|
+
}
|
|
98
|
+
export type Cookie = Protocol.Network.Cookie;
|
|
99
|
+
export default Bridge;
|
|
100
|
+
//# sourceMappingURL=bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../src/bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAGrC,OAAO,EACL,OAAO,EAEP,MAAM,EAEN,aAAa,EACb,IAAI,EACJ,QAAQ,EACT,MAA4B,WAAW,CAAA;AAMxC,OAAO,EACL,UAAU,EACX,MAA4B,aAAa,CAAA;AAW1C,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,oBAAoB,EACpB,iBAAiB,EAClB,MAA6B,eAAe,CAAA;AAM7C,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAK,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAS,MAAM,CAAC;IACzB,IAAI,CAAC,EAAa,OAAO,CAAC;IAC1B,aAAa,CAAC,EAAI,aAAa,CAAC;IAChC,MAAM,EAAY,UAAU,CAAC;IAC7B,WAAW,CAAC,EAAM,OAAO,CAAC;IAC1B,OAAO,CAAC,EAAU,MAAM,CAAA;CACzB;AAED,qBAAa,MAAO,SAAQ,YAAY;IAO7B,OAAO,EAAE,aAAa;IAL/B,OAAO,CAAC,OAAO,CAAsB;IACrC,OAAO,CAAC,IAAI,CAAsB;IAClC,OAAO,CAAC,KAAK,CAAgB;gBA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