wechaty / matrix-appservice

Wechaty [Matrix] Application Services Bridge
https://matrix.org/docs/projects/bridge/matrix-appservice-wechaty
Apache License 2.0
132 stars 16 forks source link

How to use matrix-appservice-wechaty with wechaty-puppet-service #64

Closed yswtrue closed 3 years ago

yswtrue commented 3 years ago
version: '2'
services:
  matrix-appservice-wechaty:
      container_name: matrix-appservice-wechaty
      image: wechaty/matrix-appservice
      volumes:
        - ./config:/data
      networks:
        - default
      environment:
        - WECHATY_PUPPET_SERVICE_TOKEN=puppet_34e2b701-a21a-4f12-8f5a-90b1331bbe8f
        - WECHATY_PUPPET_SERVICE_ENDPOINT=114.215.83.32:7777
        - WECHATY_PUPPET=wechaty-puppet-service
#        - WECHATY_PUPPET_PADPLUS_TOKEN=fa9f6ebaf1ad0a0eff7f4fbec327905a
#        - WECHATY_PUPPET_HOSTIE_ENDPOINT=45.32.57.135:7777
#        - WECHATY_PUPPET=wechaty-puppet-padplus
#        - WECHATY_PUPPET=wechaty-puppet-puppeteer
        - WECHATY_LOG=silly
      command: ["--config", "/data/wechaty-config.yaml", "--file", "/data/wechaty-registration.yaml"]
      ports:
        - 8788:8788

this is my docker-compose.yml file.

and matrix connects to matrix-appservice-wechaty successfully. But matrix-appservice-wechaty get UNAUTHENTICATED error

