-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmessages.py
79 lines (57 loc) · 2.15 KB
/
messages.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import json
from knockapi.core.Service import Service
class Messages(Service):
async def list(self, options=None):
"""
Gets a paginated list of Message records
Args:
options (dict): An optional set of filtering options to pass to the query
Returns:
dict: a paginated list of Message records
"""
endpoint = '/messages'
if options and options['trigger_data']:
options['trigger_data'] = json.dumps(options['trigger_data'])
return await self.client.connection.request('get', endpoint, payload=options)
async def get(self, message_id):
"""
Get a message by its id
Args:
message_id: The message ID
Returns:
dict: Message response from Knock.
"""
endpoint = f'/messages/{message_id}'
return await self.client.connection.request('get', endpoint)
async def get_content(self, message_id):
"""
Get a message's content by its id
Args:
message_id: The message ID
Returns:
dict: MessageContent response from Knock.
"""
endpoint = f'/messages/{message_id}/content'
return await self.client.connection.request('get', endpoint)
async def get_activities(self, message_id, options=None):
"""
Get a message's activities by its id
Args:
message_id: The message ID
Returns:
dict: paginated Activity response from Knock.
"""
endpoint = f'/messages/{message_id}/activities'
if options and options['trigger_data']:
options['trigger_data'] = json.dumps(options['trigger_data'])
return await self.client.connection.request('get', endpoint, options)
async def get_events(self, message_id, options=None):
"""
Get a message's events by its id
Args:
message_id: The message ID
Returns:
dict: paginated Event response from Knock.
"""
endpoint = f'/messages/{message_id}/events'
return await self.client.connection.request('get', endpoint, options)