mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 12:34:57 +00:00
refactor(line): share source info parsing
This commit is contained in:
@@ -20,6 +20,7 @@ import {
|
||||
} from "../pairing/pairing-store.js";
|
||||
import { firstDefined, isSenderAllowed, normalizeAllowFromWithStore } from "./bot-access.js";
|
||||
import {
|
||||
getLineSourceInfo,
|
||||
buildLineMessageContext,
|
||||
buildLinePostbackContext,
|
||||
type LineInboundContext,
|
||||
@@ -40,28 +41,6 @@ export interface LineHandlerContext {
|
||||
processMessage: (ctx: LineInboundContext) => Promise<void>;
|
||||
}
|
||||
|
||||
type LineSourceInfo = {
|
||||
userId?: string;
|
||||
groupId?: string;
|
||||
roomId?: string;
|
||||
isGroup: boolean;
|
||||
};
|
||||
|
||||
function getSourceInfo(source: EventSource): LineSourceInfo {
|
||||
const userId =
|
||||
source.type === "user"
|
||||
? source.userId
|
||||
: source.type === "group"
|
||||
? source.userId
|
||||
: source.type === "room"
|
||||
? source.userId
|
||||
: undefined;
|
||||
const groupId = source.type === "group" ? source.groupId : undefined;
|
||||
const roomId = source.type === "room" ? source.roomId : undefined;
|
||||
const isGroup = source.type === "group" || source.type === "room";
|
||||
return { userId, groupId, roomId, isGroup };
|
||||
}
|
||||
|
||||
function resolveLineGroupConfig(params: {
|
||||
config: ResolvedLineAccount["config"];
|
||||
groupId?: string;
|
||||
@@ -129,7 +108,7 @@ async function shouldProcessLineEvent(
|
||||
context: LineHandlerContext,
|
||||
): Promise<boolean> {
|
||||
const { cfg, account } = context;
|
||||
const { userId, groupId, roomId, isGroup } = getSourceInfo(event.source);
|
||||
const { userId, groupId, roomId, isGroup } = getLineSourceInfo(event.source);
|
||||
const senderId = userId ?? "";
|
||||
|
||||
const storeAllowFrom = await readChannelAllowFromStore("line").catch(() => []);
|
||||
|
||||
Reference in New Issue
Block a user