msgbyte/tailchat

期望可以支持和机器人进行私信聊天 || Hopefully support private message chatting with robots

Closed this issue · 14 comments

image

添加的机器人,只能在群组中聊天,无法直接私聊

是否可以支持和机器人进行私信聊天,类似ChatGPT的问答界面


image

The added robot can only chat in the group and cannot directly chat privately.

Is it possible to support private message chatting with robots, similar to ChatGPT’s Q&A interface?

bot can send message using sendMessage api,but how does the bot get the message ?

you can checkout this document https://tailchat.msgbyte.com/blog/tailchat-laf-robot

i have developed some bots, but private message chatting with bots is not supported

image image

show your code

show your code

image

you can try chat with a bot and show the example.

this code is useless.

this just looks like a api which call by others.

you need provide more context than i can help you

or just create a webhook and receive all message post by tailchat.

this code is useless.

this just looks like a api which call by others.

you need provide more context than i can help you

image this is Callback Url of the bot,i don‘t understand what you means

bot receive message -> tailchat service will check bot config, if has set callback url, its will post a request to target service -> use your service to receive message

now you can get payload from http request which send from tailchat service. then you can study it if you wanna create a service which not provide sdk yet.

bot receive message -> tailchat service will check bot config, if has set callback url, its will post a request to target service -> use your service to receive message

now you can get payload from http request which send from tailchat service. then you can study it if you wanna create a service which not provide sdk yet.

The above process should be the process of message execution after a bot is @ in the group. Now this process can work.

I now find,
bot receives private messages -> even if the callback URL is configured, it will not send a request to the target service -> messages will not be received using your service.
Is it a configuration problem or is this the case now?

Oh i get it. because of bot callback service is based on inbox feature not message feature.(because message is a high frequency operation, add check will reduce performance of whole service.)

Bot should have own logic to make sure message payload should easy be detect. let me see.

Reference:

this.registerEventListener('chat.inbox.append', async (payload, ctx) => {
const userInfo = await call(ctx).getUserInfo(String(payload.userId));
if (!userInfo) {
return;
}
if (userInfo.type !== 'openapiBot') {
return;
}
// 开放平台机器人
const botId: string | null = await ctx.call('user.findOpenapiBotId', {
email: userInfo.email,
});
if (!(isValidStr(botId) && botId.startsWith('open_'))) {
return;
}
// 是合法的机器人id
const appId = botId.replace('open_', '');
const appInfo: OpenApp | null = await ctx.call('openapi.app.get', {
appId,
});
const callbackUrl = _.get(appInfo, 'bot.callbackUrl');
if (!isValidUrl(callbackUrl)) {
this.logger.info('机器人回调地址不是一个可用的url, skip.');
return;
}
got
.post(callbackUrl, { json: payload })
.then(() => {
this.logger.info('调用机器人通知接口回调成功');
})
.catch((err) => {
this.logger.error('调用机器人通知接口回调失败:', err);
});
});
this.registerAction('login', this.login, {
params: {
appId: 'string',
token: 'string',
},
});
this.registerAction('getOrCreateBotAccount', this.getOrCreateBotAccount, {
params: {
appId: 'string',
},
visibility: 'public',
});
this.registerAuthWhitelist(['/login']);
}

Oh i get it. because of bot callback service is based on inbox feature not message feature.(because message is a high frequency operation, add check will reduce performance of whole service.)

Bot should have own logic to make sure message payload should easy be detect. let me see.

Reference:

this.registerEventListener('chat.inbox.append', async (payload, ctx) => {
const userInfo = await call(ctx).getUserInfo(String(payload.userId));
if (!userInfo) {
return;
}
if (userInfo.type !== 'openapiBot') {
return;
}
// 开放平台机器人
const botId: string | null = await ctx.call('user.findOpenapiBotId', {
email: userInfo.email,
});
if (!(isValidStr(botId) && botId.startsWith('open_'))) {
return;
}
// 是合法的机器人id
const appId = botId.replace('open_', '');
const appInfo: OpenApp | null = await ctx.call('openapi.app.get', {
appId,
});
const callbackUrl = _.get(appInfo, 'bot.callbackUrl');
if (!isValidUrl(callbackUrl)) {
this.logger.info('机器人回调地址不是一个可用的url, skip.');
return;
}
got
.post(callbackUrl, { json: payload })
.then(() => {
this.logger.info('调用机器人通知接口回调成功');
})
.catch((err) => {
this.logger.error('调用机器人通知接口回调失败:', err);
});
});
this.registerAction('login', this.login, {
params: {
appId: 'string',
token: 'string',
},
});
this.registerAction('getOrCreateBotAccount', this.getOrCreateBotAccount, {
params: {
appId: 'string',
},
visibility: 'public',
});
this.registerAuthWhitelist(['/login']);
}

callback

Yes, that's right.

The bot callback service can be based on the message feature. Whether this feature will be supported in the future.

Discord supports private chatting with robots
image

Here is 2 way:

This is a great feature, looking forward to it