@juzi/wechaty-puppet-service 1.0.12 → 1.0.16

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.
@@ -921,12 +921,14 @@ class PuppetService extends PUPPET.Puppet {
921
921
  */
922
922
  request.setMiniProgramDeprecated(JSON.stringify(miniProgramPayload))
923
923
 
924
+ log.info('PuppetService', `messageSendMiniProgram(${conversationId}, ${miniProgramPayload.description}) about to call grpc`)
924
925
  const response = await util.promisify(
925
926
  this.grpcManager.client.messageSendMiniProgram
926
927
  .bind(this.grpcManager.client),
927
928
  )(request)
928
929
 
929
930
  const messageId = response.getId()
931
+ log.info('PuppetService', `messageSendMiniProgram(${conversationId}, ${miniProgramPayload.description}) grpc called, messageId: ${messageId}`)
930
932
 
931
933
  if (messageId) {
932
934
  return messageId
@@ -961,12 +963,14 @@ class PuppetService extends PUPPET.Puppet {
961
963
  pbLocationPayload.setName(locationPayload.name)
962
964
  request.setLocation(pbLocationPayload)
963
965
 
966
+ log.info('PuppetService', `messageSendLocation(${conversationId}, ${locationPayload.name}) about to call grpc`)
964
967
  const response = await util.promisify(
965
968
  this.grpcManager.client.messageSendLocation
966
969
  .bind(this.grpcManager.client),
967
970
  )(request)
968
971
 
969
972
  const id = response.getId()
973
+ log.info('PuppetService', `messageSendMiniProgram(${conversationId}, ${locationPayload.name}) grpc called, messageId: ${id}`)
970
974
 
971
975
  if (id) {
972
976
  return id
@@ -993,12 +997,14 @@ class PuppetService extends PUPPET.Puppet {
993
997
  if (channelPayload.url) { pbChannelPayload.setUrl(channelPayload.url) }
994
998
  request.setChannel(pbChannelPayload)
995
999
 
1000
+ log.info('PuppetService', `messageSendChannel(${conversationId}, ${channelPayload.desc}) about to call grpc`)
996
1001
  const response = await util.promisify(
997
1002
  this.grpcManager.client.messageSendChannel
998
1003
  .bind(this.grpcManager.client),
999
1004
  )(request)
1000
1005
 
1001
1006
  const messageId = response.getId()
1007
+ log.info('PuppetService', `messageSendChannel(${conversationId}, ${channelPayload.desc}) grpc called, messageId: ${messageId}`)
1002
1008
 
1003
1009
  if (messageId) {
1004
1010
  return messageId
@@ -1087,12 +1093,14 @@ class PuppetService extends PUPPET.Puppet {
1087
1093
  request.setConversationId(conversationId)
1088
1094
  request.setMessageId(messageId)
1089
1095
 
1096
+ log.info('PuppetService', `messageForward(${conversationId}, ${messageId}) about to call grpc`)
1090
1097
  const response = await util.promisify(
1091
1098
  this.grpcManager.client.messageForward
1092
1099
  .bind(this.grpcManager.client),
1093
1100
  )(request)
1094
1101
 
1095
1102
  const forwardedMessageId = response.getId()
1103
+ log.info('PuppetService', `messageForward(${conversationId}, ${messageId}) grpc called, messageId: ${forwardedMessageId}`)
1096
1104
 
1097
1105
  if (forwardedMessageId) {
1098
1106
  return forwardedMessageId
@@ -1185,12 +1193,14 @@ class PuppetService extends PUPPET.Puppet {
1185
1193
  request.setQuoteId(quoteId)
1186
1194
  }
1187
1195
 
1196
+ log.info('PuppetService', `messageSend(${conversationId}, ${text}) about to call grpc`)
1188
1197
  const response = await util.promisify(
1189
1198
  this.grpcManager.client.messageSendText
1190
1199
  .bind(this.grpcManager.client),
1191
1200
  )(request)
1192
1201
 
1193
1202
  const messageId = response.getId()
1203
+ log.info('PuppetService', `messageSend(${conversationId}, ${text}) grpc called, messageId: ${messageId}`)
1194
1204
 
1195
1205
  if (messageId) {
1196
1206
  return messageId
@@ -1221,12 +1231,14 @@ class PuppetService extends PUPPET.Puppet {
1221
1231
  const serializedFileBox = await this.serializeFileBox(fileBox)
1222
1232
  request.setFileBox(serializedFileBox)
1223
1233
 
1234
+ log.info('PuppetService', `messageSendFile(${conversationId}, ${fileBox}) about to call grpc`)
1224
1235
  const response = await util.promisify(
1225
1236
  this.grpcManager.client.messageSendFile
1226
1237
  .bind(this.grpcManager.client),
1227
1238
  )(request)
1228
1239
 
1229
1240
  const messageId = response.getId()
1241
+ log.info('PuppetService', `messageSendFile(${conversationId}, ${fileBox}) grpc called, messageId: ${messageId}`)
1230
1242
 
1231
1243
  if (messageId) {
1232
1244
  return messageId
@@ -1265,12 +1277,14 @@ class PuppetService extends PUPPET.Puppet {
1265
1277
  request.setConversationId(conversationId)
1266
1278
  request.setContactId(contactId)
1267
1279
 
1280
+ log.info('PuppetService', `messageSendContact(${conversationId}, ${contactId}) about to call grpc`)
1268
1281
  const response = await util.promisify(
1269
1282
  this.grpcManager.client.messageSendContact
1270
1283
  .bind(this.grpcManager.client),
1271
1284
  )(request)
1272
1285
 
1273
1286
  const messageId = response.getId()
1287
+ log.info('PuppetService', `messageSendContact(${conversationId}, ${contactId}) grpc called, messageId: ${messageId}`)
1274
1288
 
1275
1289
  if (messageId) {
1276
1290
  return messageId
@@ -1307,12 +1321,14 @@ class PuppetService extends PUPPET.Puppet {
1307
1321
  // Deprecated: will be removed after Dec 31, 2022
1308
1322
  request.setUrlLinkDeprecated(JSON.stringify(urlLinkPayload))
1309
1323
 
1324
+ log.info('PuppetService', `messageSendUrl(${conversationId}, ${urlLinkPayload}) about to call grpc`)
1310
1325
  const response = await util.promisify(
1311
1326
  this.grpcManager.client.messageSendUrl
1312
1327
  .bind(this.grpcManager.client),
1313
1328
  )(request)
1314
1329
 
1315
1330
  const messageId = response.getId()
1331
+ log.info('PuppetService', `messageSendUrl(${conversationId}, ${urlLinkPayload}) grpc called, messageId: ${messageId}`)
1316
1332
 
1317
1333
  if (messageId) {
1318
1334
  return messageId
@@ -1904,82 +1920,263 @@ class PuppetService extends PUPPET.Puppet {
1904
1920
  * Tag
1905
1921
  *
1906
1922
  */
1907
- // add a tag for a Contact. Create it first if it not exist.
1908
- override async tagContactAdd (
1909
- id: string,
1923
+
1924
+ override async tagContactTagAdd (
1925
+ tagGroupId: string | undefined,
1926
+ tagId: string,
1910
1927
  contactId: string,
1911
1928
  ): Promise<void> {
1912
- log.verbose('PuppetService', 'tagContactAdd(%s, %s)', id, contactId)
1929
+ log.verbose('PuppetService', 'tagContactTagAdd(%s, %s, %s)', tagGroupId, tagId, contactId)
1913
1930
 
1914
- const request = new grpcPuppet.TagContactAddRequest()
1915
- request.setId(id)
1931
+ const request = new grpcPuppet.TagContactTagAddRequest()
1932
+
1933
+ if (typeof tagGroupId !== 'undefined') {
1934
+ request.setTagGroupId(tagGroupId)
1935
+ }
1936
+ request.setTagId(tagId)
1916
1937
  request.setContactId(contactId)
1917
1938
 
1918
1939
  await util.promisify(
1919
- this.grpcManager.client.tagContactAdd
1940
+ this.grpcManager.client.tagContactTagAdd
1920
1941
  .bind(this.grpcManager.client),
1921
1942
  )(request)
1922
1943
  }
1923
1944
 
1924
- // remove a tag from the Contact
1925
- override async tagContactRemove (
1926
- id: string,
1945
+ override async tagContactTagRemove (
1946
+ tagGroupId: string | undefined,
1947
+ tagId: string,
1927
1948
  contactId: string,
1928
- ) : Promise<void> {
1929
- log.verbose('PuppetService', 'tagContactRemove(%s, %s)', id, contactId)
1949
+ ): Promise<void> {
1950
+ log.verbose('PuppetService', 'tagContactTagRemove(%s, %s, %s)', tagGroupId, tagId, contactId)
1930
1951
 
1931
- const request = new grpcPuppet.TagContactRemoveRequest()
1932
- request.setId(id)
1952
+ const request = new grpcPuppet.TagContactTagRemoveRequest()
1953
+
1954
+ if (typeof tagGroupId !== 'undefined') {
1955
+ request.setTagGroupId(tagGroupId)
1956
+ }
1957
+ request.setTagId(tagId)
1933
1958
  request.setContactId(contactId)
1934
1959
 
1935
1960
  await util.promisify(
1936
- this.grpcManager.client.tagContactRemove
1961
+ this.grpcManager.client.tagContactTagRemove
1937
1962
  .bind(this.grpcManager.client),
1938
1963
  )(request)
1939
1964
  }
1940
1965
 
1941
- // delete a tag from Wechat
1942
- override async tagContactDelete (
1943
- id: string,
1944
- ) : Promise<void> {
1945
- log.verbose('PuppetService', 'tagContactDelete(%s)', id)
1966
+ override async tagGroupAdd (
1967
+ tagGroupName: string,
1968
+ ): Promise<PUPPET.payloads.TagGroup | void> {
1969
+ log.verbose('PuppetService', 'tagGroupAdd(%s)', tagGroupName)
1946
1970
 
1947
- const request = new grpcPuppet.TagContactDeleteRequest()
1948
- request.setId(id)
1971
+ const request = new grpcPuppet.TagGroupAddRequest()
1972
+
1973
+ request.setTagGroupName(tagGroupName)
1974
+
1975
+ const result = await util.promisify(
1976
+ this.grpcManager.client.tagGroupAdd
1977
+ .bind(this.grpcManager.client),
1978
+ )(request)
1979
+
1980
+ const grpcPayload = result.getPayload()
1981
+ const id = grpcPayload?.getId()
1982
+ const name = grpcPayload?.getName()
1983
+
1984
+ if (id && name) {
1985
+ const payload: PUPPET.payloads.TagGroup = {
1986
+ id,
1987
+ name,
1988
+ }
1989
+ return payload
1990
+ }
1991
+
1992
+ }
1993
+
1994
+ override async tagGroupDelete (
1995
+ tagGroupId: string,
1996
+ ): Promise<void> {
1997
+ log.verbose('PuppetService', 'tagGroupDelete(%s)', tagGroupId)
1998
+
1999
+ const request = new grpcPuppet.TagGroupDeleteRequest()
2000
+
2001
+ request.setTagGroupId(tagGroupId)
1949
2002
 
1950
2003
  await util.promisify(
1951
- this.grpcManager.client.tagContactDelete
2004
+ this.grpcManager.client.tagGroupDelete
1952
2005
  .bind(this.grpcManager.client),
1953
2006
  )(request)
2007
+
1954
2008
  }
1955
2009
 
1956
- // get tags from a specific Contact
1957
- override async tagContactList (
1958
- contactId?: string,
1959
- ) : Promise<string[]> {
1960
- log.verbose('PuppetService', 'tagContactList(%s)', contactId)
2010
+ override async tagTagAdd (
2011
+ tagGroupId: string | undefined,
2012
+ tagName: string,
2013
+ ): Promise<PUPPET.payloads.Tag | void> {
2014
+ log.verbose('PuppetService', 'tagTagAdd(%s, %s)', tagGroupId, tagName)
1961
2015
 
1962
- const request = new grpcPuppet.TagContactListRequest()
2016
+ const request = new grpcPuppet.TagTagAddRequest()
1963
2017
 
1964
- if (typeof contactId !== 'undefined') {
1965
- request.setContactId(contactId)
1966
- {
2018
+ if (typeof tagGroupId !== 'undefined') {
2019
+ request.setTagGroupId(tagGroupId)
2020
+ }
2021
+ request.setTagName(tagName)
1967
2022
 
1968
- /**
1969
- * Huan(202110): Deprecated: will be removed after Dec 31, 2022
1970
- */
1971
- const contactIdWrapper = new StringValue()
1972
- contactIdWrapper.setValue(contactId)
1973
- request.setContactIdStringValueDeprecated(contactIdWrapper)
2023
+ const result = await util.promisify(
2024
+ this.grpcManager.client.tagTagAdd
2025
+ .bind(this.grpcManager.client),
2026
+ )(request)
2027
+
2028
+ const grpcPayload = result.getPayload()
2029
+ const id = grpcPayload?.getId()
2030
+ const name = grpcPayload?.getName()
2031
+ const groupId = grpcPayload?.getGroupId()
2032
+ const type = grpcPayload?.getType()
2033
+
2034
+ if (id && name && type) {
2035
+ const payload: PUPPET.payloads.Tag = {
2036
+ id,
2037
+ name,
2038
+ groupId,
2039
+ type,
1974
2040
  }
2041
+ return payload
1975
2042
  }
1976
2043
 
1977
- const response = await util.promisify(
1978
- this.grpcManager.client.tagContactList
2044
+ }
2045
+
2046
+ override async tagTagDelete (
2047
+ tagGroupId: string | undefined,
2048
+ tagId: string,
2049
+ ): Promise<void> {
2050
+ log.verbose('PuppetService', 'tagTagDelete(%s, %s)', tagGroupId, tagId)
2051
+
2052
+ const request = new grpcPuppet.TagTagDeleteRequest()
2053
+
2054
+ if (typeof tagGroupId !== 'undefined') {
2055
+ request.setTagGroupId(tagGroupId)
2056
+ }
2057
+ request.setTagId(tagId)
2058
+
2059
+ await util.promisify(
2060
+ this.grpcManager.client.tagTagDelete
1979
2061
  .bind(this.grpcManager.client),
1980
2062
  )(request)
1981
2063
 
1982
- return response.getIdsList()
2064
+ }
2065
+
2066
+ override async tagGroupList (): Promise<PUPPET.payloads.TagGroup[]> {
2067
+ log.verbose('PuppetService', 'tagGroupList()')
2068
+
2069
+ const request = new grpcPuppet.TagGroupListRequest()
2070
+
2071
+ const result = await util.promisify(
2072
+ this.grpcManager.client.tagGroupList
2073
+ .bind(this.grpcManager.client),
2074
+ )(request)
2075
+
2076
+ const grpcPayloads = result.getPayloadsList()
2077
+ const payloads: PUPPET.payloads.TagGroup[] = grpcPayloads.map(payload => {
2078
+ return {
2079
+ id: payload.getId(),
2080
+ name: payload.getName(),
2081
+ } as PUPPET.payloads.TagGroup
2082
+ })
2083
+ return payloads
2084
+ }
2085
+
2086
+ override async tagGroupTagList (
2087
+ tagGroupId: string | undefined,
2088
+ ): Promise<PUPPET.payloads.Tag[]> {
2089
+ log.verbose('PuppetService', 'tagGroupTagList(%s)', tagGroupId)
2090
+
2091
+ const request = new grpcPuppet.TagGroupTagListRequest()
2092
+ if (typeof tagGroupId !== 'undefined') {
2093
+ request.setTagGroupId(tagGroupId)
2094
+ }
2095
+
2096
+ const result = await util.promisify(
2097
+ this.grpcManager.client.tagGroupTagList
2098
+ .bind(this.grpcManager.client),
2099
+ )(request)
2100
+
2101
+ const grpcPayloads = result.getPayloadsList()
2102
+ const payloads: PUPPET.payloads.Tag[] = grpcPayloads.map(payload => {
2103
+ return {
2104
+ id: payload.getId(),
2105
+ name: payload.getName(),
2106
+ groupId: payload.getGroupId(),
2107
+ type: payload.getType(),
2108
+ } as PUPPET.payloads.Tag
2109
+ })
2110
+ return payloads
2111
+ }
2112
+
2113
+ override async tagTagList (
2114
+ ): Promise<PUPPET.payloads.Tag[]> {
2115
+ log.verbose('PuppetService', 'tagTagList()')
2116
+
2117
+ const request = new grpcPuppet.TagTagListRequest()
2118
+
2119
+ const result = await util.promisify(
2120
+ this.grpcManager.client.tagTagList
2121
+ .bind(this.grpcManager.client),
2122
+ )(request)
2123
+
2124
+ const grpcPayloads = result.getPayloadsList()
2125
+ const payloads: PUPPET.payloads.Tag[] = grpcPayloads.map(payload => {
2126
+ return {
2127
+ id: payload.getId(),
2128
+ name: payload.getName(),
2129
+ groupId: payload.getGroupId(),
2130
+ type: payload.getType(),
2131
+ } as PUPPET.payloads.Tag
2132
+ })
2133
+ return payloads
2134
+ }
2135
+
2136
+ override async tagContactTagList (
2137
+ contactId: string,
2138
+ ): Promise<PUPPET.payloads.Tag[]> {
2139
+ log.verbose('PuppetService', 'tagContactTagList(%s)', contactId)
2140
+
2141
+ const request = new grpcPuppet.TagContactTagListRequest()
2142
+ request.setContactId(contactId)
2143
+
2144
+ const result = await util.promisify(
2145
+ this.grpcManager.client.tagContactTagList
2146
+ .bind(this.grpcManager.client),
2147
+ )(request)
2148
+
2149
+ const grpcPayloads = result.getPayloadsList()
2150
+ const payloads: PUPPET.payloads.Tag[] = grpcPayloads.map(payload => {
2151
+ return {
2152
+ id: payload.getId(),
2153
+ name: payload.getName(),
2154
+ groupId: payload.getGroupId(),
2155
+ type: payload.getType(),
2156
+ } as PUPPET.payloads.Tag
2157
+ })
2158
+ return payloads
2159
+ }
2160
+
2161
+ override async tagTagContactList (
2162
+ tagGroupId: string | undefined,
2163
+ tagId: string,
2164
+ ): Promise<string[]> {
2165
+ log.verbose('PuppetService', 'tagTagContactList(%s, %s)', tagGroupId, tagId)
2166
+
2167
+ const request = new grpcPuppet.TagTagContactListRequest()
2168
+ if (typeof tagGroupId !== 'undefined') {
2169
+ request.setTagGroupId(tagGroupId)
2170
+ }
2171
+ request.setTagId(tagId)
2172
+
2173
+ const result = await util.promisify(
2174
+ this.grpcManager.client.tagTagContactList
2175
+ .bind(this.grpcManager.client),
2176
+ )(request)
2177
+
2178
+ const payloads = result.getPayloadsList()
2179
+ return payloads
1983
2180
  }
1984
2181
 
1985
2182
  /**
@@ -4,7 +4,7 @@
4
4
  import type { PackageJson } from 'type-fest'
5
5
  export const packageJson: PackageJson = {
6
6
  "name": "@juzi/wechaty-puppet-service",
7
- "version": "1.0.12",
7
+ "version": "1.0.16",
8
8
  "description": "Puppet Service for Wechaty",
9
9
  "type": "module",
10
10
  "exports": {
@@ -69,10 +69,10 @@ export const packageJson: PackageJson = {
69
69
  "why-is-node-running": "^2.2.1"
70
70
  },
71
71
  "peerDependencies": {
72
- "@juzi/wechaty-puppet": "1.0.7"
72
+ "@juzi/wechaty-puppet": "^1.0.12"
73
73
  },
74
74
  "dependencies": {
75
- "@juzi/wechaty-grpc": "1.0.7",
75
+ "@juzi/wechaty-grpc": "^1.0.11",
76
76
  "clone-class": "^1.1.1",
77
77
  "ducks": "^1.0.2",
78
78
  "file-box": "^1.5.5",