matrix-appservice-wechaty    | 19:29:12 ERR PuppetService start() rejection: 16 UNAUTHENTICATED: {code:8,message:"A token(puppet_34e2b701-a21a-4f12-8f5a-90b1331bbe8f) must be prefixed with a 'puppet_' "}
matrix-appservice-wechaty    | Error: 16 UNAUTHENTICATED: {code:8,message:"A token(puppet_34e2b701-a21a-4f12-8f5a-90b1331bbe8f) must be prefixed with a 'puppet_' "}
matrix-appservice-wechaty    |     at Object.exports.createStatusError (/matrix-appservice-wechaty/node_modules/grpc/src/common.js:91:15)
matrix-appservice-wechaty    |     at Object.onReceiveStatus (/matrix-appservice-wechaty/node_modules/grpc/src/client_interceptors.js:1209:28)
matrix-appservice-wechaty    |     at InterceptingListener._callNext (/matrix-appservice-wechaty/node_modules/grpc/src/client_interceptors.js:568:42)
matrix-appservice-wechaty    |     at InterceptingListener.onReceiveStatus (/matrix-appservice-wechaty/node_modules/grpc/src/client_interceptors.js:618:8)
matrix-appservice-wechaty    |     at callback (/matrix-appservice-wechaty/node_modules/grpc/src/client_interceptors.js:847:24) {
matrix-appservice-wechaty    |   code: 16,
matrix-appservice-wechaty    |   metadata: Metadata { _internal_repr: {}, flags: 0 },
matrix-appservice-wechaty    |   details: `{code:8,message:"A token(puppet_34e2b701-a21a-4f12-8f5a-90b1331bbe8f) must be prefixed with a 'puppet_' "}`
matrix-appservice-wechaty    | }
matrix-appservice-wechaty    | 19:29:12 ERR Wechaty start() exception: 16 UNAUTHENTICATED: {code:8,message:"A token(puppet_34e2b701-a21a-4f12-8f5a-90b1331bbe8f) must be prefixed with a 'puppet_' "}
matrix-appservice-wechaty    | 19:29:12 ERR Config ###########################
matrix-appservice-wechaty    | 19:29:12 ERR Config unhandledRejection: Error: 16 UNAUTHENTICATED: {code:8,message:"A token(puppet_34e2b701-a21a-4f12-8f5a-90b1331bbe8f) must be prefixed with a 'puppet_' "}
matrix-appservice-wechaty    |     at Object.exports.createStatusError (/matrix-appservice-wechaty/node_modules/grpc/src/common.js:91:15)
matrix-appservice-wechaty    |     at Object.onReceiveStatus (/matrix-appservice-wechaty/node_modules/grpc/src/client_interceptors.js:1209:28)
matrix-appservice-wechaty    |     at InterceptingListener._callNext (/matrix-appservice-wechaty/node_modules/grpc/src/client_interceptors.js:568:42)
matrix-appservice-wechaty    |     at InterceptingListener.onReceiveStatus (/matrix-appservice-wechaty/node_modules/grpc/src/client_interceptors.js:618:8)
matrix-appservice-wechaty    |     at callback (/matrix-appservice-wechaty/node_modules/grpc/src/client_interceptors.js:847:24) [object Promise]
matrix-appservice-wechaty    | 19:29:12 ERR Config ###########################
matrix-appservice-wechaty    | 19:29:12 ERR Config process.on(unhandledRejection) promise.catch(16 UNAUTHENTICATED: {code:8,message:"A token(puppet_34e2b701-a21a-4f12-8f5a-90b1331bbe8f) must be prefixed with a 'puppet_' "})
matrix-appservice-wechaty    | Config Error: 16 UNAUTHENTICATED: {code:8,message:"A token(puppet_34e2b701-a21a-4f12-8f5a-90b1331bbe8f) must be prefixed with a 'puppet_' "}
matrix-appservice-wechaty    |     at Object.exports.createStatusError (/matrix-appservice-wechaty/node_modules/grpc/src/common.js:91:15)
matrix-appservice-wechaty    |     at Object.onReceiveStatus (/matrix-appservice-wechaty/node_modules/grpc/src/client_interceptors.js:1209:28)
matrix-appservice-wechaty    |     at InterceptingListener._callNext (/matrix-appservice-wechaty/node_modules/grpc/src/client_interceptors.js:568:42)
matrix-appservice-wechaty    |     at InterceptingListener.onReceiveStatus (/matrix-appservice-wechaty/node_modules/grpc/src/client_interceptors.js:618:8)
matrix-appservice-wechaty    |     at callback (/matrix-appservice-wechaty/node_modules/grpc/src/client_interceptors.js:847:24) {
matrix-appservice-wechaty    |   code: 16,
matrix-appservice-wechaty    |   metadata: Metadata { _internal_repr: {}, flags: 0 },
matrix-appservice-wechaty    |   details: `{code:8,message:"A token(puppet_34e2b701-a21a-4f12-8f5a-90b1331bbe8f) must be prefixed with a 'puppet_' "}`
matrix-appservice-wechaty    | }
matrix-appservice-wechaty    | (node:7) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 1)
matrix-appservice-wechaty    | 19:29:12 WARN matrix-appservice-wechaty process.on(warning)
matrix-appservice-wechaty    | PromiseRejectionHandledWarning
matrix-appservice-wechaty    | Promise rejection was handled asynchronously (rejection id: 1)
matrix-appservice-wechaty    | PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 1)
matrix-appservice-wechaty    |     at handledRejection (internal/process/promises.js:121:23)
matrix-appservice-wechaty    |     at promiseRejectHandler (internal/process/promises.js:83:7)
matrix-appservice-wechaty    |     at Promise.then (<anonymous>)
matrix-appservice-wechaty    |     at Promise.catch (<anonymous>)
matrix-appservice-wechaty    |     at process.<anonymous> (/matrix-appservice-wechaty/node_modules/wechaty/dist/src/config.js:81:22)
matrix-appservice-wechaty    |     at process.emit (events.js:314:20)
matrix-appservice-wechaty    |     at process.EventEmitter.emit (domain.js:483:12)
matrix-appservice-wechaty    |     at processPromiseRejections (internal/process/promises.js:209:33)
matrix-appservice-wechaty    |     at processTicksAndRejections (internal/process/task_queues.js:98:32)
matrix-appservice-wechaty    | 19:29:12 SILL StateSwitch <PuppetService> off() is false
matrix-appservice-wechaty    | 19:29:12 VERB StateSwitch <PuppetService> off(true) <- (false)
matrix-appservice-wechaty    | 19:29:12 VERB PuppetService startGrpcStream() eventStream.on(error) Error: 16 UNAUTHENTICATED: {code:8,message:"A token(puppet_34e2b701-a21a-4f12-8f5a-90b1331bbe8f) must be prefixed with a 'puppet_' "}
matrix-appservice-wechaty    | 19:29:12 SILL Puppet throttleReset() payload: "{"data":"startGrpcStream() eventStream.on(error) Error: 16 UNAUTHENTICATED: {code:8,message:\"A token(puppet_34e2b701-a21a-4f12-8f5a-90b1331bbe8f) must be prefixed with a 'puppet_' \"}"}"
matrix-appservice-wechaty    | 19:29:12 SILL Puppet constructor() resetThrottleQueue.subscribe() reason: "startGrpcStream() eventStream.on(error) Error: 16 UNAUTHENTICATED: {code:8,message:"A token(puppet_34e2b701-a21a-4f12-8f5a-90b1331bbe8f) must be prefixed with a 'puppet_' "}"
matrix-appservice-wechaty    | 19:29:12 VERB Puppet reset(startGrpcStream() eventStream.on(error) Error: 16 UNAUTHENTICATED: {code:8,message:"A token(puppet_34e2b701-a21a-4f12-8f5a-90b1331bbe8f) must be prefixed with a 'puppet_' "})
matrix-appservice-wechaty    | 19:29:12 VERB PuppetService stop()
matrix-appservice-wechaty    | 19:29:12 SILL StateSwitch <PuppetService> off() is true
matrix-appservice-wechaty    | 19:29:12 VERB StateSwitch <PuppetService> ready(off, false)
matrix-appservice-wechaty    | 19:29:12 WARN PuppetService stop() is called on a OFF puppet. await ready(off) and return.
matrix-appservice-wechaty    | 19:29:12 SILL StateSwitch <PuppetService> ready(off, false) resolved.
matrix-appservice-wechaty    | 19:29:12 VERB PuppetService start()
matrix-appservice-wechaty    | 19:29:12 SILL StateSwitch <PuppetService> on() is false
matrix-appservice-wechaty    | 19:29:12 SILL StateSwitch <PuppetService> on() is false
matrix-appservice-wechaty    | 19:29:12 VERB StateSwitch <PuppetService> on(pending) <- (false)
matrix-appservice-wechaty    | 19:29:12 VERB PuppetService startGrpcClient()
matrix-appservice-wechaty    | 19:29:12 VERB PuppetService startGrpcStream()
matrix-appservice-wechaty    | 19:29:12 SILL StateSwitch <PuppetService> off() is false
matrix-appservice-wechaty    | 19:29:12 VERB StateSwitch <PuppetService> off(true) <- (false)
matrix-appservice-wechaty    | 19:29:12 ERR PuppetService start() rejection: event stream exists
matrix-appservice-wechaty    | 19:29:12 WARN Puppet reset() exception: Error: event stream exists
matrix-appservice-wechaty    | 19:29:12 ERR Config ###########################
matrix-appservice-wechaty    | 19:29:12 ERR Config unhandledRejection: Error
matrix-appservice-wechaty    |     at PuppetService.<anonymous> (/matrix-appservice-wechaty/node_modules/wechaty/dist/src/wechaty.js:271:44)
matrix-appservice-wechaty    |     at PuppetService.emit (events.js:314:20)
matrix-appservice-wechaty    |     at PuppetService.EventEmitter.emit (domain.js:483:12)
matrix-appservice-wechaty    |     at /matrix-appservice-wechaty/node_modules/wechaty-puppet/dist/src/puppet.js:230:18
matrix-appservice-wechaty    |     at processTicksAndRejections (internal/process/task_queues.js:97:5) [object Promise]
matrix-appservice-wechaty    | 19:29:12 ERR Config ###########################
matrix-appservice-wechaty    | 19:29:12 ERR Config process.on(unhandledRejection) promise.catch()
matrix-appservice-wechaty    | Config Error
matrix-appservice-wechaty    |     at PuppetService.<anonymous> (/matrix-appservice-wechaty/node_modules/wechaty/dist/src/wechaty.js:271:44)
matrix-appservice-wechaty    |     at PuppetService.emit (events.js:314:20)
matrix-appservice-wechaty    |     at PuppetService.EventEmitter.emit (domain.js:483:12)
matrix-appservice-wechaty    |     at /matrix-appservice-wechaty/node_modules/wechaty-puppet/dist/src/puppet.js:230:18
matrix-appservice-wechaty    |     at processTicksAndRejections (internal/process/task_queues.js:97:5)
matrix-appservice-wechaty    | (node:7) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 3)
matrix-appservice-wechaty    | 19:29:12 WARN matrix-appservice-wechaty process.on(warning)
matrix-appservice-wechaty    | PromiseRejectionHandledWarning
matrix-appservice-wechaty    | Promise rejection was handled asynchronously (rejection id: 3)
matrix-appservice-wechaty    | PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 3)
matrix-appservice-wechaty    |     at handledRejection (internal/process/promises.js:121:23)
matrix-appservice-wechaty    |     at promiseRejectHandler (internal/process/promises.js:83:7)
matrix-appservice-wechaty    |     at Promise.then (<anonymous>)
matrix-appservice-wechaty    |     at Promise.catch (<anonymous>)
matrix-appservice-wechaty    |     at process.<anonymous> (/matrix-appservice-wechaty/node_modules/wechaty/dist/src/config.js:81:22)
matrix-appservice-wechaty    |     at process.emit (events.js:314:20)
matrix-appservice-wechaty    |     at process.EventEmitter.emit (domain.js:483:12)
matrix-appservice-wechaty    |     at processPromiseRejections (internal/process/promises.js:209:33)
matrix-appservice-wechaty    |     at processTicksAndRejections (internal/process/task_queues.js:98:32)

