@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.
Files changed (167) hide show
  1. package/.editorconfig +14 -0
  2. package/.eslintrc.js +7 -0
  3. package/.github/workflows/npm.yml +91 -0
  4. package/.markdownlintrc +13 -0
  5. package/.travis.yml +62 -0
  6. package/.vscode/settings.json +73 -0
  7. package/CODEOWNERS +9 -0
  8. package/LICENSE +201 -0
  9. package/NOTICE +8 -0
  10. package/README.md +145 -0
  11. package/dist/examples/demo.d.ts +20 -0
  12. package/dist/examples/demo.d.ts.map +1 -0
  13. package/dist/examples/demo.js +113 -0
  14. package/dist/examples/demo.js.map +1 -0
  15. package/dist/scripts/retry-unit-tests.d.ts +10 -0
  16. package/dist/scripts/retry-unit-tests.d.ts.map +1 -0
  17. package/dist/scripts/retry-unit-tests.js +47 -0
  18. package/dist/scripts/retry-unit-tests.js.map +1 -0
  19. package/dist/src/bridge.d.ts +100 -0
  20. package/dist/src/bridge.d.ts.map +1 -0
  21. package/dist/src/bridge.js +927 -0
  22. package/dist/src/bridge.js.map +1 -0
  23. package/dist/src/bridge.spec.d.ts +21 -0
  24. package/dist/src/bridge.spec.d.ts.map +1 -0
  25. package/dist/src/bridge.spec.js +191 -0
  26. package/dist/src/bridge.spec.js.map +1 -0
  27. package/dist/src/config.d.ts +10 -0
  28. package/dist/src/config.d.ts.map +1 -0
  29. package/dist/src/config.js +57 -0
  30. package/dist/src/config.js.map +1 -0
  31. package/dist/src/event.d.ts +23 -0
  32. package/dist/src/event.d.ts.map +1 -0
  33. package/dist/src/event.js +166 -0
  34. package/dist/src/event.js.map +1 -0
  35. package/dist/src/event.spec.d.ts +3 -0
  36. package/dist/src/event.spec.d.ts.map +1 -0
  37. package/dist/src/event.spec.js +41 -0
  38. package/dist/src/event.spec.js.map +1 -0
  39. package/dist/src/firer.d.ts +50 -0
  40. package/dist/src/firer.d.ts.map +1 -0
  41. package/dist/src/firer.js +409 -0
  42. package/dist/src/firer.js.map +1 -0
  43. package/dist/src/firer.spec.d.ts +21 -0
  44. package/dist/src/firer.spec.d.ts.map +1 -0
  45. package/dist/src/firer.spec.js +190 -0
  46. package/dist/src/firer.spec.js.map +1 -0
  47. package/dist/src/mod.d.ts +23 -0
  48. package/dist/src/mod.d.ts.map +1 -0
  49. package/dist/src/mod.js +28 -0
  50. package/dist/src/mod.js.map +1 -0
  51. package/dist/src/puppet-wechat.d.ts +164 -0
  52. package/dist/src/puppet-wechat.d.ts.map +1 -0
  53. package/dist/src/puppet-wechat.js +1287 -0
  54. package/dist/src/puppet-wechat.js.map +1 -0
  55. package/dist/src/puppet-wechat.spec.d.ts +21 -0
  56. package/dist/src/puppet-wechat.spec.d.ts.map +1 -0
  57. package/dist/src/puppet-wechat.spec.js +123 -0
  58. package/dist/src/puppet-wechat.spec.js.map +1 -0
  59. package/dist/src/pure-function-helpers/is-type.d.ts +3 -0
  60. package/dist/src/pure-function-helpers/is-type.d.ts.map +1 -0
  61. package/dist/src/pure-function-helpers/is-type.js +12 -0
  62. package/dist/src/pure-function-helpers/is-type.js.map +1 -0
  63. package/dist/src/pure-function-helpers/message-extname.d.ts +3 -0
  64. package/dist/src/pure-function-helpers/message-extname.d.ts.map +1 -0
  65. package/dist/src/pure-function-helpers/message-extname.js +44 -0
  66. package/dist/src/pure-function-helpers/message-extname.js.map +1 -0
  67. package/dist/src/pure-function-helpers/message-filename.d.ts +3 -0
  68. package/dist/src/pure-function-helpers/message-filename.d.ts.map +1 -0
  69. package/dist/src/pure-function-helpers/message-filename.js +19 -0
  70. package/dist/src/pure-function-helpers/message-filename.js.map +1 -0
  71. package/dist/src/pure-function-helpers/message-raw-payload-parser.d.ts +4 -0
  72. package/dist/src/pure-function-helpers/message-raw-payload-parser.d.ts.map +1 -0
  73. package/dist/src/pure-function-helpers/message-raw-payload-parser.js +67 -0
  74. package/dist/src/pure-function-helpers/message-raw-payload-parser.js.map +1 -0
  75. package/dist/src/pure-function-helpers/mod.d.ts +7 -0
  76. package/dist/src/pure-function-helpers/mod.d.ts.map +1 -0
  77. package/dist/src/pure-function-helpers/mod.js +23 -0
  78. package/dist/src/pure-function-helpers/mod.js.map +1 -0
  79. package/dist/src/pure-function-helpers/normalize-scan-status.d.ts +3 -0
  80. package/dist/src/pure-function-helpers/normalize-scan-status.d.ts.map +1 -0
  81. package/dist/src/pure-function-helpers/normalize-scan-status.js +21 -0
  82. package/dist/src/pure-function-helpers/normalize-scan-status.js.map +1 -0
  83. package/dist/src/pure-function-helpers/normalize-scan-status.spec.d.ts +21 -0
  84. package/dist/src/pure-function-helpers/normalize-scan-status.spec.d.ts.map +1 -0
  85. package/dist/src/pure-function-helpers/normalize-scan-status.spec.js +37 -0
  86. package/dist/src/pure-function-helpers/normalize-scan-status.spec.js.map +1 -0
  87. package/dist/src/pure-function-helpers/web-message-type.d.ts +4 -0
  88. package/dist/src/pure-function-helpers/web-message-type.d.ts.map +1 -0
  89. package/dist/src/pure-function-helpers/web-message-type.js +58 -0
  90. package/dist/src/pure-function-helpers/web-message-type.js.map +1 -0
  91. package/dist/src/pure-function-helpers/xml.d.ts +14 -0
  92. package/dist/src/pure-function-helpers/xml.d.ts.map +1 -0
  93. package/dist/src/pure-function-helpers/xml.js +64 -0
  94. package/dist/src/pure-function-helpers/xml.js.map +1 -0
  95. package/dist/src/version.d.ts +6 -0
  96. package/dist/src/version.d.ts.map +1 -0
  97. package/dist/src/version.js +9 -0
  98. package/dist/src/version.js.map +1 -0
  99. package/dist/src/version.spec.d.ts +3 -0
  100. package/dist/src/version.spec.d.ts.map +1 -0
  101. package/dist/src/version.spec.js +13 -0
  102. package/dist/src/version.spec.js.map +1 -0
  103. package/dist/src/web-schemas.d.ts +249 -0
  104. package/dist/src/web-schemas.d.ts.map +1 -0
  105. package/dist/src/web-schemas.js +118 -0
  106. package/dist/src/web-schemas.js.map +1 -0
  107. package/dist/src/wechaty-bro.js +868 -0
  108. package/dist/tests/puppeteer-contact.spec.d.ts +21 -0
  109. package/dist/tests/puppeteer-contact.spec.d.ts.map +1 -0
  110. package/dist/tests/puppeteer-contact.spec.js +67 -0
  111. package/dist/tests/puppeteer-contact.spec.js.map +1 -0
  112. package/dist/tests/puppeteer-friendship.spec.d.ts +21 -0
  113. package/dist/tests/puppeteer-friendship.spec.d.ts.map +1 -0
  114. package/dist/tests/puppeteer-friendship.spec.js +115 -0
  115. package/dist/tests/puppeteer-friendship.spec.js.map +1 -0
  116. package/dist/tests/puppeteer-message.spec.d.ts +21 -0
  117. package/dist/tests/puppeteer-message.spec.d.ts.map +1 -0
  118. package/dist/tests/puppeteer-message.spec.js +184 -0
  119. package/dist/tests/puppeteer-message.spec.js.map +1 -0
  120. package/dist/tests/puppeteer-room.spec.d.ts +21 -0
  121. package/dist/tests/puppeteer-room.spec.d.ts.map +1 -0
  122. package/dist/tests/puppeteer-room.spec.js +129 -0
  123. package/dist/tests/puppeteer-room.spec.js.map +1 -0
  124. package/dist/tests/puppeteer.spec.d.ts +21 -0
  125. package/dist/tests/puppeteer.spec.d.ts.map +1 -0
  126. package/dist/tests/puppeteer.spec.js +213 -0
  127. package/dist/tests/puppeteer.spec.js.map +1 -0
  128. package/docs/images/puppeteer-logo.png +0 -0
  129. package/docs/images/wechaty-puppet-wechat.png +0 -0
  130. package/examples/demo.ts +130 -0
  131. package/package.json +94 -0
  132. package/scripts/generate-version.sh +18 -0
  133. package/scripts/npm-pack-testing.sh +49 -0
  134. package/scripts/package-publish-config-tag.sh +13 -0
  135. package/scripts/retry-unit-tests.ts +57 -0
  136. package/src/bridge.spec.ts +224 -0
  137. package/src/bridge.ts +1122 -0
  138. package/src/config.ts +71 -0
  139. package/src/event.spec.ts +41 -0
  140. package/src/event.ts +247 -0
  141. package/src/firer.spec.ts +208 -0
  142. package/src/firer.ts +530 -0
  143. package/src/mod.ts +29 -0
  144. package/src/puppet-wechat.spec.ts +149 -0
  145. package/src/puppet-wechat.ts +1659 -0
  146. package/src/pure-function-helpers/is-type.ts +7 -0
  147. package/src/pure-function-helpers/message-extname.ts +57 -0
  148. package/src/pure-function-helpers/message-filename.ts +25 -0
  149. package/src/pure-function-helpers/message-raw-payload-parser.ts +85 -0
  150. package/src/pure-function-helpers/mod.ts +6 -0
  151. package/src/pure-function-helpers/normalize-scan-status.spec.ts +44 -0
  152. package/src/pure-function-helpers/normalize-scan-status.ts +23 -0
  153. package/src/pure-function-helpers/web-message-type.ts +71 -0
  154. package/src/pure-function-helpers/xml.ts +79 -0
  155. package/src/typings.d.ts +19 -0
  156. package/src/version.spec.ts +10 -0
  157. package/src/version.ts +6 -0
  158. package/src/web-schemas.ts +298 -0
  159. package/src/wechaty-bro.js +868 -0
  160. package/tests/fixtures/inject-file.js +7 -0
  161. package/tests/fixtures/smoke-testing.ts +42 -0
  162. package/tests/puppeteer-contact.spec.ts +78 -0
  163. package/tests/puppeteer-friendship.spec.ts +157 -0
  164. package/tests/puppeteer-message.spec.ts +249 -0
  165. package/tests/puppeteer-room.spec.ts +166 -0
  166. package/tests/puppeteer.spec.ts +262 -0
  167. package/tsconfig.json +26 -0
