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

How work listener #98

Closed
ar53n opened this issue Dec 11, 2015 · 5 comments
Closed

How work listener #98

ar53n opened this issue Dec 11, 2015 · 5 comments

Comments

@ar53n
Copy link

ar53n commented Dec 11, 2015

Hello, i'am beginner programmer and i want to know which logs read messages. Because when restart script, bot ignore reading messages

@eternnoir
Copy link
Owner

I do not really understand what you mean. Can you give some sample code?

@ar53n
Copy link
Author

ar53n commented Dec 12, 2015

Sorry for my bad English. This bot repeat all messages:

def listener(messages)
    for m in messages:
        if m.content_type == 'text':
            bot.send_message(m.chat.id, m.text)

if __name__ == '__main__':
     bot = telebot.Telebot(config.token)
     bot.set_update_listener(listener)
     bot.polling(none_stop=True)

If start first time bot repeat all mesages, but second time not repeated messages.

@eternnoir
Copy link
Owner

You need add infinite loop after polling. Because polling do not block your thread. So you need block it to avoid thread terminate.

Try this.

def listener(messages)
    for m in messages:
        if m.content_type == 'text':
            bot.send_message(m.chat.id, m.text)

if __name__ == '__main__':
     bot = telebot.Telebot(config.token)
     bot.set_update_listener(listener)
     bot.polling(none_stop=True)
     import time
     while True:
          time.sleep(1)

@ar53n
Copy link
Author

ar53n commented Dec 13, 2015

Thank you, just i want to know where store last_update_id, because where we restarting bot dont repeted already repeated messages. Or maybe last_update_id statment calculate in init.py?

@eternnoir
Copy link
Owner

Yes, last_update_id is store in init.py telebot instance. New telebot instance created the last_update_id will be set to 0. When telebot get new messages, it will change last_update_id to max number which new message telebot received.

because where we restarting bot dont repeted already repeated messages.

Do you mean when you restart bot it will not get messages which already get before? Because when telebot call getUpdates with telegram bot api it will pass offset parameters. About this parameters meaning you can find in telegram bot api document.
https://core.telegram.org/bots/api#getupdates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants