-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteractives.py
More file actions
64 lines (47 loc) · 1.8 KB
/
interactives.py
File metadata and controls
64 lines (47 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import json
import uuid
import base64
class ReplyKeyboard:
def __init__(self, key_constructor):
if isinstance(key_constructor, dict):
self.key_constructor = key_constructor
else:
raise Exception('except Dict receives {}'.format(str(type(key_constructor))))
self.keyboard = key_constructor
@property
def keyboard(self):
return json.dumps(self._keyboard)
@keyboard.setter
def keyboard(self, key_constructor):
self._keyboard = {'keyboard': key_constructor}
def reply_keyboard(self):
keyboard = {'keyboard': self.key_constructor}
return json.dumps(keyboard)
class InlineKeyboardButton:
def __init__(self, text=None, cb_data=None):
self.button = dict(text=str(text), cb_data=str(cb_data))
def get_keyboard_dict(self):
return self.button
def __repr__(self):
return json.dumps(self.button)
class InlineUrlButton:
def __init__(self, text=None, url=None):
self.button = dict(text=str(text), url=str(url))
def get_keyboard_dict(self):
return self.button
def __repr__(self):
return json.dumps(self.button)
class InlineInAppPurchaseButton:
def __init__(self, text=None, amount=None, currency=None, desc=None):
if currency not in ['IRR', 'coin']:
raise Exception('currency must be IRR or coin')
self.random_id = bytes(uuid.uuid4().hex, 'ascii')
self.button = dict(text=str(text),
amount=int(amount),
currency=str(currency),
ref_id=base64.b64encode(self.random_id).decode('utf-8'),
desc=str(desc))
def get_keyboard_dict(self):
return self.button
def __repr__(self):
return json.dumps(self.button)