Permalink
Browse files

Fixed support for channels

  • Loading branch information...
yusufk committed Feb 24, 2016
1 parent 49760b4 commit 3ca0b7e72aa317abe579f61e5445018f600e7f1a
Showing with 17 additions and 13 deletions.
  1. +13 −8 pytgbotapi/BotApi.py
  2. +4 −5 pytgbotapi/example.py
View
@@ -35,20 +35,24 @@ class Update:
def __init__(self, update_id,message=None):
self.update_id = update_id
if message != None:
#print(message)
print(message)
self.message = Message(message['message_id'],message['from'],message['date'],message['chat'])
if "text" in message:
self.message.set_text(message['text'])
else: self.message = None
class Chat:
"""Chat Object"""
def __init__(self, msg_id, msg_type):
self.msg_id = msg_id
self.msg_type = msg_type
def set_title(self,msg_title):
self.title = msg_title
"""Chat Object"""
def __init__(self, chat_id, chat_type, chat_title=None, chat_username=None, chat_first_name=None, chat_last_name=None):
self.chat_id = chat_id
self.chat_type = chat_type
self.title = chat_title
self.username = chat_username
self.first_name = chat_first_name
self.last_name = chat_last_name
def set_title(self,title):
self.title = chat_title
def set_username(self,username):
self.username = username
@@ -82,6 +86,7 @@ def send_request(self,method,parameters=None):
r = requests.post(self.api_url+"/bot"+self.token+"/"+method, parameters)#, data, auth=('user', '*****'))
response = json.loads(r.text)
if "result" in response:
#print(response)
return response['result']
else:
print(response)
View
@@ -2,13 +2,12 @@
def main():
print("Starting...")
bot = BotApi("47745865:AAFgsfC2QWsmRNEFYJ3EZPTgBLGrhMMOTCQ")
bot = BotApi("111111111:AAAAAAaJrJrJebfRF55njXPn5rxTfSD3Y90")
print(bot.getMe())
updates = bot.getUpdates(offset=bot.getLastFetchedId()+1)
updates = bot.getUpdates(offset=bot.getLastFetchedId()+1)
for update in updates:
if update.message.msg_from != None:
print(str(update.update_id)+": "+str(update.message.msg_from.userid)+": "+update.message.text)
bot.sendMessage(str(update.message.msg_from.userid),"Hello World")
if update.message.chat != None:
print(str(update.message.chat.chat_id ))
#bot.sendMessage(str(update.message.msg_from.userid),"Hello World")
if __name__ == "__main__":
main()

0 comments on commit 3ca0b7e

Please sign in to comment.