-
Notifications
You must be signed in to change notification settings - Fork 1
/
eb_message.py
47 lines (37 loc) · 1.14 KB
/
eb_message.py
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
MSG_TYPE_THREAD_STARTED = 1
MSG_TYPE_STOP_THREAD = 2
MSG_TYPE_THREAD_STOPPED = 3
MSG_TYPE_USER_MESSAGE = 4
MSG_TYPE_LOCATION_UPDATE = 5
MSG_TYPE_NOTIFY_USER = 6
VALID_MSG_TYPES = [
MSG_TYPE_THREAD_STARTED,
MSG_TYPE_STOP_THREAD,
MSG_TYPE_THREAD_STOPPED,
MSG_TYPE_USER_MESSAGE,
MSG_TYPE_LOCATION_UPDATE,
MSG_TYPE_NOTIFY_USER,
]
EXAMPLE_USER_MESSAGES_DATA = {
# Incoming or outgoing depends on the context. Could be from owner to
# bot or bot to owner (or perhaps from bot to other user)
"user": "username",
"text": "foo",
"choices": [["first row", "second column"],
["second row", "final button"]]
}
example_location_update_data = {
"location": "home",
"arrived": True, # True = arrived, False = left
}
class MessageTypeInvalid(Exception):
pass
class Message:
def __init__(self, sender, msg_type, data=None):
if msg_type not in VALID_MSG_TYPES:
raise MessageTypeInvalid
self.sender = sender
self.msg_type = msg_type
self.data = data
def __repr__(self):
return "Message type: %d, sender: %s" % (self.msg_type, self.sender)