1

I have a simple PHP script (using Botman) called by my Telegram bot via a webhook. It's supposed to respond on receiving a keyword. This works, sending response messages to my phone.

Randomly however it repeats the messages, without any input. Though random, its so frequent I would estimate it does this at least 10 times per minute.

Thinking this could be due to some web bots calling my URL, I modified the script to check the presence (and value of) and query parameter and all random messages stopped. The web bots wouldn't know this secret parameter, right?

As expected, once I updated the PHP script (without updating Telegram with the modified webhook), the messages stopped. So far so good.

Next, updated the Telegram with the webhook containing the secret query parameter, then waited 5 minutes. No messages: still looking good.

Alas, once I send my keyword, it gives the expected response but then keeps repeating endlessly again.

Where do I look to fix this?

Ps. To test, the script also returns general info of the user. I can see it keeps returning my info in the repeated message, as if I made each request. Could this be a bug with Telegram?

user1729972
  • 712
  • 2
  • 9
  • 29
  • Are you using the "getUpdates" method? – Istorn Feb 09 '22 at 09:43
  • Not explicitly: the documentation is quite dense, I thought I read somewhere that setting the webhook automatically overrides getUpdates option. Is there someway to disable getUpdates? I have logged the IP address and all do indeed emanate from Telegram (91.108.6.141) – user1729972 Feb 09 '22 at 09:49
  • You can't because you have to get updates from Telegram's servers, otherwise your PHP page cannot handle incoming messages. Is your webhook composed of some sort of repeated schedule? – Istorn Feb 09 '22 at 09:53
  • No repeated schedule whatsoever. It simply listens for “hello” and replies with something fixed since it’s just at testing stage. It’s very confusing. – user1729972 Feb 09 '22 at 09:58
  • Could you please share your webhook's details? If the PHP script is in charge of only replying to messages, the problem relies into the webhook which probably is still looking for the latest update. – Istorn Feb 09 '22 at 09:59
  • Not sure I follow. I set the webhook by calling https://api.telegram.com/bot/setWebhook?url=, I’m not aware of any other way to access it. – user1729972 Feb 09 '22 at 10:20
  • Your webhook is probably seeing the same update object, so that it will answer continuously to that, so that's why probably. – Istorn Feb 09 '22 at 11:23
  • How do I get the update object changed then? The code was generating a pdf and then trying to return the file as an attachment. I removed all those complex parts and now it doesn’t repeat so you are right it’s the code. If I still cannot fix I will paste the code (needs some pruning) but what explicitly changes the update object? – user1729972 Feb 09 '22 at 11:29
  • I believe you need to add more details giving a 360° scenario, otherwise your question cannot be answered. – Istorn Feb 09 '22 at 11:31
  • Yes, will do once I strip out personal stuff from the code – user1729972 Feb 09 '22 at 11:32
  • Not sure what was wrong with the attachment download but changed the code to provide an external expiring URL and now it no longer repeats. If you capture your guiding comment as a response pointing me to re-examine the script well I would mark as correct answer. My initial question was "Where do I look to fix this?" anyway :-) – user1729972 Feb 09 '22 at 12:19
  • I could maybe combine what you should look out in order to understand it properly, i'll proceed in that way then. – Istorn Feb 09 '22 at 15:10

1 Answers1

1

According to your description, it seems that your webhook architecture it still looking for the most recent updates returned by Telegram getUpdates method: if your script repeats answering to the same exact message, it means that it's receiving the same exact update object more than one time.

A good solution to solve this problem could be have a look at the webhook working of, how it communicates with Telegram servers in order to understand how does it handle updates received from the Telegram Chatbot itself.

Istorn
  • 485
  • 1
  • 5
  • 23