@@ -0,0 +1,7 @@
1
+ export function isRoomId (id: string): boolean {
2
+ return /^@@/.test(id)
3
+ }
4
+
5
+ export function isContactId (id: string): boolean {
6
+ return !isRoomId(id)
7
+ }
@@ -0,0 +1,57 @@
1
+ import {
2
+ WebAppMsgType,
3
+ WebMessageRawPayload,
4
+ WebMessageType,
5
+ } from '../web-schemas'
6
+
7
+ export function messageExtname (
8
+ rawPayload: WebMessageRawPayload,
9
+ ): string {
10
+ let ext: string
11
+
12
+ // const type = this.type()
13
+
14
+ switch (rawPayload.MsgType) {
15
+ case WebMessageType.EMOTICON:
16
+ ext = '.gif'
17
+ break
18
+
19
+ case WebMessageType.IMAGE:
20
+ ext = '.jpg'
21
+ break
22
+
23
+ case WebMessageType.VIDEO:
24
+ case WebMessageType.MICROVIDEO:
25
+ ext = '.mp4'
26
+ break
27
+
28
+ case WebMessageType.VOICE:
29
+ ext = '.mp3'
30
+ break
31
+
32
+ case WebMessageType.APP:
33
+ switch (rawPayload.AppMsgType) {
34
+ case WebAppMsgType.URL:
35
+ ext = '.url' // XXX
36
+ break
37
+ default:
38
+ ext = '.' + rawPayload.MsgType
39
+ break
40
+ }
41
+ break
42
+
43
+ case WebMessageType.TEXT:
44
+ if (rawPayload.SubMsgType === WebMessageType.LOCATION) {
45
+ ext = '.jpg'
46
+ }
47
+ ext = '.' + rawPayload.MsgType
48
+
49
+ break
50
+
51
+ default:
52
+ ext = '.' + rawPayload.MsgType
53
+ }
54
+
55
+ return ext
56
+
57
+ }
@@ -0,0 +1,25 @@
1
+ import {
2
+ WebMessageRawPayload,
3
+ } from '../web-schemas'
4
+
5
+ import {
6
+ messageExtname,
7
+ } from './message-extname'
8
+
9
+ export function messageFilename (
10
+ rawPayload: WebMessageRawPayload,
11
+ ): string {
12
+
13
+ let guessFilename = rawPayload.FileName || rawPayload.MediaId || rawPayload.MsgId
14
+
15
+ const re = /\.[a-z0-9]{1,7}$/i
16
+ if (!re.test(guessFilename)) {
17
+ if (rawPayload.MMAppMsgFileExt) {
18
+ guessFilename += '.' + rawPayload.MMAppMsgFileExt
19
+ } else {
20
+ guessFilename += messageExtname(rawPayload)
21
+ }
22
+ }
23
+
24
+ return guessFilename
25
+ }
@@ -0,0 +1,85 @@
1
+ import {
2
+ WebMessageRawPayload,
3
+ } from '../web-schemas'
4
+
5
+ import {
6
+ MessagePayload,
7
+ MessageType,
8
+ } from 'wechaty-puppet'
9
+ import {
10
+ isRoomId,
11
+ } from './is-type'
12
+
13
+ import {
14
+ messageFilename,
15
+ } from './message-filename'
16
+ import {
17
+ webMessageType,
18
+ } from './web-message-type'
19
+
20
+ export function messageRawPayloadParser (
21
+ rawPayload: WebMessageRawPayload,
22
+ ): MessagePayload {
23
+ const id = rawPayload.MsgId
24
+ const fromId = rawPayload.MMActualSender // MMPeerUserName
25
+ const text: string = rawPayload.MMActualContent // Content has @id prefix added by wx
26
+ const timestamp: number = rawPayload.MMDisplayTime // Javascript timestamp of milliseconds
27
+ const msgFileName: undefined | string = messageFilename(rawPayload) || undefined
28
+
29
+ let roomId : undefined | string
30
+ let toId : undefined | string
31
+
32
+ // FIXME: has there any better method to know the room ID?
33
+ if (rawPayload.MMIsChatRoom) {
34
+ if (isRoomId(rawPayload.FromUserName)) {
35
+ roomId = rawPayload.FromUserName // MMPeerUserName always eq FromUserName ?
36
+ } else if (isRoomId(rawPayload.ToUserName)) {
37
+ roomId = rawPayload.ToUserName
38
+ } else {
39
+ throw new Error('parse found a room message, but neither FromUserName nor ToUserName is a room(/^@@/)')
40
+ }
41
+
42
+ // console.log('rawPayload.FromUserName: ', rawPayload.FromUserName)
43
+ // console.log('rawPayload.ToUserName: ', rawPayload.ToUserName)
44
+ // console.log('rawPayload.MMPeerUserName: ', rawPayload.MMPeerUserName)
45
+ }
46
+
47
+ if (rawPayload.ToUserName) {
48
+ if (!isRoomId(rawPayload.ToUserName)) {
49
+ // if a message in room without any specific receiver, then it will set to be `undefined`
50
+ toId = rawPayload.ToUserName
51
+ }
52
+ }
53
+
54
+ const type: MessageType = webMessageType(rawPayload)
55
+
56
+ const payloadBase = {
57
+ filename: msgFileName,
58
+ fromId,
59
+ id,
60
+ mentionIdList: [],
61
+ text,
62
+ timestamp,
63
+ type,
64
+ }
65
+
66
+ let payload: MessagePayload
67
+
68
+ if (toId) {
69
+ payload = {
70
+ ...payloadBase,
71
+ roomId,
72
+ toId,
73
+ }
74
+ } else if (roomId) {
75
+ payload = {
76
+ ...payloadBase,
77
+ roomId,
78
+ toId,
79
+ }
80
+ } else {
81
+ throw new Error('neither roomId nor toId')
82
+ }
83
+
84
+ return payload
85
+ }
@@ -0,0 +1,6 @@
1
+ export * from './is-type'
2
+ export * from './message-extname'
3
+ export * from './message-filename'
4
+ export * from './message-raw-payload-parser'
5
+ export * from './web-message-type'
6
+ export * from './xml'
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ts-node
2
+
3
+ /**
4
+ * Wechaty - https://github.com/chatie/wechaty
5
+ *
6
+ * @copyright 2016-2018 Huan LI <zixia@zixia.net>
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ *
20
+ */
21
+
22
+ import {
23
+ test,
24
+ } from 'tstest'
25
+
26
+ import {
27
+ ScanStatus,
28
+ } from 'wechaty-puppet'
29
+
30
+ import { normalizeScanStatus } from './normalize-scan-status'
31
+
32
+ test('normalizeScanStatus()', async t => {
33
+ const SCAN_STATUS_LIST = [
34
+ [0, ScanStatus.Waiting],
35
+ [200, ScanStatus.Confirmed],
36
+ [201, ScanStatus.Scanned],
37
+ [408, ScanStatus.Timeout],
38
+ ]
39
+
40
+ for (const [puppeteerStatus, EXPECT_PUPPET_STATUS] of SCAN_STATUS_LIST) {
41
+ const puppetStatus = normalizeScanStatus(puppeteerStatus)
42
+ t.is(puppetStatus, EXPECT_PUPPET_STATUS, `should convert status code from puppeer(${puppeteerStatus}) to puppet(${EXPECT_PUPPET_STATUS})`)
43
+ }
44
+ })
@@ -0,0 +1,23 @@
1
+ import { ScanStatus } from 'wechaty-puppet'
2
+
3
+ export function normalizeScanStatus (
4
+ status: number,
5
+ ): ScanStatus {
6
+ switch (status) {
7
+ case 0:
8
+ return ScanStatus.Waiting
9
+
10
+ case 200:
11
+ return ScanStatus.Confirmed
12
+
13
+ case 201:
14
+ return ScanStatus.Scanned
15
+
16
+ case 408:
17
+ // No scan after 2 minute ...
18
+ return ScanStatus.Timeout
19
+
20
+ default:
21
+ throw new Error('unsupported scan status: ' + status)
22
+ }
23
+ }
@@ -0,0 +1,71 @@
1
+ import {
2
+ WebAppMsgType,
3
+ WebMessageRawPayload,
4
+ WebMessageType,
5
+ } from '../web-schemas'
6
+
7
+ import {
8
+ MessageType,
9
+ } from 'wechaty-puppet'
10
+
11
+ export function webMessageType (
12
+ rawPayload: WebMessageRawPayload,
13
+ ): MessageType {
14
+
15
+ switch (rawPayload.MsgType) {
16
+ case WebMessageType.TEXT:
17
+ switch (rawPayload.SubMsgType) {
18
+ case WebMessageType.LOCATION:
19
+ return MessageType.Attachment
20
+
21
+ default:
22
+ return MessageType.Text
23
+ }
24
+
25
+ case WebMessageType.EMOTICON:
26
+ case WebMessageType.IMAGE:
27
+ return MessageType.Image
28
+
29
+ case WebMessageType.VOICE:
30
+ return MessageType.Audio
31
+
32
+ case WebMessageType.MICROVIDEO:
33
+ case WebMessageType.VIDEO:
34
+ return MessageType.Video
35
+
36
+ case WebMessageType.APP:
37
+ switch (rawPayload.AppMsgType) {
38
+ case WebAppMsgType.ATTACH:
39
+ case WebAppMsgType.URL:
40
+ case WebAppMsgType.READER_TYPE:
41
+ return MessageType.Attachment
42
+
43
+ default:
44
+ return MessageType.Text
45
+ }
46
+
47
+ /**
48
+ * Treat those Types as TEXT
49
+ *
50
+ * Friendship is a SYS message
51
+ * FIXME: should we use better message type at here???
52
+ */
53
+ case WebMessageType.SYS:
54
+ return MessageType.Text
55
+ // add recall type
56
+ case WebMessageType.RECALLED:
57
+ return MessageType.Recalled
58
+ // VERIFYMSG = 37,
59
+ // POSSIBLEFRIEND_MSG = 40,
60
+ // SHARECARD = 42,
61
+ // LOCATION = 48,
62
+ // VOIPMSG = 50,
63
+ // STATUSNOTIFY = 51,
64
+ // VOIPNOTIFY = 52,
65
+ // VOIPINVITE = 53,
66
+ // SYSNOTICE = 9999,
67
+ // RECALLED = 10002,
68
+ default:
69
+ return MessageType.Text
70
+ }
71
+ }
@@ -0,0 +1,79 @@
1
+ export function stripHtml (html?: string): string {
2
+ if (!html) {
3
+ return ''
4
+ }
5
+ return html.replace(/(<([^>]+)>)/ig, '')
6
+ }
7
+
8
+ export function unescapeHtml (str?: string): string {
9
+ if (!str) {
10
+ return ''
11
+ }
12
+ return str
13
+ .replace(/&apos;/g, "'")
14
+ .replace(/&quot;/g, '"')
15
+ .replace(/&gt;/g, '>')
16
+ .replace(/&lt;/g, '<')
17
+ .replace(/&amp;/g, '&')
18
+ }
19
+
20
+ export function digestEmoji (html?: string): string {
21
+ if (!html) {
22
+ return ''
23
+ }
24
+ return html
25
+ .replace(/<img class="(\w*?emoji) (\w*?emoji[^"]+?)" text="(.*?)_web" src=[^>]+>/g,
26
+ '$3',
27
+ ) // <img class="emoji emoji1f4a4" text="[流汗]_web" src="/zh_CN/htmledition/v2/images/spacer.gif" />
28
+ .replace(/<span class="(\w*?emoji) (\w*?emoji[^"]+?)"><\/span>/g,
29
+ '[$2]',
30
+ ) // '<span class="emoji emoji1f334"></span>'
31
+ }
32
+
33
+ /**
34
+ * unifyEmoji: the same emoji will be encoded as different xml code in browser. unify them.
35
+ *
36
+ * from: <img class="emoji emoji1f602" text="_web" src="/zh_CN/htmledition/v2/images/spacer.gif" />
37
+ * to: <span class=\"emoji emoji1f602\"></span>
38
+ *
39
+ */
40
+ export function unifyEmoji (html?: string): string {
41
+ if (!html) {
42
+ return ''
43
+ }
44
+ return html
45
+ .replace(/<img class="(\w*?emoji) (\w*?emoji[^"]+?)" text="(.*?)_web" src=[^>]+>/g,
46
+ '<emoji code="$2"/>',
47
+ ) // <img class="emoji emoji1f4a4" text="[流汗]_web" src="/zh_CN/htmledition/v2/images/spacer.gif" />
48
+ .replace(/<span class="(\w*?emoji) (\w*?emoji[^"]+?)"><\/span>/g,
49
+ '<emoji code="$2"/>',
50
+ ) // '<span class="emoji emoji1f334"></span>'
51
+ }
52
+
53
+ export function stripEmoji (html?: string): string {
54
+ if (!html) {
55
+ return ''
56
+ }
57
+ return html
58
+ .replace(/<img class="(\w*?emoji) (\w*?emoji[^"]+?)" text="(.*?)_web" src=[^>]+>/g,
59
+ '',
60
+ ) // <img class="emoji emoji1f4a4" text="[流汗]_web" src="/zh_CN/htmledition/v2/images/spacer.gif" />
61
+ .replace(/<span class="(\w*?emoji) (\w*?emoji[^"]+?)"><\/span>/g,
62
+ '',
63
+ ) // '<span class="emoji emoji1f334"></span>'
64
+ }
65
+
66
+ export function plainText (html?: string): string {
67
+ if (!html) {
68
+ return ''
69
+ }
70
+ return stripHtml(
71
+ unescapeHtml(
72
+ stripHtml(
73
+ digestEmoji(
74
+ html,
75
+ ),
76
+ ),
77
+ ),
78
+ )
79
+ }
@@ -0,0 +1,19 @@
1
+ // declare const window: any
2
+
3
+ // Extend the `Window` from Browser
4
+ interface Window {
5
+ wechatyPuppetBridgeEmit?: Function, // from puppeteer
6
+ }
7
+
8
+ declare const WechatyBro: any
9
+
10
+ declare module 'puppeteer-extra-plugin-stealth' {
11
+ function plugin(config?:any): any;
12
+ export = plugin;
13
+ }
14
+
15
+ declare module 'puppeteer-extra' {
16
+ import { Browser, LaunchOptions } from 'puppeteer'
17
+ export function use(plugin:any): any;
18
+ export function launch(opts?:LaunchOptions): Promise<Browser>;
19
+ }
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ts-node
2
+
3
+ // tslint:disable:no-shadowed-variable
4
+ import test from 'blue-tape'
5
+
6
+ import { VERSION } from './version'
7
+
8
+ test('Make sure the VERSION is fresh in source code', async (t) => {
9
+ t.equal(VERSION, '0.0.0', 'version should be 0.0.0 in source code, only updated before publish to NPM')
10
+ })
package/src/version.ts ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * This file will be overwrite when we publish NPM module
3
+ * by scripts/generate_version.ts
4
+ */
5
+
6
+ export const VERSION = '0.0.0'