fix(telegram): ignore bot-originated inbound messages to prevent echo loop
This commit is contained in:
parent
2f4f45080b
commit
c4080436db
1 changed files with 15 additions and 0 deletions
|
|
@ -355,6 +355,21 @@ func (c *TelegramChannel) handleMessage(ctx context.Context, message *telego.Mes
|
||||||
if user == nil {
|
if user == nil {
|
||||||
return fmt.Errorf("message sender (user) is nil")
|
return fmt.Errorf("message sender (user) is nil")
|
||||||
}
|
}
|
||||||
|
if user.IsBot {
|
||||||
|
logger.DebugCF("telegram", "Ignoring bot-originated message", map[string]any{
|
||||||
|
"user_id": user.ID,
|
||||||
|
})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
// Defensive fallback: ignore messages from this bot by username to avoid self-loop echoes.
|
||||||
|
if botUsername := c.bot.Username(); botUsername != "" && strings.EqualFold(user.Username, botUsername) {
|
||||||
|
logger.DebugCF("telegram", "Ignoring self message by username", map[string]any{
|
||||||
|
"user_id": user.ID,
|
||||||
|
"username": user.Username,
|
||||||
|
"bot_name": botUsername,
|
||||||
|
})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
platformID := fmt.Sprintf("%d", user.ID)
|
platformID := fmt.Sprintf("%d", user.ID)
|
||||||
sender := bus.SenderInfo{
|
sender := bus.SenderInfo{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue