Last active
August 29, 2015 14:27
-
-
Save leandrotoledo/413eb831ca858872aad0 to your computer and use it in GitHub Desktop.
python-telegram-bot using Redis/RQ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import telegram | |
import time | |
from rq import Queue | |
from redis import Redis | |
from handleMessage import handleTgMessage | |
__author__ = 'mehrdad vesal' | |
_botToken='<TOKEN>' | |
_raziBot=telegram.Bot(token=_botToken) | |
_updates=_raziBot.getUpdates() | |
_redisCon=Redis() | |
_turn=0 | |
try: | |
_lastUpdateID=_updates[-1].update_id | |
except IndexError: | |
_lastUpdateID=0 | |
def checkUpdate(timeToSleep): | |
global _lastUpdateID | |
time.sleep(timeToSleep) | |
for update in _raziBot.getUpdates(offset=_lastUpdateID): | |
if update.update_id > _lastUpdateID: | |
_lastUpdateID=update.update_id | |
if update.message.text: | |
sendToQueue(_raziBot,update.message.text,update.update_id,update.message.chat.id) | |
def sendToQueue(tg_Bot,tg_Message,tg_Update_ID,tg_Chat_ID): | |
_q=Queue(connection=_redisCon) | |
_q.enqueue(handleTgMessage,tg_Bot,tg_Message,tg_Chat_ID,tg_Update_ID) | |
if __name__=="__main__": | |
while True: | |
checkUpdate(0.5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment