feat: 优化非法消息过滤逻辑,增加对私聊和艾特机器人的支持
This commit is contained in:
parent
68151bf1a1
commit
a415832851
@ -4,19 +4,15 @@ import groupAgent from "../../controller/groupAgent"
|
||||
import createKVTemp from "../../controller/sheet/createKVTemp"
|
||||
import soupAgent from "../../controller/soupAgent"
|
||||
import { Context } from "../../types"
|
||||
import { isNotP2POrAtBot } from "../../utils/message"
|
||||
import { isNotP2POrAtBot, isP2POrAtBot } from "../../utils/message"
|
||||
|
||||
/**
|
||||
* 过滤出非法消息,如果发表情包就直接发回去
|
||||
* @param {Context} ctx - 上下文数据,包含body, logger和larkService
|
||||
* @returns {boolean} 是否为非法消息
|
||||
*/
|
||||
const filterIllegalMsg = async ({
|
||||
body,
|
||||
logger,
|
||||
larkService,
|
||||
larkBody,
|
||||
}: Context): Promise<boolean> => {
|
||||
const filterIllegalMsg = async (ctx: Context): Promise<boolean> => {
|
||||
const { body, logger, larkService, larkBody } = ctx
|
||||
const { chatId, msgType, msgText } = larkBody
|
||||
// 没有chatId的消息不处理
|
||||
logger.info(`bot req chatId: ${chatId}`)
|
||||
@ -42,7 +38,7 @@ const filterIllegalMsg = async ({
|
||||
}
|
||||
|
||||
// 非表情包只在私聊或者群聊中艾特机器人时才回复
|
||||
else {
|
||||
else if (isP2POrAtBot(ctx)) {
|
||||
logger.info(`got a illegal message, chatId: ${chatId}`)
|
||||
larkService.message.sendText2Chat(
|
||||
chatId,
|
||||
|
4
test/chat/image.http
Normal file
4
test/chat/image.http
Normal file
@ -0,0 +1,4 @@
|
||||
POST http://localhost:3000/bot?app=egg HTTP/1.1
|
||||
content-type: application/json
|
||||
|
||||
{"schema":"2.0","header":{"event_id":"c7e0e9d2cd364accaeb59585376e64a2","token":"tV9djUKSjzVnekV7xTg2Od06NFTcsBnj","create_time":"1736850768816","event_type":"im.message.receive_v1","tenant_key":"2ee61fe50f4f1657","app_id":"cli_a1eff35b43b89063"},"event":{"message":{"chat_id":"oc_8c789ce8f4ecc6695bb63ca6ec4c61ea","chat_type":"group","content":"{\"image_key\":\"img_v3_02ih_df34945e-4e9c-4ec8-b380-a27aacc29e7l\"}","create_time":"1736850768656","message_id":"om_355702b6e5d794e35a48db68d020098e","message_type":"image","update_time":"1736850768656"},"sender":{"sender_id":{"open_id":"ou_470ac13b8b50fc472d9d8ee71e03de26","union_id":"on_9dacc59a539023df8b168492f5e5433c","user_id":"zhaoyingbo"},"sender_type":"user","tenant_key":"2ee61fe50f4f1657"}}}
|
Loading…
x
Reference in New Issue
Block a user