Skip to main content

Puppet Service: DIY

Wechaty Puppet Service DIY

Do It Yourself

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-padlocal by setting WECHATY_PUPPET=wechaty-puppet-padlocal, add an additional PadLocal token WECHATY_PUPPET_PADLOCAL_TOKEN=puppet_padlocal__TOKEN__ which is required by PadLocal.

Wechaty Puppet Providers

Learn all Wechaty Puppet Providers

You need to set all environment variables which requires from a specific provider.

export WECHATY_PUPPET="wechaty-puppet-padlocal"
export WECHATY_PUPPET_PADLOCAL_TOKEN="puppet_padlocal__TOKEN__"

3. Set 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.

TOKEN uniqueness

Your new token MUST different to any existing tokens in our system. (or they will conflict!)

export WECHATY_TOKEN=$(curl -s https://www.uuidgenerator.net/api/version4)
echo "WECHATY_TOKEN=$WECHATY_TOKEN"

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.

port availablility
  1. The server IP must be public on the internet
  2. the port must be public accessible on the internet
export WECHATY_PUPPET_SERVER_PORT="8788"

5. Set Wechaty Log Level#

Enable verbose log message output for easy debugging.

More options are:

  1. silly: all debug messages will be outputed
  2. verbose: recommended debug level
  3. info: disable debug messages
  4. warning: only warning message
  5. silence: no log message
export WECHATY_LOG="verbose"

6. 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_PADLOCAL_TOKEN \
-e WECHATY_PUPPET_SERVER_PORT \
-e WECHATY_TOKEN \
wechaty/wechaty
privileged mode

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

7. Check your TOKEN service#

wait for token gateway getting full started

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}

echo HTTP/$(curl -s -o /dev/null -w '%{http_code}' https://api.chatie.io/v0/hosties/${WECHATY_TOKEN})
  1. Succ: HTTP/200 means you are good, the TOKEN is ready to use.
  2. 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

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:

modify before use

We are using PadLocal as the example. Remember to modify WECHATY_PUPPET_PADLOCAL_TOKEN by replacing puppet_padlocal__TOKEN__ with yours.

# Step 1
docker pull wechaty/wechaty
# Step 2
# here we are using padlocal for example
# replace it to fit your needs
export WECHATY_PUPPET=wechaty-puppet-padlocal
export WECHATY_PUPPET_PADLOCAL_TOKEN=puppet_padlocal__TOKEN__
# 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_PADLOCAL_TOKEN \
-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 🎉

I hope you enjoy it!

Blogs#

History#

  1. Using your Puppet PadLocal token with Python, Java, and Go Wechaty wechaty/wechaty#1985
  2. How to create your own Wechaty Puppet Service Token with the Web Protocol wechaty/wechaty#1986
  3. Using PadLocal Token with Polyglot Wechaty via Token Gateway wechaty/puppet-services#84
  4. 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.

Last updated on by Souvik Biswas