@@ -112,25 +112,38 @@ export function hashCommandList(commands: TelegramMenuCommand[]): string {
112112 return createHash ( "sha256" ) . update ( JSON . stringify ( sorted ) ) . digest ( "hex" ) . slice ( 0 , 16 ) ;
113113}
114114
115- function resolveCommandHashPath ( accountId ?: string ) : string {
115+ function hashBotIdentity ( botIdentity ?: string ) : string {
116+ const normalized = botIdentity ?. trim ( ) ;
117+ if ( ! normalized ) {
118+ return "no-bot" ;
119+ }
120+ return createHash ( "sha256" ) . update ( normalized ) . digest ( "hex" ) . slice ( 0 , 16 ) ;
121+ }
122+
123+ function resolveCommandHashPath ( accountId ?: string , botIdentity ?: string ) : string {
116124 const stateDir = resolveStateDir ( process . env , os . homedir ) ;
117- const normalized = accountId ?. trim ( ) . replace ( / [ ^ a - z 0 - 9 . _ - ] + / gi, "_" ) || "default" ;
118- return path . join ( stateDir , "telegram" , `command-hash-${ normalized } .txt` ) ;
125+ const normalizedAccount = accountId ?. trim ( ) . replace ( / [ ^ a - z 0 - 9 . _ - ] + / gi, "_" ) || "default" ;
126+ const botHash = hashBotIdentity ( botIdentity ) ;
127+ return path . join ( stateDir , "telegram" , `command-hash-${ normalizedAccount } -${ botHash } .txt` ) ;
119128}
120129
121- async function readCachedCommandHash ( accountId ?: string ) : Promise < string | null > {
130+ async function readCachedCommandHash (
131+ accountId ?: string ,
132+ botIdentity ?: string ,
133+ ) : Promise < string | null > {
122134 try {
123- return ( await fs . readFile ( resolveCommandHashPath ( accountId ) , "utf-8" ) ) . trim ( ) ;
135+ return ( await fs . readFile ( resolveCommandHashPath ( accountId , botIdentity ) , "utf-8" ) ) . trim ( ) ;
124136 } catch {
125137 return null ;
126138 }
127139}
128140
129- async function writeCachedCommandHash ( accountId ?: string , hash ?: string ) : Promise < void > {
130- if ( ! hash ) {
131- return ;
132- }
133- const filePath = resolveCommandHashPath ( accountId ) ;
141+ async function writeCachedCommandHash (
142+ accountId : string | undefined ,
143+ botIdentity : string | undefined ,
144+ hash : string ,
145+ ) : Promise < void > {
146+ const filePath = resolveCommandHashPath ( accountId , botIdentity ) ;
134147 try {
135148 await fs . mkdir ( path . dirname ( filePath ) , { recursive : true } ) ;
136149 await fs . writeFile ( filePath , hash , "utf-8" ) ;
@@ -145,15 +158,16 @@ export function syncTelegramMenuCommands(params: {
145158 runtime : RuntimeEnv ;
146159 commandsToRegister : TelegramMenuCommand [ ] ;
147160 accountId ?: string ;
161+ botIdentity ?: string ;
148162} ) : void {
149- const { bot, runtime, commandsToRegister, accountId } = params ;
163+ const { bot, runtime, commandsToRegister, accountId, botIdentity } = params ;
150164 const sync = async ( ) => {
151165 // Skip sync if the command list hasn't changed since the last successful
152166 // sync. This prevents hitting Telegram's 429 rate limit when the gateway
153167 // is restarted several times in quick succession.
154168 // See: openclaw/openclaw#32017
155169 const currentHash = hashCommandList ( commandsToRegister ) ;
156- const cachedHash = await readCachedCommandHash ( accountId ) ;
170+ const cachedHash = await readCachedCommandHash ( accountId , botIdentity ) ;
157171 if ( cachedHash === currentHash ) {
158172 runtime . log ?.( "telegram: command menu unchanged; skipping sync" ) ;
159173 return ;
@@ -169,7 +183,7 @@ export function syncTelegramMenuCommands(params: {
169183 }
170184
171185 if ( commandsToRegister . length === 0 ) {
172- await writeCachedCommandHash ( accountId , currentHash ) ;
186+ await writeCachedCommandHash ( accountId , botIdentity , currentHash ) ;
173187 return ;
174188 }
175189
@@ -181,7 +195,7 @@ export function syncTelegramMenuCommands(params: {
181195 runtime,
182196 fn : ( ) => bot . api . setMyCommands ( retryCommands ) ,
183197 } ) ;
184- await writeCachedCommandHash ( accountId , currentHash ) ;
198+ await writeCachedCommandHash ( accountId , botIdentity , currentHash ) ;
185199 return ;
186200 } catch ( err ) {
187201 if ( ! isBotCommandsTooMuchError ( err ) ) {
0 commit comments