-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto-generate TypeScript data structure from wechaty/grpc #171
Comments
We will generate the JS/TS by running Line 29 in 7d881dd
And you can learn how to use the |
Thx. Will such generated code be published somewhere for public's general consumption? |
Yes. They are published as wechaty-grpc NPM module |
Oh, sorry, I meant the generated TS data structure from wechaty/go-grpc. So I took a look at the Is such generated |
Yes, we have published the go-grpc at https://github.com/wechaty/go-grpc Please also refer to the action script: Lines 35 to 44 in 7d881dd
|
sorry, I meant the generated TypeScript data structure, not I took a look at the content of wechaty-grpc npm module, and see:
I.e., I see almost all languages, except TypeScript / JavaScript. |
And, under $ npm run generate
> [email protected] generate
> bash -x scripts/generate-stub.sh
+ set -e
+ PROTO_DIR=./proto/
+ THIRD_PARTY_DIR=./third-party/
+ OUT_DIR=./generated
+ '[' -d ./generated ']'
+ mkdir -p ./generated
++ find ./proto/ ./third-party/ -type f -name '*.proto'
find: â./third-party/â: No such file or directory
+ PROTO_FILE_LIST='./proto/wechaty/puppet.proto
./proto/wechaty/puppet/file_box.proto
./proto/wechaty/puppet/base.proto
./proto/wechaty/puppet/message.proto
./proto/wechaty/puppet/room_invitation.proto
./proto/wechaty/puppet/contact.proto
./proto/wechaty/puppet/friendship.proto
./proto/wechaty/puppet/tag.proto
./proto/wechaty/puppet/room.proto
./proto/wechaty/puppet/event.proto
./proto/wechaty/puppet/room_member.proto'
$ find !$
find ./generated
./generated I.e., I see nothing get generated. |
Your local repo is outdated:
┌ [email protected]:~/git/wechaty/grpc [13:35:45] tty:[11] jobs:[0]
└ (main) $ jq .version package.json
"0.33.6" Run ┌ [email protected]:~/git/wechaty/grpc [13:35:29] tty:[11] jobs:[0]
└ (main) $ npm run generate
> [email protected] generate
> bash -x scripts/generate-stub.sh
+ set -e
+ shopt -s globstar
+++ dirname scripts/generate-stub.sh
++ cd scripts
++ pwd -P
+ WORK_DIR=/home/huan/git/wechaty/grpc/scripts
++ cd /home/huan/git/wechaty/grpc/scripts/../
++ pwd -P
+ REPO_DIR=/home/huan/git/wechaty/grpc
+ OUT_DIR=/home/huan/git/wechaty/grpc/out/
+ '[' -d /home/huan/git/wechaty/grpc/out/ ']'
+ PROTOC_CMD='protoc -I /home/huan/git/wechaty/grpc/third-party/ -I /home/huan/git/wechaty/grpc/proto/ /home/huan/git/wechaty/grpc/third-party/**/*.proto /home/huan/git/wechaty/grpc/proto/**/*.proto '
+ main
+ gen_js_pb
+ protoc -I /home/huan/git/wechaty/grpc/third-party/ -I /home/huan/git/wechaty/grpc/proto/ /home/huan/git/wechaty/grpc/third-party/google/api/annotations.proto /home/huan/git/wechaty/grpc/third-party/google/api/health_check/v1/health_check.proto /home/huan/git/wechaty/grpc/third-party/google/api/http.proto /home/huan/git/wechaty/grpc/third-party/protoc-gen-openapiv2/options/annotations.proto /home/huan/git/wechaty/grpc/third-party/protoc-gen-openapiv2/options/openapiv2.proto /home/huan/git/wechaty/grpc/proto/wechaty/deprecated/file-box.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/base.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/contact.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/download-upload.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/event.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/friendship.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/image.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/location.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/message.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/mini-program.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/referrer.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/room-invitation.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/room-member.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/room.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/tag.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/url-link.proto --js_out=import_style=commonjs,binary:/home/huan/git/wechaty/grpc/out/
+ gen_js_stub
+ protoc -I /home/huan/git/wechaty/grpc/third-party/ -I /home/huan/git/wechaty/grpc/proto/ /home/huan/git/wechaty/grpc/third-party/google/api/annotations.proto /home/huan/git/wechaty/grpc/third-party/google/api/health_check/v1/health_check.proto /home/huan/git/wechaty/grpc/third-party/google/api/http.proto /home/huan/git/wechaty/grpc/third-party/protoc-gen-openapiv2/options/annotations.proto /home/huan/git/wechaty/grpc/third-party/protoc-gen-openapiv2/options/openapiv2.proto /home/huan/git/wechaty/grpc/proto/wechaty/deprecated/file-box.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/base.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/contact.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/download-upload.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/event.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/friendship.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/image.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/location.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/message.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/mini-program.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/referrer.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/room-invitation.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/room-member.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/room.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/tag.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/url-link.proto --plugin=protoc-gen-grpc=node_modules/.bin/grpc_tools_node_protoc_plugin --grpc_out=grpc_js:/home/huan/git/wechaty/grpc/out/
+ gen_ts_typing
+ protoc -I /home/huan/git/wechaty/grpc/third-party/ -I /home/huan/git/wechaty/grpc/proto/ /home/huan/git/wechaty/grpc/third-party/google/api/annotations.proto /home/huan/git/wechaty/grpc/third-party/google/api/health_check/v1/health_check.proto /home/huan/git/wechaty/grpc/third-party/google/api/http.proto /home/huan/git/wechaty/grpc/third-party/protoc-gen-openapiv2/options/annotations.proto /home/huan/git/wechaty/grpc/third-party/protoc-gen-openapiv2/options/openapiv2.proto /home/huan/git/wechaty/grpc/proto/wechaty/deprecated/file-box.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/base.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/contact.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/download-upload.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/event.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/friendship.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/image.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/location.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/message.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/mini-program.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/referrer.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/room-invitation.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/room-member.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/room.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/tag.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/url-link.proto --plugin=protoc-gen-grpc=node_modules/grpc_tools_node_protoc_ts/bin/protoc-gen-ts --grpc_out=grpc_js:/home/huan/git/wechaty/grpc/out/
+ gen_cjs_package_json
+ echo '{"type": "commonjs"}'
+ gen_web_grpc
+ protoc -I /home/huan/git/wechaty/grpc/third-party/ -I /home/huan/git/wechaty/grpc/proto/ /home/huan/git/wechaty/grpc/third-party/google/api/annotations.proto /home/huan/git/wechaty/grpc/third-party/google/api/health_check/v1/health_check.proto /home/huan/git/wechaty/grpc/third-party/google/api/http.proto /home/huan/git/wechaty/grpc/third-party/protoc-gen-openapiv2/options/annotations.proto /home/huan/git/wechaty/grpc/third-party/protoc-gen-openapiv2/options/openapiv2.proto /home/huan/git/wechaty/grpc/proto/wechaty/deprecated/file-box.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/base.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/contact.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/download-upload.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/event.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/friendship.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/image.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/location.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/message.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/mini-program.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/referrer.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/room-invitation.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/room-member.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/room.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/tag.proto /home/huan/git/wechaty/grpc/proto/wechaty/puppet/url-link.proto --plugin=protoc-gen-ts=node_modules/ts-protoc-gen/bin/protoc-gen-ts --ts_out=service=grpc-web:/home/huan/git/wechaty/grpc/out/
+ gen_openapi
+ pushd openapi
~/git/wechaty/grpc/openapi ~/git/wechaty/grpc
+ make generate
./generate.sh
Swagger version synced with gRPC version 0.33.6 for /home/huan/git/wechaty/grpc/out//wechaty/puppet.swagger.json
+ popd
~/git/wechaty/grpc
┌ [email protected]:~/git/wechaty/grpc [13:35:36] tty:[11] jobs:[0]
└ (main) $ ls gen
ls: cannot access 'gen': No such file or directory
┌ [email protected]:~/git/wechaty/grpc [13:35:41] tty:[11] jobs:[0]
└ (main) $ ls out/
google package.json protoc-gen-openapiv2 wechaty
┌ [email protected]:~/git/wechaty/grpc [13:35:42] tty:[11] jobs:[0]
└ (main) $ ls out/wechaty/
deprecated puppet_grpc_pb.d.ts puppet.openapi.yaml puppet_pb.js puppet_pb_service.js
puppet puppet_grpc_pb.js puppet_pb.d.ts puppet_pb_service.d.ts puppet.swagger.json
┌ [email protected]:~/git/wechaty/grpc [13:35:45] tty:[11] jobs:[0]
└ (main) $ jq .version package.json
"0.33.6" They reside in the |
I got that wechaty-grpc with
The above code was run under my Sorry I'm not very clear how to properly get the result of yours above. Can you try to run |
Oh, Run |
$ npm run generate
> [email protected] generate
> bash -x scripts/generate-stub.sh
. . .
+ protoc -I /home/suntong/git/grpc/third-party/ -I /home/suntong/git/grpc/proto/ '/home/suntong/git/grpc/third-party/**/*.proto' /home/suntong/git/grpc/proto/wechaty/deprecated/file-box.proto /home/suntong/git/grpc/proto/wechaty/puppet.proto /home/suntong/git/grpc/proto/wechaty/puppet/base.proto /home/suntong/git/grpc/proto/wechaty/puppet/contact.proto /home/suntong/git/grpc/proto/wechaty/puppet/download-upload.proto /home/suntong/git/grpc/proto/wechaty/puppet/event.proto /home/suntong/git/grpc/proto/wechaty/puppet/friendship.proto /home/suntong/git/grpc/proto/wechaty/puppet/image.proto /home/suntong/git/grpc/proto/wechaty/puppet/location.proto /home/suntong/git/grpc/proto/wechaty/puppet/message.proto /home/suntong/git/grpc/proto/wechaty/puppet/mini-program.proto /home/suntong/git/grpc/proto/wechaty/puppet/referrer.proto /home/suntong/git/grpc/proto/wechaty/puppet/room-invitation.proto /home/suntong/git/grpc/proto/wechaty/puppet/room-member.proto /home/suntong/git/grpc/proto/wechaty/puppet/room.proto /home/suntong/git/grpc/proto/wechaty/puppet/tag.proto /home/suntong/git/grpc/proto/wechaty/puppet/url-link.proto --js_out=import_style=commonjs,binary:/home/suntong/git/grpc/out/
scripts/generate-stub.sh: line 30: protoc: command not found
$ ./scripts/install-protoc.sh
[sudo] password for suntong:
$ id
uid=1006(suntong) gid=1006(suntong) groups=1006(suntong),116(docker),1001(wechaty) I.e., I need Is it possible that I have Or, somebody install |
Protoc has been installed on our community server: root@wechaty-contributors:/home/suntong/git/grpc/scripts# sudo apt install -y protobuf-compiler
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
linux-azure-cloud-tools-5.4.0-1036 linux-azure-headers-5.4.0-1036 linux-azure-tools-5.4.0-1036 linux-cloud-tools-5.4.0-1036-azure linux-headers-5.4.0-1036-azure linux-image-5.4.0-1036-azure
linux-modules-5.4.0-1036-azure linux-modules-extra-5.4.0-1036-azure linux-tools-5.4.0-1036-azure
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
libprotobuf-dev libprotobuf-lite17 libprotoc17
The following NEW packages will be installed:
libprotobuf-dev libprotobuf-lite17 libprotoc17 protobuf-compiler
0 upgraded, 4 newly installed, 0 to remove and 120 not upgraded.
Need to get 1,960 kB of archives.
After this operation, 13.8 MB of additional disk space will be used.
Get:1 http://azure.archive.ubuntu.com/ubuntu focal/main amd64 libprotobuf-lite17 amd64 3.6.1.3-2ubuntu5 [132 kB]
Get:2 http://azure.archive.ubuntu.com/ubuntu focal/main amd64 libprotoc17 amd64 3.6.1.3-2ubuntu5 [646 kB]
Get:3 http://azure.archive.ubuntu.com/ubuntu focal/main amd64 libprotobuf-dev amd64 3.6.1.3-2ubuntu5 [1,155 kB]
Get:4 http://azure.archive.ubuntu.com/ubuntu focal/universe amd64 protobuf-compiler amd64 3.6.1.3-2ubuntu5 [27.6 kB]
Fetched 1,960 kB in 0s (26.9 MB/s)
Selecting previously unselected package libprotobuf-lite17:amd64.
(Reading database ... 164255 files and directories currently installed.)
Preparing to unpack .../libprotobuf-lite17_3.6.1.3-2ubuntu5_amd64.deb ...
Unpacking libprotobuf-lite17:amd64 (3.6.1.3-2ubuntu5) ...
Selecting previously unselected package libprotoc17:amd64.
Preparing to unpack .../libprotoc17_3.6.1.3-2ubuntu5_amd64.deb ...
Unpacking libprotoc17:amd64 (3.6.1.3-2ubuntu5) ...
Selecting previously unselected package libprotobuf-dev:amd64.
Preparing to unpack .../libprotobuf-dev_3.6.1.3-2ubuntu5_amd64.deb ...
Unpacking libprotobuf-dev:amd64 (3.6.1.3-2ubuntu5) ...
Selecting previously unselected package protobuf-compiler.
Preparing to unpack .../protobuf-compiler_3.6.1.3-2ubuntu5_amd64.deb ...
Unpacking protobuf-compiler (3.6.1.3-2ubuntu5) ...
Setting up libprotoc17:amd64 (3.6.1.3-2ubuntu5) ...
Setting up protobuf-compiler (3.6.1.3-2ubuntu5) ...
Setting up libprotobuf-lite17:amd64 (3.6.1.3-2ubuntu5) ...
Setting up libprotobuf-dev:amd64 (3.6.1.3-2ubuntu5) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
root@wechaty-contributors:/home/suntong/git/grpc/scripts# protoc --version
libprotoc 3.6.1 |
thx @huan ! Now
|
You are welcome. Please refer to our GitHub Action YAML file to learn how to reproduce the generating process |
Hmm... The above
Yet, why $ npm run install:protoc
> [email protected] install:protoc
> bash -x scripts/install-protoc.sh
+ set -e
+ set -o pipefail
+++ dirname scripts/install-protoc.sh
++ cd scripts
++ pwd -P
+ WORK_DIR=/home/suntong/git/grpc/scripts
++ cd /home/suntong/git/grpc/scripts/../
++ pwd -P
+ REPO_DIR=/home/suntong/git/grpc
+ THIRD_PARTY_DIR=/home/suntong/git/grpc/third-party/
+ main
+ install_protoc
+ command -v protoc
+ echo 'install skipped: protoc exists'
install skipped: protoc exists
+ return
+ check_protoc_version
++ protoc --version
++ cut '-d ' -f 2
+ protocVersion=3.6.1
++ cut -d. -f 1
++ echo 3.6.1
+ majorVer=3
++ echo 3.6.1
++ cut -d. -f 2
+ minorVer=6
+ (( 3 == 3 ))
+ (( 6 >= 17 ))
+ echo 'protoc minor version must >= 17 (the installed version is 3.6.1)'
protoc minor version must >= 17 (the installed version is 3.6.1)
+ exit 1 |
I then skipped that step and run the next few steps:
What else I'm missing? |
Have updated it to v3.19.3 See: https://grpc.io/docs/protoc-installation/#install-pre-compiled-binaries-any-os $ protoc --version
libprotoc 3.19.1 |
OK, now a different error after updating it to v3.19.3:
please |
Done. And all you need is to run $ ./scripts/install-protoc.sh
install skipped: protoc exists
protoc version check: v3.19.1 OK
go: downloading github.com/ckaznocha/protoc-gen-lint v0.2.4
go: downloading google.golang.org/protobuf v1.26.0
~/git/grpc/openapi ~/git/grpc
./install.sh
go: downloading google.golang.org/protobuf v1.27.1
go: downloading google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0
go: downloading google.golang.org/grpc v1.42.0
go: downloading google.golang.org/protobuf v1.23.0
go: downloading github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.1
go: downloading github.com/golang/glog v1.0.0
go: downloading google.golang.org/genproto v0.0.0-20211129164237-f09f9a12af12
go: downloading sigs.k8s.io/yaml v1.3.0
go: downloading gopkg.in/yaml.v2 v2.4.0
go: downloading github.com/golang/protobuf v1.5.2
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1760 100 1760 0 0 5789 0 --:--:-- --:--:-- --:--:-- 5789
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 24777 100 24777 0 0 76236 0 --:--:-- --:--:-- --:--:-- 76236
~/git/grpc
go: downloading github.com/pseudomuto/protoc-gen-doc v1.5.0
go: downloading github.com/pseudomuto/protokit v0.2.0
go: downloading google.golang.org/genproto v0.0.0-20181107211654-5fc9ac540362
go: downloading github.com/golang/protobuf v1.4.2
go: downloading github.com/mwitkow/go-proto-validators v0.0.0-20180403085117-0950a7990007
go: downloading github.com/Masterminds/sprig v2.15.0+incompatible
go: downloading github.com/envoyproxy/protoc-gen-validate v0.3.0-java
go: downloading github.com/gogo/protobuf v1.1.1
go: downloading github.com/Masterminds/semver v1.4.2
go: downloading github.com/aokoli/goutils v1.0.1
go: downloading github.com/google/uuid v0.0.0-20161128191214-064e2069ce9c
go: downloading github.com/huandu/xstrings v1.0.0
go: downloading github.com/imdario/mergo v0.3.4
go: downloading golang.org/x/crypto v0.0.0-20180501155221-613d6eafa307
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1045 100 1045 0 0 3415 0 --:--:-- --:--:-- --:--:-- 3415
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 15140 100 15140 0 0 47760 0 --:--:-- --:--:-- --:--:-- 47760
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 15140 100 15140 0 0 924k 0 --:--:-- --:--:-- --:--:-- 924k
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2416 100 2416 0 0 7023 0 --:--:-- --:--:-- --:--:-- 7023 |
Thx! Now I get it going. But calling
But at least my |
I think I misunderstand what wechaty/grpc generates when I asked this question. Apparently what generated is how the puppet client can talk to wechaty/grpc server with the protobuf protocol, right? Is there anywhere I can find the definition in TypeScript of the data structure of different wechat message are? E.g., for a type 54 wechat message ( Hmmm, maybe these?
but these only cast different message requests into objects. Not message itself.
Maybe the message data type is defined in |
Are you trying to find this? Most of the universal schema definitions are in the above folder. |
Hmm... more or less this |
You can also refer to the source code of webwx app: //msg type
MSGTYPE_TEXT: 1
, MSGTYPE_IMAGE: 3
, MSGTYPE_VOICE: 34
, MSGTYPE_VIDEO: 43
, MSGTYPE_MICROVIDEO: 62
, MSGTYPE_EMOTICON: 47
, MSGTYPE_APP: 49
, MSGTYPE_VOIPMSG: 50, // voip msg
MSGTYPE_VOIPNOTIFY: 52, // voip 结束消息
MSGTYPE_VOIPINVITE: 53, // voip 邀请
MSGTYPE_LOCATION: 48
, MSGTYPE_STATUSNOTIFY: 51
, MSGTYPE_SYSNOTICE: 9999
, MSGTYPE_POSSIBLEFRIEND_MSG: 40
, MSGTYPE_VERIFYMSG: 37
, MSGTYPE_SHARECARD: 42
, MSGTYPE_SYS: 10000
, MSGTYPE_RECALLED: 10002, See: |
I'm looking for the definition in TypeScript of the data structure of different wechat message. E.g., for this type 51 message: <?xml version="1.0"?>
<msg>
<appmsg appid="" sdkver="0">
<title>Your current WeChat version does not support this content. Update to the latest version.</title>
<des />
<username />
<action>view</action>
<type>51</type>
<showtype>0</showtype>
<content />
<url>https://support.weixin.qq.com/security/readtemplate?t=w_security_center_website/upgrade</url>
<lowurl />
<dataurl />
<lowdataurl />
<contentattr>0</contentattr>
<streamvideo>
<streamvideourl />
<streamvideototaltime>0</streamvideototaltime>
<streamvideotitle />
<streamvideowording />
<streamvideoweburl />
<streamvideothumburl />
<streamvideoaduxinfo />
<streamvideopublishid />
</streamvideo>
<canvasPageItem>
<canvasPageXml><![CDATA[]]></canvasPageXml>
</canvasPageItem>
<appattach>
<totallen>0</totallen>
<attachid />
<cdnattachurl />
<emoticonmd5></emoticonmd5>
<aeskey></aeskey>
<fileext />
<islargefilemsg>0</islargefilemsg>
<overwrite_newmsgid>0</overwrite_newmsgid>
<fileuploadtoken><![CDATA[]]></fileuploadtoken>
</appattach>
<extinfo />
<androidsource>0</androidsource>
<thumburl />
<mediatagname />
<messageaction><![CDATA[]]></messageaction>
<messageext><![CDATA[]]></messageext>
<emoticongift>
<packageflag>0</packageflag>
<packageid />
</emoticongift>
<emoticonshared>
<packageflag>0</packageflag>
<packageid />
</emoticonshared>
<designershared>
<designeruin>0</designeruin>
<designername>null</designername>
<designerrediretcturl>null</designerrediretcturl>
</designershared>
<emotionpageshared>
<tid>0</tid>
<title>null</title>
<desc>null</desc>
<iconUrl>null</iconUrl>
<secondUrl />
<pageType>0</pageType>
</emotionpageshared>
<webviewshared>
<shareUrlOriginal />
<shareUrlOpen />
<jsAppId />
<publisherId />
</webviewshared>
<template_id />
<md5 />
<weappinfo>
<username />
<appid />
<appservicetype>0</appservicetype>
<videopageinfo>
<thumbwidth>0</thumbwidth>
<thumbheight>0</thumbheight>
<fromopensdk>0</fromopensdk>
</videopageinfo>
</weappinfo>
<statextstr />
<musicShareItem>
<musicDuration>0</musicDuration>
</musicShareItem>
<finderFeed>
<objectId>13586191238638082080</objectId>
<objectNonceId>2479223310619088676_4_20_13</objectNonceId>
<feedType>4</feedType>
<nickname>滇东南行者</nickname>
<username>v2_060000231003b20faec8c5e5881bc4d1cb03ea36b077a34e350ea4895034bb2b4d3df377eabd@finder</username>
<avatar><![CDATA[http://wx.qlogo.cn/finderhead/eHEMOF2hOelPSyzBicEqdLPKKsTbS7Ff9h7d54WtPUqBPjjLicNwu2hw/0]]></avatar>
<desc>像是回到了冰河时代,冰雹,暴雨,雪,一起砸下来,头一回见这么厉害!</desc>
<mediaCount>1</mediaCount>
<localId>0</localId>
<mediaList>
<media>
<mediaType>4</mediaType>
<url><![CDATA[http://wxapp.tc.qq.com/251/20302/stodownload?encfilekey=Cvvj5Ix3eezXKmVNfShJRUicJJMYPEroic4L0paJjibKRISeJCCpqp7iaS9rxgh97Vyx0RpQR4HSnO5cpRJibMyXaKyWDH4Ye4SjRfQc2DqvWhfdjIT4OE9lrgnqElVykU31ShvsTgAoUmcHA4p9J6HWPP8uTbbdZkaicgbH2fOfGgMYOf3KicK7JicHjHoKgIXUGsuJ&adaptivelytrans=0&bizid=1023&dotrans=938&hy=SZ&idx=1&m=7d3803d8f2c1afb7aed787ec5937609a]]></url>
<thumbUrl><![CDATA[http://wxapp.tc.qq.com/251/20350/stodownload?encfilekey=XGocBFxVWK5dcyOOqpEU4yZ0ia4qlCRBBTHTgGfEODUzWBl1WYcKtOuUjeibYYPcHlURnMw0RwbE68WWTopR43X9CWEvV50Z33iax7yKY6NgCjus14sicoFdF3SUDrfnquCXicffUnEb5udxYC8fiaXTZs6iaThfTs7ia8HU8nkicwoOI8XibrSiaIZQmmBog&adaptivelytrans=0&bizid=1023&dotrans=0&hy=SZ&idx=1&m=78634793a91e2c6011e51255c325e5ed&token=x5Y29zUxcibBiaGHtmXXicGxqSiaiaOb6G2y8lpQ4vWoI03lxEt7I0zhgjyibLibUJSRNc5]]></thumbUrl>
<fullCoverUrl><![CDATA[http://wxapp.tc.qq.com/251/20304/stodownload?encfilekey=XGocBFxVWK5dcyOOqpEU4yZ0ia4qlCRBBFUImJxslyp8liaHI4I5h2IsSyAPZVT5tabmyIbDEHLUYpRbao6Y4LQ45hh0HN4ibkib6Fng9wpl2KjRaIRaQgwaI1ibiaGG9BB8Jg1iaicI0h66Hcg04SaYl8YITgKNW383xy5ljfrIgSgNIXxb3iaof8y9J6A&adaptivelytrans=0&bizid=1023&dotrans=0&hy=SZ&idx=1&m=9525757867aa7e93bd14ee3a8721dcc4&token=x5Y29zUxcibCvkDbNQE5SdNN7OrXdJWIRQjGibFFddEhQqHNdhWuJicdp7CW630yUjia]]></fullCoverUrl>
<fullClipInset><![CDATA[]]></fullClipInset>
<width>720.0</width>
<height>1280.0</height>
<videoPlayDuration>43</videoPlayDuration>
</media>
</mediaList>
<megaVideo>
<objectId />
<objectNonceId />
</megaVideo>
</finderFeed>
<findernamecard>
<username />
<avatar><![CDATA[]]></avatar>
<nickname />
<auth_job />
<auth_icon>0</auth_icon>
<auth_icon_url />
</findernamecard>
<finderEndorsement>
<scene><![CDATA[0]]></scene>
</finderEndorsement>
<directshare>0</directshare>
<gamecenter>
<namecard>
<iconUrl />
<name />
<desc />
<tail />
<jumpUrl />
</namecard>
</gamecenter>
<patMsg>
<chatUser />
<records>
<recordNum>0</recordNum>
</records>
</patMsg>
<websearch />
</appmsg>
<fromusername>wxid_h6tt4q3egsoh22</fromusername>
<scene>0</scene>
<appinfo>
<version>1</version>
<appname />
</appinfo>
<commenturl />
</msg> The corresponding TypeScript data structure would more or less look like this: declare module namespace {
export interface Streamvideo {
streamvideourl: any[];
streamvideototaltime: string;
streamvideotitle: any[];
streamvideowording: any[];
streamvideoweburl: any[];
streamvideothumburl: any[];
streamvideoaduxinfo: any[];
streamvideopublishid: any[];
}
export interface CanvasPageItem {
canvasPageXml: any[];
}
export interface Appattach {
totallen: string;
attachid: any[];
cdnattachurl: any[];
emoticonmd5: any[];
aeskey: any[];
fileext: any[];
islargefilemsg: string;
overwrite_newmsgid: string;
fileuploadtoken: any[];
}
export interface Emoticongift {
packageflag: string;
packageid: any[];
}
export interface Emoticonshared {
packageflag: string;
packageid: any[];
}
export interface Designershared {
designeruin: string;
designername?: any;
designerrediretcturl?: any;
}
export interface Emotionpageshared {
tid: string;
title?: any;
desc?: any;
iconUrl?: any;
secondUrl: any[];
pageType: string;
}
export interface Webviewshared {
shareUrlOriginal: any[];
shareUrlOpen: any[];
jsAppId: any[];
publisherId: any[];
}
export interface Videopageinfo {
thumbwidth: string;
thumbheight: string;
fromopensdk: string;
}
export interface Weappinfo {
username: any[];
appid: any[];
appservicetype: string;
videopageinfo: Videopageinfo;
}
export interface MusicShareItem {
musicDuration: string;
}
export interface Media {
mediaType: string;
url: string;
thumbUrl: string;
fullCoverUrl: string;
fullClipInset: any[];
width: string;
height: string;
videoPlayDuration: string;
}
export interface MediaList {
media: Media;
}
export interface MegaVideo {
objectId: any[];
objectNonceId: any[];
}
export interface FinderFeed {
objectId: string;
objectNonceId: string;
feedType: string;
nickname: string;
username: string;
avatar: string;
desc: string;
mediaCount: string;
localId: string;
mediaList: MediaList;
megaVideo: MegaVideo;
}
export interface Findernamecard {
username: any[];
avatar: any[];
nickname: any[];
auth_job: any[];
auth_icon: string;
auth_icon_url: any[];
}
export interface FinderEndorsement {
scene: string;
}
export interface Namecard {
iconUrl: any[];
name: any[];
desc: any[];
tail: any[];
jumpUrl: any[];
}
export interface Gamecenter {
namecard: Namecard;
}
export interface Records {
recordNum: string;
}
export interface PatMsg {
chatUser: any[];
records: Records;
}
export interface Appmsg {
@appid: string;
@sdkver: string;
title: string;
des: any[];
username: any[];
action: string;
type: string;
showtype: string;
content: any[];
url: string;
lowurl: any[];
dataurl: any[];
lowdataurl: any[];
contentattr: string;
streamvideo: Streamvideo;
canvasPageItem: CanvasPageItem;
appattach: Appattach;
extinfo: any[];
androidsource: string;
thumburl: any[];
mediatagname: any[];
messageaction: any[];
messageext: any[];
emoticongift: Emoticongift;
emoticonshared: Emoticonshared;
designershared: Designershared;
emotionpageshared: Emotionpageshared;
webviewshared: Webviewshared;
template_id: any[];
md5: any[];
weappinfo: Weappinfo;
statextstr: any[];
musicShareItem: MusicShareItem;
finderFeed: FinderFeed;
findernamecard: Findernamecard;
finderEndorsement: FinderEndorsement;
directshare: string;
gamecenter: Gamecenter;
patMsg: PatMsg;
websearch: any[];
}
export interface Appinfo {
version: string;
appname: any[];
}
export interface RootObject {
appmsg: Appmsg;
fromusername: string;
scene: string;
appinfo: Appinfo;
commenturl: any[];
}
} |
Because TypeScript object is strongly typed. Thus it need data structure so as to visit data. In Javascript, to convert a JSON string to Javascript object, one can simply do this: const text = '{"name":"John", "birth":"1986-12-14", "city":"New York"}'
const obj = JSON.parse(text) |
I hope you can solve your problem soon, good luck! |
🚀 Feature
From #65:
So what's the status of auto-generating ts-wechaty data definitions from wechaty/grpc?
It seems that we have Go, Java, PHP, but I don't see other languages like TS.
I don't know JS/TS much, but
says that https://github.com/grpc/grpc-node/ seems to be a good candidate,
gRPC on Node.js with Buf and TypeScript
https://slavovojacek.medium.com/?p=5aad61bab03b
I don't know JS/TS much, but hope ts-wechaty DS auto-generation can be done soon, so that we can avoid problems like #65, and fix issues like wechaty/puppet-padlocal#76 and wechaty/puppet-padlocal#68
thanks
The text was updated successfully, but these errors were encountered: