Anillc / koishi-plugin-adapter-matrix

Matrix adapter for koishi
MIT License
5 stars 0 forks source link

Bug:启动后报错 #2

Closed yunkuangao closed 1 year ago

yunkuangao commented 1 year ago

期望发生什么?

适配器正常工作

发生了什么?

适配器无法工作,后台报错

matrix failed to initialize AxiosError: Request failed with status code 403 at settle (/koishi/node_modules/cordis-axios/node_modules/axios/dist/node/axios.cjs:1268:12) at BrotliDecompress.handleStreamEnd (/koishi/node_modules/cordis-axios/node_modules/axios/dist/node/axios.cjs:2446:11) at BrotliDecompress.emit (node:events:525:35) at endReadableNT (node:internal/streams/readable:1359:12) at process.processTicksAndRejections (node:internal/process/task_queues:82:21) { code: 'ERR_BAD_REQUEST', config: { transitional: { silentJSONParsing: true, forcedJSONParsing: true, clarifyTimeoutError: false }, adapter: [Function: httpAdapter], transformRequest: [ [Function: transformRequest] ], transformResponse: [ [Function: transformResponse] ], timeout: 0, xsrfCookieName: ...

使用版本?

OS: Docker image: koishijs/koishi:v1.6.5 Synapse: Docker image: docker.io/matrixdotorg/synapse plugin: 3.0.0

Anillc commented 1 year ago

麻烦贴一下配置文件,包括 matrix 侧的 registry.yaml 和 koishi 的配置文件

yunkuangao commented 1 year ago

好的

koishi plugin: image

registray.yaml: image

yunkuangao commented 1 year ago

之前我koishi的id用的application service id,报的是403,后面我换成sender_localpart,报的就是500了

错误如下: matrix failed to initialize AxiosError: Request failed with status code 500 at settle (/koishi/node_modules/cordis-axios/node_modules/axios/dist/node/axios.cjs:1268:12) at IncomingMessage.handleStreamEnd (/koishi/node_modules/cordis-axios/node_modules/axios/dist/node/axios.cjs:2446:11) at IncomingMessage.emit (node:events:525:35) at endReadableNT (node:internal/streams/readable:1359:12) at process.processTicksAndRejections (node:internal/process/task_queues:82:21) { code: 'ERR_BAD_RESPONSE', config: { transitional: { silentJSONParsing: true, forcedJSONParsing: true, clarifyTimeoutError: false }, adapter: [Function: httpAdapter], transformRequest: [ [Function: transformRequest] ], transformResponse: [ [Function: transformResponse] ], timeout: 5000, xsrfCookieName...

Anillc commented 1 year ago

403 我怀疑是你的两个 token 配置有问题,我晚上有空的话再测一下,理论上这个适配器应该没有坏

yunkuangao commented 1 year ago

抱歉没有说清楚,403是我用application service id当作koishi里面的id的时候报的 后面我用sender_localpart当作koishi的id的时候就是500 如果我没猜错的话,koishi里面的id应该是对应synapse里面的sender_localpart对吧?

Anillc commented 1 year ago

如果我没猜错的话,koishi里面的id应该是对应synapse里面的sender_localpart对吧?

并不是,sender_localpart 与 matrix adapter 的 id 不应该相等,因为 matrix 会给 application service 分配一个账号,但是 matrix 会为机器人创建账号,如果 id 重复了就会报错。

这样做的目的是为了让同一个 application service 可以有多个 bot 账号。

403是我用application service id当作koishi里面的id的时候报的

application service id 跟 sender_localpart 和 matrix adapter 中的 id 应该是没有关系的才对。403 报错一般是鉴权的问题,所以我前面怀疑你的 token 配置有问题。

yunkuangao commented 1 year ago

OK,现在能登录上了,但是有新的问题。

在koishi的console界面还是处于连接状态,但是在element这边就已经是离线状态了,而且对于邀请进入房间也都没有任何反应,verifier已经安装且配置为全部通过: image

element界面: image

Anillc commented 1 year ago

日志里有没有报错呢

yunkuangao commented 1 year ago

日志里面没有报错,这就是最诡异的一点了。

Snipaste_2023-03-30_09-23-54
Anillc commented 1 year ago

测试了一下,matrix adapter 是有在正常工作的。你到 synapse 那里看下日志(可以用 grep 过滤一下你的 application service id),看看是不是 synapse 到你的机器人的请求失败了。

另外 synapse 不支持 301 这类跳转,如果到你机器人的 http 接口 (PUT /transactions/123) 会返回 301 的话将会失败,请注意一下

yunkuangao commented 1 year ago

抱歉,周末两天有点事情。 我看了下synapse日志,发现有个错误

synapse | 2023-04-03 09:52:32,184 - synapse.http.server - 107 - INFO - POST-122 - <XForwardedForRequest at 0x7f61b41bff10 method='POST' uri='/_matrix/client/v3/register' clientproto='HTTP/1.1' site='8008'> SynapseError: 400 - Invalid user localpart for this application service. synapse | 2023-04-03 09:52:32,185 - synapse.access.http.8008 - 460 - INFO - POST-122 - 172.71.147.166 - 8008 - {None} Processed request: 0.002sec/0.000sec (0.002sec, 0.000sec) (0.000sec/0.000sec/0) 88B 400 "POST /_matrix/client/v3/register HTTP/1.1" "axios/1.1.3" [0 dbevts] synapse | 2023-04-03 09:52:32,222 - synapse.rest.client.login - 256 - INFO - POST-123 - Got appservice login request with identifier: {'type': 'm.id.user', 'user': 'bot111'} synapse | 2023-04-03 09:52:32,222 - synapse.http.server - 107 - INFO - POST-123 - <XForwardedForRequest at 0x7f61b41bf450 method='POST' uri='/_matrix/client/v3/login' clientproto='HTTP/1.1' site='8008'> SynapseError: 403 - Invalid access_token synapse | 2023-04-03 09:52:32,225 - synapse.access.http.8008 - 460 - INFO - POST-123 - 172.71.151.42 - 8008 - {@hello:im.yka.moe} Processed request: 0.001sec/0.002sec (0.001sec, 0.000sec) (0.000sec/0.000sec/0) 56B 403 "POST /_matrix/client/v3/login HTTP/1.1" "axios/1.1.3" [0 dbevts]

但是这个sender_localpart要怎么改才正确呢,我试过和application service id 一样以及不一样,都会有这个错误 另外关于网络问题,我没有301跳转,但是有一层代理,用的cloudflare cdn和traefik,docker compose配置如下:

version: '3'
services:
  synapse:
    image: docker.io/matrixdotorg/synapse
    container_name: synapse
    restart: always
    environment:
      - SYNAPSE_CONFIG_PATH=/data/homeserver.yaml
      - TZ=Asia/Shanghai
    volumes:
      - $PWD/files:/data
    labels:
      - traefik.http.routers.synapse.rule=Host(`im.yka.moe`)
      - traefik.http.routers.synapse.entrypoints=https
      - traefik.http.routers.synapse.tls.certresolver=letsencrypt
      - traefik.http.services.synapse.loadbalancer.server.port=8008
    networks:
      - traefik
networks:
  traefik:
    external: true
yunkuangao commented 1 year ago

我修改了一下配置之后好像可以了,我也不知道为啥。感谢作者的帮助。

留个配置以供后来人参考: registry.yaml

id: "koishi"
hs_token: "hs_token"
as_token: "as_token"
url: "https://example.org"
sender_localpart: "koishibot"
namespaces:
  users:
    - exclusive: true
      regex: "@bot:example.org"
  rooms: []