Puppet Service: DIY
You can make a Wechaty Puppet Service easily from any Wechaty Puppet Providers.
You can build a Wechaty Puppet Service by yourself with any Wechaty Puppet Providers.
Steps
We have a easy to use docker image which works out-of-the-box.
1. Pull the latest Wechaty Docker Image
docker pull wechaty/wechaty
2. Config Wechaty Puppet Provider
We need to choice which Wechaty Puppet Provider we want to use by setting the WECHATY_PUPPET
environment variable.
For example, you can choose wechaty-puppet-wechat by setting WECHATY_PUPPET=wechaty-puppet-wechat
.
Learn all Wechaty Puppet Providers
You need to set all environment variables which requires from a specific provider.
For example, an additional token will be required by PadLocal
: WECHATY_PUPPET_PADLOCAL_TOKEN=puppet_padlocal${TOKEN}
- Linux
- macOS
- Windows
export WECHATY_PUPPET="wechaty-puppet-wechat"
export WECHATY_PUPPET="wechaty-puppet-wechat"
set WECHATY_PUPPET="wechaty-puppet-wechat"
3. Create your own Wechaty Puppet Service TOKEN
In order to provide Wechaty Puppet Service, you need to specify a TOKEN for authorization.
You can Generate a new UUIDv4 online, use this new UUIDv4 as your token.
Your new token MUST different to any existing tokens in our system. (or they will conflict!)
- Linux
- macOS
- Windows
export WECHATY_TOKEN=$(curl -s https://www.uuidgenerator.net/api/version4)
echo "WECHATY_TOKEN=$WECHATY_TOKEN"
export WECHATY_TOKEN=$(curl -s https://www.uuidgenerator.net/api/version4)
echo "WECHATY_TOKEN=$WECHATY_TOKEN"
# TODO: use script to get UUIDv4 automatically like Linux/Mac
set WECHATY_TOKEN="__UUIDv4__"
4. Set Wechaty Puppet Service port
The port for your Wechaty Puppet Service need to be specified. Make sure it's free on your server.
- The server IP must be public on the internet
- the port must be public accessible on the internet
- Linux
- macOS
- Windows
export WECHATY_PUPPET_SERVER_PORT="8788"
export WECHATY_PUPPET_SERVER_PORT="8788"
set WECHATY_PUPPET_SERVER_PORT="8788"
5. Set Wechaty Log Level
Enable verbose
log message output for easy debugging.
More options are:
silly
: all debug messages will be outputedverbose
: recommended debug levelinfo
: disable debug messageswarning
: only warning messagesilence
: no log message
- Linux
- macOS
- Windows
export WECHATY_LOG="verbose"
export WECHATY_LOG="verbose"
set WECHATY_LOG="verbose"
6. Config TLS(SSL) for Wechaty Puppet Service (optional)
From Wechaty version 0.67, the Puppet Service will enable TLS(SSL) by default. (See wechaty/wechaty-puppet-service#160)
You can enable/disable the TLS by setting environment variables to fullfil your needs.
For example, if you need to provide a Wechaty Puppet Service token without TLS, then you can set WECHATY_PUPPET_SERVICE_NO_TLS_INSECURE_SERVER=true
to disable TLS.
- Linux
- macOS
- Windows
# set to "true" to disable TLS (not recommanded)
export WECHATY_PUPPET_SERVICE_NO_TLS_INSECURE_SERVER="false"
# set to "true" to disable TLS (not recommanded)
export WECHATY_PUPPET_SERVICE_NO_TLS_INSECURE_SERVER="false"
# set to "true" to disable TLS (not recommanded)
set WECHATY_PUPPET_SERVICE_NO_TLS_INSECURE_SERVER="false"
7. Start your Wechaty Token Gate Server
After finish config all the above settings, start the token gate server with the following docker command:
docker run -ti \
--name wechaty_puppet_service_token_gateway \
--rm \
--privileged \
--network=host \
-e WECHATY_LOG \
-e WECHATY_PUPPET \
-e WECHATY_PUPPET_SERVER_PORT \
-e WECHATY_PUPPET_SERVICE_NO_TLS_INSECURE_SERVER \
-e WECHATY_TOKEN \
wechaty/wechaty
Privileged mode is for using host networking to simplify the docker arguments.
If you want to remove the --privileged
, you need to add:
-p $WECHATY_PUPPET_SERVER_PORT:$WECHATY_PUPPET_SERVER_PORT
for Linux & Mac-p %WECHATY_PUPPET_SERVER_PORT%:%WECHATY_PUPPET_SERVER_PORT%
for Windows
8. Check your TOKEN service
The docker command in the previous step might need some time to getting fully started.
Wait and read the docker container log messages carefully to make sure the server has been started before continue this step.
Check your TOKEN availability by visiting https://api.chatie.io/v0/hosties/${WECHATY_TOKEN}
- Linux
- macOS
- Windows
echo HTTP/$(curl -s -o /dev/null -w '%{http_code}' https://api.chatie.io/v0/hosties/${WECHATY_TOKEN})
echo HTTP/$(curl -s -o /dev/null -w '%{http_code}' https://api.chatie.io/v0/hosties/${WECHATY_TOKEN})
# echo HTTP/$(curl -s -o /dev/null -w '%{http_code}' https://api.chatie.io/v0/hosties/${WECHATY_TOKEN})
# TODO: add windows version. (Pull Request is welcome!)
- Succ:
HTTP/200
means you are good, the TOKEN is ready to use. - Fail:
HTTP/404
means the TOKEN is not registered successfully.
If you get HTTP/404
, then you need to check the previous steps and troubleshoot which part has problems. If you find anything need to be reported, please feel free to submit an issue at here
Using wechaty-token
CLI
You can use wechaty-token
CLI command to check the TOKEN status.
$ npm install --global wechaty-token
+ wechaty-token@0.4.3
updated 1 package in 2.654s
$ wechaty-token --help
wechaty-token <subcommand>
> Wechaty utility for discovering and generating tokens
where <subcommand> can be one of:
- generate - Generate a new Wechaty Token
- discover - Wechaty TOKEN Service Discovery
For more help, try running `wechaty-token <subcommand> --help`
$ wechaty-token discover puppet_not_exist_token
NotFound
$ wechaty-token discover ${WECHATY_TOKEN}
{ host: '1.2.3.4', port: 5678 }
Learn more about the TOKEN from Wechaty Puppet Service TOKEN Specification.
🎉 Congratulations! You are all set
Your Wechaty Puppet Service will be ready to service for Polyglot Wechaty!
All in One Command
For use Wechaty Token Gateway with ease, you can copy/paste the following code (with modifications for your need) in your bash shell:
- Linux
- macOS
- Windows
# Step 1
docker pull wechaty/wechaty
# Step 2
# here we are using wechaty-puppet-wechat for example
# replace it to fit your needs
export WECHATY_PUPPET=wechaty-puppet-wechat
# Step 3
export WECHATY_TOKEN=$(curl -s https://www.uuidgenerator.net/api/version4)
echo "WECHATY_TOKEN=$WECHATY_TOKEN"
# Step 4
export WECHATY_PUPPET_SERVER_PORT=8788
# Step 5
export WECHATY_LOG="verbose"
# Step 6
docker run \
-d \
-ti \
--name wechaty_puppet_service_token_gateway \
--rm \
--privileged \
--network=host \
-e WECHATY_LOG \
-e WECHATY_PUPPET \
-e WECHATY_PUPPET_SERVER_PORT \
-e WECHATY_TOKEN \
wechaty/wechaty
# Step 7
export HTTP_CODE=$(curl -s -o /dev/null -w '%{http_code}' https://api.chatie.io/v0/hosties/${WECHATY_TOKEN})
if [ "$HTTP_CODE" == 200 ]; then
echo "Wechaty Puppet Service TOKEN ${WECHATY_TOKEN} online status:"
curl https://api.chatie.io/v0/hosties/${WECHATY_TOKEN}
echo
else
>&2 echo "ERROR: Wechaty Puppet Service TOKEN ${WECHATY_TOKEN} out of service"
fi
# Step 8 🎉
# Step 1
docker pull wechaty/wechaty
# Step 2
# here we are using wechaty-puppet-wechat for example
# replace it to fit your needs
export WECHATY_PUPPET=wechaty-puppet-wechat
# Step 3
export WECHATY_TOKEN=$(curl -s https://www.uuidgenerator.net/api/version4)
echo "WECHATY_TOKEN=$WECHATY_TOKEN"
# Step 4
export WECHATY_PUPPET_SERVER_PORT=8788
# Step 5
export WECHATY_LOG="verbose"
# Step 6
docker run \
-d \
-ti \
--name wechaty_puppet_service_token_gateway \
--rm \
--privileged \
--network=host \
-e WECHATY_LOG \
-e WECHATY_PUPPET \
-e WECHATY_PUPPET_SERVER_PORT \
-e WECHATY_TOKEN \
wechaty/wechaty
# Step 7
export HTTP_CODE=$(curl -s -o /dev/null -w '%{http_code}' https://api.chatie.io/v0/hosties/${WECHATY_TOKEN})
if [ "$HTTP_CODE" == 200 ]; then
echo "Wechaty Puppet Service TOKEN ${WECHATY_TOKEN} online status:"
curl https://api.chatie.io/v0/hosties/${WECHATY_TOKEN}
echo
else
>&2 echo "ERROR: Wechaty Puppet Service TOKEN ${WECHATY_TOKEN} out of service"
fi
# Step 8 🎉
#
# Huan(202006): To be fixed for Win32
#
# Step 1
docker pull wechaty/wechaty
# Step 2
# here we are using wechaty-puppet-wechat for example
# replace it to fit your needs
set WECHATY_PUPPET=wechaty-puppet-wechat
# Step 3
set WECHATY_TOKEN=$(curl -s https://www.uuidgenerator.net/api/version4)
echo "WECHATY_TOKEN=%WECHATY_TOKEN%"
# Step 4
set WECHATY_PUPPET_SERVER_PORT=8788
# Step 5
set WECHATY_LOG="verbose"
# Step 6
docker run \
-d \
-ti \
--name wechaty_puppet_service_token_gateway \
--rm \
--privileged \
--network=host \
-e WECHATY_LOG \
-e WECHATY_PUPPET \
-e WECHATY_PUPPET_SERVER_PORT \
-e WECHATY_TOKEN \
wechaty/wechaty
# Step 7
set HTTP_CODE=$(curl -s -o /dev/null -w '%{http_code}' https://api.chatie.io/v0/hosties/${WECHATY_TOKEN})
if [ "$HTTP_CODE" == 200 ]; then
echo "Wechaty Puppet Service TOKEN ${WECHATY_TOKEN} online status:"
curl https://api.chatie.io/v0/hosties/${WECHATY_TOKEN}
echo
else
>&2 echo "ERROR: Wechaty Puppet Service TOKEN ${WECHATY_TOKEN} out of service"
fi
# Step 8 🎉
I hope you enjoy it!
Blogs
- Python Wechaty如何使用PadLocal Puppet Service, Biofer, Feb, 3, 2021
- .NET Wechaty如何使用PadLocal Puppet Service, Darren, Jan 28, 2021
History
- Using your Puppet PadLocal token with Python, Java, and Go Wechaty wechaty/wechaty#1985
- How to create your own Wechaty Puppet Service Token with the Web Protocol wechaty/wechaty#1986
- Using PadLocal Token with Polyglot Wechaty via Token Gateway wechaty/puppet-services#84
- Wechaty is All You Need: Python, Go, and Java Translation Project wechaty/wechaty#1927
Support
You can join our Gitter network if you aren’t already a member.