Skip to content

机器人无法接收数据 || Robot cannot receive data #225

@oiov

Description

@oiov

使用官方文档代码创建的机器人:

router.post("/callback", async (ctx) => {
  console.log(ctx);
  const type = ctx.body.type;
  ...
}

我增加了一行日志,在频道里@机器人成功触发了callback,日志:

Login...
Server is running on http://localhost:3030
tailchat openapp login success!
{
request: {
method: 'POST',
url: '/callback',
header: {
host: 'tailbot.vmail.dev:443',
'x-real-ip': 'x.x.x.x',
'x-forwarded-for': ''x.x.x.x',
'remote-host': ''x.x.x.x',
'x-host': 'tailbot.vmail.dev:443',
'x-scheme': 'https',
connection: 'upgrade',
'content-length': '461',
'user-agent': 'got (https://github.com/sindresorhus/got)',
'x-tc-payload-type': 'inbox',
'content-type': 'application/json',
'accept-encoding': 'gzip, deflate, br'
}
},
response: {
status: 404,
message: 'Not Found',
header: [Object: null prototype] {}
},
app: { subdomainOffset: 2, proxy: false, env: 'development' },
originalUrl: '/callback',
req: '<original node req>',
res: '<original node res>',
socket: '<original node socket>'
}

TypeError: Cannot read properties of undefined (reading 'type')
at /www/wwwroot/tailchat-bot/index.js:23:25
at dispatch (/www/wwwroot/tailchat-bot/node_modules/koa-compose/index.js:42:32)
at /www/wwwroot/tailchat-bot/node_modules/koa-router/lib/router.js:423:16
at dispatch (/www/wwwroot/tailchat-bot/node_modules/koa-compose/index.js:42:32)
at /www/wwwroot/tailchat-bot/node_modules/koa-compose/index.js:34:12
at dispatch (/www/wwwroot/tailchat-bot/node_modules/koa-router/lib/router.js:428:31)
at dispatch (/www/wwwroot/tailchat-bot/node_modules/koa-compose/index.js:42:32)
at /www/wwwroot/tailchat-bot/node_modules/koa-compose/index.js:34:12
at Application.handleRequest (/www/wwwroot/tailchat-bot/node_modules/koa/lib/application.js:186:12)
at Server.handleRequest (/www/wwwroot/tailchat-bot/node_modules/koa/lib/application.js:157:21)

补充:
发现请求体中没有数据所以拿不到。机器人的端口是 http://localhost:3030 我用 tailbot.vmail.dev 做了反代,在机器人的消息回调地址那里就填的是https://tailbot.vmail.dev/callback

但是我用tailchat-laf-robot可以正常拿到数据返回,host那些应该配置没问题,难道自部署是有什么差异吗?为什么ctx里没有payload?


Bot created using Official Documentation code:

router.post("/callback", async (ctx) => {
  console.log(ctx);
  const type = ctx.body.type;
  ...
}

I added a line of log. @Robot successfully triggered the callback in the channel. The log:

Login...
Server is running on http://localhost:3030
tailchat openapp login success!
{
request: {
method: 'POST',
url: '/callback',
header: {
host: 'tailbot.vmail.dev:443',
'x-real-ip': 'x.x.x.x',
'x-forwarded-for': ''x.x.x.x',
'remote-host': ''x.x.x.x',
'x-host': 'tailbot.vmail.dev:443',
'x-scheme': 'https',
connection: 'upgrade',
'content-length': '461',
'user-agent': 'got (https://github.com/sindresorhus/got)',
'x-tc-payload-type': 'inbox',
'content-type': 'application/json',
'accept-encoding': 'gzip, deflate, br'
}
},
response: {
status: 404,
message: 'Not Found',
header: [Object: null prototype] {}
},
app: { subdomainOffset: 2, proxy: false, env: 'development' },
originalUrl: '/callback',
req: '<original node req>',
res: '<original node res>',
socket: '<original node socket>'
}

TypeError: Cannot read properties of undefined (reading 'type')
at /www/wwwroot/tailchat-bot/index.js:23:25
at dispatch (/www/wwwroot/tailchat-bot/node_modules/koa-compose/index.js:42:32)
at /www/wwwroot/tailchat-bot/node_modules/koa-router/lib/router.js:423:16
at dispatch (/www/wwwroot/tailchat-bot/node_modules/koa-compose/index.js:42:32)
at /www/wwwroot/tailchat-bot/node_modules/koa-compose/index.js:34:12
at dispatch (/www/wwwroot/tailchat-bot/node_modules/koa-router/lib/router.js:428:31)
at dispatch (/www/wwwroot/tailchat-bot/node_modules/koa-compose/index.js:42:32)
at /www/wwwroot/tailchat-bot/node_modules/koa-compose/index.js:34:12
at Application.handleRequest (/www/wwwroot/tailchat-bot/node_modules/koa/lib/application.js:186:12)
at Server.handleRequest (/www/wwwroot/tailchat-bot/node_modules/koa/lib/application.js:157:21)

Replenish:
It was found that there was no data in the request body so it could not be obtained. The robot's port is http://localhost:3030. I used tailbot.vmail.dev for reverse generation. The message callback address of the robot is https://tailbot.vmail.dev/callback'. .

But I can use tailchat-laf-robot to get the data back normally. The host should be configured with no problem. Is it self-deployment? Is there any difference? Why is there no payload in ctx?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions