예제 #1
0
파일: main.py 프로젝트: tormich/pybot
    def get_updates(self, limit=100):
        if self.token is None:
            logger.warn("Cant ask for updates without token!")
            return
        if self.is_webhook_set:
            logger.warn("Webhook set. getUpdate will not work.")
            return

        msg = {"limit": limit}
        if self.last_update_id is not None:
            msg.update({"offset": self.last_update_id + 1})

        r = telegram.send(self.token, telegram.GET_UPDATES, msg)
        updates = r.json()
        if updates.get("ok") is not True:
            logger.warn(json.dumps(updates, sort_keys=True, indent=4))
            return

        try:
            self.on_update(updates)
        except Exception as e:
            logger.error(str(e))

        timeout = 1
        if len(updates.get("result", [])) == limit:
            timeout = .4

        self.set_timeout(timeout)
예제 #2
0
파일: main.py 프로젝트: tormich/pybot
    def reply(self, reply_to, text, files=None, reply_markup=None):
        """

        :type text: str
        :type reply_markup: dict
        :type reply_to: dict
        :return: requests.Response
        """
        message = {"chat_id": reply_to.get("chat").get("id"),
                   "reply_to_message_id": reply_to.get("message_id"),
                   "text": text}

        return telegram.send(token=self.token,
                             method=telegram.SEND_MESSAGE,
                             message=message,
                             files=files)