Ejemplo n.º 1
0
    def get_update(self):
        result = apihelper.get_updates(self.token, offset=(self.last_update_id + 1))
        updates = result['result']
        new_messages = []
        for update in updates:
            if update['update_id'] > self.last_update_id:
                self.last_update_id = update['update_id']
            msg = types.Message.de_json(json.dumps(update['message']))
            new_messages.append(msg)

        if len(new_messages) > 0:
            self.__notify_update(new_messages)
Ejemplo n.º 2
0
 def get_updates(self, offset=None, limit=None, timeout=20):
     """
     Use this method to receive incoming updates using long polling (wiki). An Array of Update objects is returned.
     :param offset: Integer. Identifier of the first update to be returned.
     :param limit: Integer. Limits the number of updates to be retrieved.
     :param timeout: Integer. Timeout in seconds for long polling.
     :return: array of Updates
     """
     json_updates = apihelper.get_updates(self.token, offset, limit, timeout)
     ret = []
     for ju in json_updates:
         ret.append(types.Update.de_json(ju))
     return ret
Ejemplo n.º 3
0
 def get_updates(self, offset=None, limit=None, timeout=20):
     """
     Use this method to receive incoming updates using long polling (wiki). An Array of Update objects is returned.
     :param offset: Integer. Identifier of the first update to be returned.
     :param limit: Integer. Limits the number of updates to be retrieved.
     :param timeout: Integer. Timeout in seconds for long polling.
     :return: array of Updates
     """
     json_updates = apihelper.get_updates(self.token, offset, limit, timeout)
     ret = []
     for ju in json_updates:
         ret.append(types.Update.de_json(ju))
     return ret
Ejemplo n.º 4
0
 def get_update(self):
     """
     Retrieves any updates from the Telegram API.
     Registered listeners and applicable message handlers will be notified when a new message arrives.
     :raises ApiException when a call has failed.
     """
     updates = apihelper.get_updates(self.token, offset=(self.last_update_id + 1), timeout=20)
     new_messages = []
     for update in updates:
         if update['update_id'] > self.last_update_id:
             self.last_update_id = update['update_id']
         msg = types.Message.de_json(update['message'])
         new_messages.append(msg)
     logger.debug('GET %d new messages' % len(new_messages))
     if len(new_messages) > 0:
         self.process_new_messages(new_messages)