when I delete WECHATY_PUPPET_SERVICE_ENDPOINT environment, I get these errors.

matrix-appservice-wechaty    | 19:31:31 VERB PuppetService discoverServiceIp(puppet_34e2b701-a21a-4f12-8f5a-90b1331bbe8f)
matrix-appservice-wechaty    | 19:31:32 WARN No endpoint when starting grpc client, 10 retry left. Reconnecting in 10 seconds...
matrix-appservice-wechaty    | 19:31:42 VERB PuppetService discoverServiceIp(puppet_34e2b701-a21a-4f12-8f5a-90b1331bbe8f)
matrix-appservice-wechaty    | 19:31:42 WARN No endpoint when starting grpc client, 9 retry left. Reconnecting in 10 seconds...
......
huan commented 3 years ago

matrix-appservice-wechaty | 19:29:12 ERR PuppetService start() rejection: 16 UNAUTHENTICATED: {code:8,message:"A token(puppet34e2b701-a21a-4f12-8f5a-90b1331bbe8f) must be prefixed with a 'puppet' "}

The above error message looks wired.

Cloud you please tell me that where did you get this token puppet_34e2b701-a21a-4f12-8f5a-90b1331bbe8f?

yswtrue commented 3 years ago

I followed this one. https://github.com/wechaty/wechaty/discussions/1986

