2015-07-07 21:50:36 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
|
2015-07-09 16:40:44 +02:00
|
|
|
import json
|
|
|
|
|
|
|
|
|
2015-07-07 21:50:36 +02:00
|
|
|
class Update(object):
|
2015-07-09 02:58:13 +02:00
|
|
|
def __init__(self,
|
|
|
|
update_id,
|
|
|
|
message=None):
|
|
|
|
self.update_id = update_id
|
|
|
|
self.message = message
|
2015-07-07 21:50:36 +02:00
|
|
|
|
|
|
|
@staticmethod
|
2015-07-09 02:15:46 +02:00
|
|
|
def de_json(data):
|
2015-07-07 21:50:36 +02:00
|
|
|
if 'message' in data:
|
|
|
|
from telegram import Message
|
2015-07-09 02:15:46 +02:00
|
|
|
message = Message.de_json(data['message'])
|
2015-07-07 21:50:36 +02:00
|
|
|
else:
|
|
|
|
message = None
|
|
|
|
|
|
|
|
return Update(update_id=data.get('update_id', None),
|
|
|
|
message=message)
|
2015-07-09 16:40:44 +02:00
|
|
|
|
|
|
|
def to_json(self):
|
|
|
|
json_data = {'update_id': self.update_id}
|
|
|
|
if self.message:
|
|
|
|
json_data['message'] = self.message.to_json()
|
|
|
|
return json.dumps(json_data)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.to_json()
|