Wechaty Puppet Service
This section is all about the Wechaty Puppet Service Registration & Discovery, which is the core system for our token.
The Puppet Service Discovery
When a Wechaty user is using a token with Wechaty, the Wechaty will use that token to connect to the specific puppet service.
The mechanism behind is the Puppet Service Discovery, which can resolve the IP of gGRPC service by the token, is implemented by the following steps:
- construct a URL:
https://api.chatie.io/v0/hosties/${TOKEN}
- make a GET request to the URL, and expect to get the following json object:
{"host":"1.2.3.4","port":1234}
the above 1.2.3.4
will be the gRPC server, and the port 1234
is the gRPC port.
- if the token is not registered, then the GET request will get a HTTP 404 with the below object:
{"host":"0.0.0.0","port":0}
- For the Wechaty SDK, we support the following environment variables so that the users can switch between different languages without any changes:
export WECHATY_PUPPET_SERVICE_TOKEN=${TOKEN}
The Registration
In order to publish a Wechaty Puppet Service Token to the Wechaty community, you need to register this token by following the Wechaty Puppet Service Registration process.
There are two ways to do the registration to publish the tokens:
- By running a Wechaty docker command
- By following the Wechaty Puppet Service Registration Protocol
1. Registration the Token with Docker
You can visit the links below which gives a more detailed step by step description about registration of token using Docker.
- How to create your own Wechaty Puppet Service Token with the Web Protocol #1986
- Using your Puppet PadPlus token with Python, Java, and Go Wechaty #1985
Through the above steps, you can publish a token with any existing wechaty puppets. Other Related issues are listed below :
- https://github.com/wechaty/python-wechaty/issues/58
- https://github.com/wechaty/wechaty/issues/1984
- https://github.com/wechaty/wechaty/issues/1153
2. Register the Token with Protocol
The current process can be described as the following steps:
- The
puppet server
sends a WebSocket connection towss://api.chatie.io/v0/websocket
, with an HTTP authorization headerToken rock_token_here
. After the connection has been established, theapi.chatie.io
service will register your token online.See the source code - When a puppet service discovery query has been sent to
api.chatie.io
likehttps://api.chatie.io/v0/hosties/puppet_rock_token
has been visited, theapi.chatie.io
will send a JSONRPC to you via the WebSocket connection, with the method namehostieGrpcPort
, and you need to return your service port so that it can be returned to the user.See the source code - You can learn more about the registration protocol via this discussion: Support rock puppet service provider. #98 The following is a pictorial representation that describes the process above.
Registration Process Discussion
The current process can be described as the following two steps:
- The
Wechaty Puppet Server
sends a WebSocket connection towss://api.chatie.io/v0/websocket
, with an HTTP authorization headerToken puppet_servcie_token_here
. After the connection has been established, theapi.chatie.io
service will register your token online.Refer to the source code - When a Wechaty Puppet Service Discovery Query has been sent to
api.chatie.io
likehttps://api.chatie.io/v0/hosties/puppet_service_token
has been visited, theapi.chatie.io
will send a JSONRPC to you via the WebSocket connection, with the method namehostieGrpcPort
, and you need to return your service port so that it can be returned to the user.Refer to the source code - Wechaty allows to register multiple rock puppet token to the service with the same IP and Port without any problem. for more information checkout the link.