Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: telegram client duplicate function removal #1140

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 5 additions & 18 deletions packages/client-telegram/src/messageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,15 @@ export class MessageManager {
'caption' in message ? (message as any).caption : '';
if (!messageText) return false;

const isReplyToBot = (message as any).reply_to_message?.from?.is_bot === true &&
(message as any).reply_to_message?.from?.username === botUsername;
const isMentioned = messageText.includes(`@${botUsername}`);
const hasUsername = messageText.toLowerCase().includes(botUsername.toLowerCase());

return isMentioned || (!this.runtime.character.clientConfig?.telegram?.shouldRespondOnlyToMentions && hasUsername);
return isReplyToBot || isMentioned || (!this.runtime.character.clientConfig?.telegram?.shouldRespondOnlyToMentions && hasUsername);
}


private _checkInterest(chatId: string): boolean {
const chatState = this.interestChats[chatId];
if (!chatState) return false;
Expand Down Expand Up @@ -360,22 +363,6 @@ export class MessageManager {
return true;
}

private _isMessageForMe(message: Message): boolean {
const botUsername = this.bot.botInfo?.username;
if (!botUsername) return false;

const messageText = 'text' in message ? message.text :
'caption' in message ? (message as any).caption : '';
if (!messageText) return false;

const isReplyToBot = (message as any).reply_to_message?.from?.is_bot === true &&
(message as any).reply_to_message?.from?.username === botUsername;
const isMentioned = messageText.includes(`@${botUsername}`);
const hasUsername = messageText.toLowerCase().includes(botUsername.toLowerCase());

return isReplyToBot || isMentioned || (!this.runtime.character.clientConfig?.telegram?.shouldRespondOnlyToMentions && hasUsername);
}

// Process image messages and generate descriptions
private async processImage(
message: Message
Expand Down Expand Up @@ -422,7 +409,7 @@ export class MessageManager {
message: Message,
state: State
): Promise<boolean> {

if (this.runtime.character.clientConfig?.telegram?.shouldRespondOnlyToMentions) {
return this._isMessageForMe(message);
}
Expand Down
Loading