huan commented 3 years ago

It seems you should not get this error message. I'll try this tomorrow.

Could you please try your token with a Wechaty bot to see if it can work without the matrix?

yswtrue commented 3 years ago

Same error when use get started example.

I ran the below commands.

export WECHATY_PUPPET_SERVICE_TOKEN=puppet_34e2b701-a21a-4f12-8f5a-90b1331bbe8f
export WECHATY_PUPPET=wechaty-puppet-service
export WECHATY_PUPPET_SERVICE_ENDPOINT=114.215.83.32:7777
export WECHATY_PUPPET=wechaty-puppet-service
./bin/docker-run-javascript-es6.sh

and get these outputs.

+ set -e
+ BOT=src/javascript-es6.js
++ dirname bin/docker-run.sh
+ source bin/docker-config.sh
++ WECHATY_IMAGE=wechaty/wechaty
+++ env
+++ grep WECHATY_
++ docker::env WECHATY_PUPPET_SERVICE_ENDPOINT=114.215.83.32:7777 WECHATY_PUPPET=wechaty-puppet-service WECHATY_PUPPET_SERVICE_TOKEN=puppet_34e2b701-a21a-4f12-8f5a-90b1331bbe8f
++ for var in '"$@"'
++ echo -n ' -e WECHATY_PUPPET_SERVICE_ENDPOINT=114.215.83.32:7777'
++ for var in '"$@"'
++ echo -n ' -e WECHATY_PUPPET=wechaty-puppet-service'
++ for var in '"$@"'
++ echo -n ' -e WECHATY_PUPPET_SERVICE_TOKEN=puppet_34e2b701-a21a-4f12-8f5a-90b1331bbe8f'
+ DOCKER_ENV=' -e WECHATY_PUPPET_SERVICE_ENDPOINT=114.215.83.32:7777 -e WECHATY_PUPPET=wechaty-puppet-service -e WECHATY_PUPPET_SERVICE_TOKEN=puppet_34e2b701-a21a-4f12-8f5a-90b1331bbe8f'
+ '[' -z '' ']'
+ docker pull wechaty/wechaty
Using default tag: latest
latest: Pulling from wechaty/wechaty
Digest: sha256:b56d3dc531b4ba95bcb46f2f721347007b5c67fd6f6778fbdf7af242e2c2d189
Status: Image is up to date for wechaty/wechaty:latest
docker.io/wechaty/wechaty:latest
++ pwd
+ docker run -t -i --rm --name wechaty --mount type=bind,source=/root/docker-wechaty-getting-started,target=/bot -e WECHATY_PUPPET_SERVICE_ENDPOINT=114.215.83.32:7777 -e WECHATY_PUPPET=wechaty-puppet-service -e WECHATY_PUPPET_SERVICE_TOKEN=puppet_34e2b701-a21a-4f12-8f5a-90b1331bbe8f wechaty/wechaty src/javascript-es6.js

 __        __        _           _
 \ \      / /__  ___| |__   __ _| |_ _   _
  \ \ /\ / / _ \/ __| '_ \ / _` | __| | | |
   \ V  V /  __/ (__| | | | (_| | |_| |_| |
    \_/\_/ \___|\___|_| |_|\__,_|\__|\__, |
                                     |___/
____________________________________________________
            https://www.chatie.io
  ____                            _   _
 / ___|___  _ __  _ __   ___  ___| |_(_)_ __   __ _
| |   / _ \| '_ \| '_ \ / _ \/ __| __| | '_ \ / _` |
| |__| (_) | | | | | | |  __/ (__| |_| | | | | (_| |
 \____\___/|_| |_|_| |_|\___|\___|\__|_|_| |_|\__, |
                                              |___/
  ____ _           _   ____        _
 / ___| |__   __ _| |_| __ )  ___ | |_ ___
| |   | '_ \ / _` | __|  _ \ / _ \| __/ __|
| |___| | | | (_| | |_| |_) | (_) | |_\__ \
 \____|_| |_|\__,_|\__|____/ \___/ \__|___/

WECHATY Environment Variables: 4
WECHATY_PUPPET_SERVICE_TOKEN=puppet_34e2b701-a21a-4f12-8f5a-90b1331bbe8f
WECHATY_DOCKER=1
WECHATY_PUPPET_SERVICE_ENDPOINT=114.215.83.32:7777
WECHATY_PUPPET=wechaty-puppet-service

Starting Docker Container for Wechaty v0.56.3 with Node.js v12.20.1 ...
Working directory: /bot
Executing babel-node --presets @babel/env src/javascript-es6.js
03:17:51 ERR PuppetService start() rejection: 16 UNAUTHENTICATED: {code:8,message:"A token(puppet_34e2b701-a21a-4f12-8f5a-90b1331bbe8f) must be prefixed with a 'puppet_' "}
Error: 16 UNAUTHENTICATED: {code:8,message:"A token(puppet_34e2b701-a21a-4f12-8f5a-90b1331bbe8f) must be prefixed with a 'puppet_' "}
    at Object.exports.createStatusError (/wechaty/node_modules/grpc/src/common.js:91:15)
    at Object.onReceiveStatus (/wechaty/node_modules/grpc/src/client_interceptors.js:1209:28)
    at InterceptingListener._callNext (/wechaty/node_modules/grpc/src/client_interceptors.js:568:42)
    at InterceptingListener.onReceiveStatus (/wechaty/node_modules/grpc/src/client_interceptors.js:618:8)
    at callback (/wechaty/node_modules/grpc/src/client_interceptors.js:847:24) {
  code: 16,
  metadata: Metadata { _internal_repr: {}, flags: 0 },
  details: `{code:8,message:"A token(puppet_34e2b701-a21a-4f12-8f5a-90b1331bbe8f) must be prefixed with a 'puppet_' "}`
}
03:17:51 ERR Wechaty start() exception: 16 UNAUTHENTICATED: {code:8,message:"A token(puppet_34e2b701-a21a-4f12-8f5a-90b1331bbe8f) must be prefixed with a 'puppet_' "}
Bot error: Error: 16 UNAUTHENTICATED: {code:8,message:"A token(puppet_34e2b701-a21a-4f12-8f5a-90b1331bbe8f) must be prefixed with a 'puppet_' "}
    at Object.exports.createStatusError (/wechaty/node_modules/grpc/src/common.js:91:15)
    at Object.onReceiveStatus (/wechaty/node_modules/grpc/src/client_interceptors.js:1209:28)
    at InterceptingListener._callNext (/wechaty/node_modules/grpc/src/client_interceptors.js:568:42)
    at InterceptingListener.onReceiveStatus (/wechaty/node_modules/grpc/src/client_interceptors.js:618:8)
    at callback (/wechaty/node_modules/grpc/src/client_interceptors.js:847:24) {
  code: 16,
  metadata: Metadata { _internal_repr: {}, flags: 0 },
  details: `{code:8,message:"A token(puppet_34e2b701-a21a-4f12-8f5a-90b1331bbe8f) must be prefixed with a 'puppet_' "}`
}
03:17:51 WARN PuppetService stop() is called on a OFF puppet. await ready(off) and return.

 __        __        _           _
 \ \      / /__  ___| |__   __ _| |_ _   _
  \ \ /\ / / _ \/ __| '_ \ / _` | __| | | |
   \ V  V /  __/ (__| | | | (_| | |_| |_| |
    \_/\_/ \___|\___|_| |_|\__,_|\__|\__, |
                                     |___/
____________________________________________________
            https://www.chatie.io
  _____      _ _      ___
 | ____|_  _(_) |_   / _ \
 |  _| \ \/ / | __| | | | |
 | |___ >  <| | |_  | |_| |
 |_____/_/\_\_|\__|  \___/
yswtrue commented 3 years ago

This is my wechaty gateway. image

huan commented 3 years ago

It would be better if we can post text instead of a screenshot image because text is copyable and searchable.

First, It seems that you are run into https://github.com/wechaty/wechaty/discussions/1985#discussioncomment-316928 : WECHATY_TOKEN should not equal to WECHATY_PUPPET_PADLOCAL_TOKEN

Second, in order to provider a Wechaty puppet service, you must have a workable Wechaty puppet provider, like PadLocal, or Donut.

Which means you have to set the environment variable WECHATY_PUPPET correctly.

Please read the issue I posted above, and learn more from https://wechaty.js.org/2021/01/28/csharp-wechaty-for-padlocal-puppet-service/

yswtrue commented 3 years ago

Thank you. It works now.

huan commented 3 years ago

Congratulations!

It's great to know that you have made matrix-appservice-wechaty works for you!

Would you like to write a blog post for sharing your experiences about how to set up this appservice with Wechaty and Matrix, so that other developers who want to do the same setup could be benefited from your post? Because this project is new, and it has very limited documentation for this topic, so there will be very valuable for creating this article and sharing to the community!

yswtrue commented 3 years ago

Ok, I will write a blog post when I have time.

huan commented 3 years ago

Thank you very much, appreciate it!