Python Forum
Handling receiving updates from user in Telebot
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Handling receiving updates from user in Telebot
#1
Hello,

I've created a Telegram bot (set on webhook) to demonstrate the issue I'd like to address:
The program currently returns the user's actions with a 3-second delay. However, I want to modify it to only process the user's initial action. I want the bot to receive the first action, ignore any subsequent actions FOREVER (it should delete if from bot's cache or elsewhere it is saved), response to that first action, then wait for the new first action from the user.

In its current state (the following code), the program responds to all user actions in the order they are received and there is no any error in log saved. I'm looking for a solution to make the bot work as follows:

- Receive the user's first action.
- Respond to the first action.
- Wait for the user's NEW action (not previous and past user's actions).
- If the user has sent additional actions before the bot responds to the first action, ignore and discard them from memory without any reaction or acknowledgement forever.

I do not know how to do it, especially deleting those non-first actions so that the bot forget them forever and never use them.
I hope the explanation is clear enough.
Can anyone provide a solution to achieve this behavior?

from flask import Flask, request
import telebot
import time
secret = "*************************************"
app = Flask(__name__)
bot = telebot.TeleBot('****************************************************', threaded=False) #https://t.me/A0524TestinggRob_bot

@app.route('/webhook', methods=['POST'])
def webhook():
    if request.headers.get('content-type') == 'application/json':
        json_str = request.get_data().decode('UTF-8')
        update = telebot.types.Update.de_json(json_str)
        bot.process_new_updates([update])
        return '', 200
    else:
        return '', 403


@bot.message_handler(func=lambda message: True)
def echo_all(message):
    time.sleep (3)
    bot.reply_to(message, message.text)
    


if __name__ == "__main__":
    bot.remove_webhook()
    bot.set_webhook(url='https://**************.pythonanywhere.com/webhook')
    
    
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Listening on receiving Interface (using scapy) CodyTheCodeNoob 1 1,883 Dec-22-2024, 10:51 PM
Last Post: PolandoFaker
  Question of Telebot mohsenamiri 0 549 Aug-14-2024, 07:03 AM
Last Post: mohsenamiri
  call query telebot lolita7777 1 2,497 May-13-2024, 06:49 PM
Last Post: david_jr_br
  Receiving this error in my "response" and causes script to return wrong status cubangt 18 5,609 Aug-13-2023, 12:16 AM
Last Post: cubangt
Star python exception handling handling .... with traceback mg24 3 3,515 Nov-09-2022, 07:29 PM
Last Post: Gribouillis
  SMA (simple moving avg) Not receiving Data (stock prices). gdbengo 2 2,183 Jul-31-2022, 08:20 PM
Last Post: paulyan
Question Installing Security only updates for 3.7.12 DailyLlama 3 2,815 Jan-26-2022, 11:24 AM
Last Post: DailyLlama
  Receiving snmp traps with more than one Community String ilknurg 0 3,820 Jan-19-2022, 09:02 AM
Last Post: ilknurg
  [Selenium]Timed out receiving message from renderer: 10.000 wood_6636 0 3,493 Jun-26-2020, 08:59 AM
Last Post: wood_6636
  Receiving XML exception from nmap.scan() results. PythonNmap 4 5,267 Jan-21-2020, 04:41 AM
Last Post: PythonNmap

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020