question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bot sending duplicates

See original GitHub issue

Hello everyone! I’m a newcomer for Telegram bot programming and I’m not really sure if this is a bug or it’s me doing something wrong. If that’s the case forgive me!

I’m trying to create a bot which simply returns data from a json file, filtering and manipulating it. Each json has a tag called “level”, so I wrote a “search by level” callback query. Once is fired, this callback sends a message to ask the user to input the level (from 0 to 9). Then the bot simply reads the json and filters the output to send as a message.

The problem is that it sends duplicates while the callback is fired more than once. If you fire it 2 times, it will send 2 messages and the third time it will send 3 messages, and so on.

Here’s the code:

 val holder = deserializeSpells("/home/nicola/Desktop/formattedFile.json")
 val bot = bot {
        dispatch {
            command("start") {
                bot.sendMessage(ChatId.fromId(update.message!!.chat.id),"<b><i>Benvenuto in WizardBook!</i></b>", parseMode = ParseMode.HTML)
                bot.sendMessage(ChatId.fromId(update.message!!.chat.id),"Ti aiuterò a trovare gli incantesimi!")
                val replyMarkup = InlineKeyboardMarkup.create(
                    listOf(
                        InlineKeyboardButton.CallbackData("Cerca per livello","bylevel"),
                        InlineKeyboardButton.CallbackData("Cerca per classe","byclass")),
                    listOf(
                        InlineKeyboardButton.CallbackData("Cerca per scuola","byschool"),
                        InlineKeyboardButton.CallbackData("Cerca per nome (o un pezzo)","byname")),
                    listOf(InlineKeyboardButton.CallbackData("Cerca per nome (preciso)","byreference")),
                    listOf(InlineKeyboardButton.CallbackData("La magia del giorno!","byday")),
                    listOf(InlineKeyboardButton.CallbackData("Contatti","bycontacts"))
                )
                bot.sendMessage(ChatId.fromId(message.chat.id),"Scegli il metodo di ricerca", replyMarkup = replyMarkup)
            }

            callbackQuery ("bylevel") {
                val chatId = update.callbackQuery?.message!!.chat.id
                bot.sendMessage(ChatId.fromId(chatId),"Che livello stai cercando? <u>(Da 0 a 9)</u>", parseMode = ParseMode.HTML)
                text {
                    var out :String = ""
                    holder.forEach {
                        if (it.level == text) out+= "\n${it.name}\n<i><u>Lvl. ${it.level} Classi ${it.combat}</u></i>"
                    }
                    bot.sendMessage(ChatId.fromId(chatId),out, parseMode = ParseMode.HTML)
                }
            }
        }
    }
    bot.startPolling()

Maybe it’s me not understanding how to properly handle updates? Thanks a lot!

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
NicolaM94commented, Oct 4, 2022

Having a library like that would be awesome, one could build much more complex commands and queries. Up until that Christmas present though, I’ll try to work something around implementing one of the solutions you guys suggested and poke it around to see the behavior, maybe manually closing the text handler each time. Thanks a lot!

0reactions
lifestreamycommented, Oct 11, 2022

I think I’ve mistakenly mentioned the wrong user. Here we go @seik @vjgarciag96

Read more comments on GitHub >

github_iconTop Results From Across the Web

bots sending duplicate messages : r/discordapp - Reddit
r/discordapp - Discord dms not sending to a specific person. I'm.
Read more >
py-cord bot sending duplicate embeds - Stack Overflow
For some reason, when my discord bot sends error messages from this function it will send a duplicate of the original embed it...
Read more >
Receiving duplicate messages on bot.reply #473 - GitHub
This issue is occurring for me. It happens when the bot has already been authorized to the team, and then someone else comes...
Read more >
Duplicating bots - Landbot Help
You can duplicate a WhatsApp and Messenger bot, because this type of bot can be used for either WhatsApp or Messenger, but not...
Read more >
Identify duplicate conversations in your inbox | Help Center
Use the duplicate detection Task Bot to highlight customers with multiple active conversations and prevent double handling.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found