-
Notifications
You must be signed in to change notification settings - Fork 334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
机器人无法接收数据 || Robot cannot receive data #225
Comments
我也不知道为什么是404,这是我所有代码: const { TailchatHTTPClient, stripMentionTag } = require("tailchat-client-sdk");
const Koa = require("koa");
const Router = require("koa-router");
const app = new Koa();
const router = new Router();
const host = "https://im.vmail.dev";
const appId = "---";
const appSecret = "---";
const client = new TailchatHTTPClient(host, appId, appSecret);
// 定义路由
router.get("/", async (ctx) => {
ctx.body = "Hello, World!";
});
router.post("/callback", async (ctx) => {
console.log(ctx);
const type = ctx.body.type;
if (type === "message") {
const payload = ctx.body.payload;
try {
const message = await client.replyMessage(
{
messageId: payload.messageId,
author: payload.messageAuthor,
content: payload.messageSnippet,
},
{
groupId: payload.groupId,
converseId: payload.converseId,
content: `Your message: ${stripMentionTag(payload.messageSnippet)}`,
}
);
console.log("send message success:", message);
} catch (err) {
console.log("send message failed:", err);
}
}
ctx.body = "Bot Callback Page";
});
// 注册路由中间件
app.use(router.routes());
app.use(router.allowedMethods());
// 启动服务
app.listen(3030, () => {
console.log("Server is running on http://localhost:3030");
}); |
you can try to send a post request by yourself at first rather than tailchat. |
I send a post request to {
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': '0',
'user-agent': 'PostmanRuntime/7.38.0',
accept: '*/*',
'cache-control': 'no-cache',
'postman-token': 'fd4a2774-cea3-4053-bfcb-bb8b555d75fb',
'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>'
} |
looks like your node server not work correct. looks not tailchat's problem |
can you try to trigger request manual first? |
is your tailchat deploy in local? |
I deployed docker to my server. |
我遇到了和你一样的问题。问题的根本原因是Koa.js在解析JSON数据时需要一个中间件来处理请求体(body)的内容。如果你不能解决这个问题,我建议你使用Express框架。Express的旧版本与Koa.js有同样的问题,但是在最新的版本中,它们已经将解决方案内置了。因此,你可以非常容易地使用它,并且能够获取到机器人被@之后的信息。 I encountered the same issue as you. The root cause is that Koa.js requires a middleware to handle the body content when parsing JSON data. If you're unable to resolve this, I recommend using the Express framework. Older versions of Express had the same problem as Koa.js, but in the latest version, they have integrated the solution internally. Therefore, you can use it quite easily and obtain the information after the bot is @-mentioned. router.post("/bot/callback", async (req, res) => {
const type = req.body.type;
if (type === "message") {
const payload = req.body.payload;
try {
const message = await client.replyMessage(
{
messageId: payload.messageId,
author: payload.messageAuthor,
content: payload.messageSnippet,
},
{
groupId: payload.groupId,
converseId: payload.converseId,
content: `message on: ${stripMentionTag(payload.messageSnippet)}`,
}
);
console.log("message success:", message);
} catch (err) {
console.log("message fail:", err);
}
}
}); |
使用官方文档代码创建的机器人:
我增加了一行日志,在频道里@机器人成功触发了callback,日志:
补充:
发现请求体中没有数据所以拿不到。机器人的端口是
http://localhost:3030
我用tailbot.vmail.dev
做了反代,在机器人的消息回调地址那里就填的是https://tailbot.vmail.dev/callback
。但是我用tailchat-laf-robot可以正常拿到数据返回,host那些应该配置没问题,难道自部署是有什么差异吗?为什么ctx里没有payload?
Bot created using Official Documentation code:
I added a line of log. @Robot successfully triggered the callback in the channel. The log:
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 usedtailbot.vmail.dev
for reverse generation. The message callback address of the robot ishttps://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?
The text was updated successfully, but these errors were encountered: