Esempio n. 1
0
class VacasBotServer():
    JOBS_FILE = 'jobs.json'

    TOKEN = ""
    BOT_ID = ""
    BOT_NAME = ""

    SLEEP_TIME = 3

    def run(self):
        self.telegram = TelegramAPIHelper(self.TOKEN, self.BOT_NAME)
        self.message_processor = MessageProcessor(self.JOBS_FILE)
        self._discard_previous_unattended_messages()
        while True:
            self.telegram.update_offset()
            for message in self.telegram.get_new_messages():
                self._process_message(message)

            sleep(self.SLEEP_TIME)

    def _discard_previous_unattended_messages(self):
        self.telegram.get_new_messages()
        self.telegram.update_offset()

    def _process_message(self, message):
        answer = self.message_processor.get_answer(message)
        if answer:
            self.telegram.reply(message, answer)
Esempio n. 2
0
    def run(self):
        self.telegram = TelegramAPIHelper(self.TOKEN, self.BOT_NAME)
        self.message_processor = MessageProcessor(self.JOBS_FILE)
        self._discard_previous_unattended_messages()
        while True:
            self.telegram.update_offset()
            for message in self.telegram.get_new_messages():
                self._process_message(message)

            sleep(self.SLEEP_TIME)