11/** Command authorization helpers for owner and allowlist checks. */
22import {
3- normalizeLowercaseStringOrEmpty ,
43 normalizeOptionalLowercaseString ,
54 normalizeOptionalString ,
65} from "@openclaw/normalization-core/string-coerce" ;
@@ -19,6 +18,7 @@ import {
1918 normalizeMessageChannel ,
2019} from "../utils/message-channel.js" ;
2120import { isNativeCommandTurn , resolveCommandTurnContext } from "./command-turn-context.js" ;
21+ import { shouldUseFromAsSenderFallback } from "./sender-identity.js" ;
2222import type { MsgContext } from "./templating.js" ;
2323
2424export type CommandAuthorization = {
@@ -461,32 +461,6 @@ function resolveCommandSenderAuthorization(params: {
461461 return params . commandAuthorized && ( params . isOwnerForCommands || params . nativeCommandAuthorized ) ;
462462}
463463
464- function isConversationLikeIdentity ( value : string ) : boolean {
465- const normalized = normalizeOptionalLowercaseString ( value ) ;
466- if ( ! normalized ) {
467- return false ;
468- }
469- if ( normalized . startsWith ( "chat_id:" ) ) {
470- return true ;
471- }
472- return / ( ^ | : ) ( c h a n n e l | g r o u p | t h r e a d | t o p i c | r o o m | s p a c e | s p a c e s ) : / . test ( normalized ) ;
473- }
474-
475- function shouldUseFromAsSenderFallback ( params : {
476- from ?: string | null ;
477- chatType ?: string | null ;
478- } ) : boolean {
479- const from = normalizeOptionalString ( params . from ) ?? "" ;
480- if ( ! from ) {
481- return false ;
482- }
483- const chatType = normalizeLowercaseStringOrEmpty ( params . chatType ) ;
484- if ( chatType && chatType !== "direct" ) {
485- return false ;
486- }
487- return ! isConversationLikeIdentity ( from ) ;
488- }
489-
490464function resolveSenderCandidates ( params : {
491465 plugin ?: ChannelPlugin ;
492466 providerId ?: ChannelId ;
0 commit comments