9
9
10
10
headers = {'X-API-KEY' : Config .FLOWINTEL_API_KEY }
11
11
12
- def request_post_flowintel (url , data , content_type = 'application/json' ):
12
+ def request_post_flowintel (url , data , content_type = 'application/json' , matrix_id = None ):
13
13
headers ["Content-Type" ] = content_type
14
+ if matrix_id :
15
+ headers ["MATRIX-ID" ] = matrix_id
14
16
res = requests .post (f"{ Config .FLOWINTEL_URL } /api/case/{ url } " , json = data , headers = headers )
15
17
return res
16
18
17
- def request_get_flowintel (url ):
19
+ def request_get_flowintel (url , matrix_id = None ):
20
+ if matrix_id :
21
+ headers ["MATRIX-ID" ] = matrix_id
18
22
res = requests .get (f"{ Config .FLOWINTEL_URL } /api/case/{ url } " , headers = headers )
19
23
return res
20
24
25
+ async def check_format (bot , match , message , room , size ):
26
+ if not len (match .args ()) >= size :
27
+ await bot .api .send_text_message (room .room_id , "Not enough argument" , reply_to = message .event_id )
28
+ return False
29
+ return True
21
30
22
- async def modify_case (bot , match , message , room , type ):
23
- """Modify title or description of a case"""
24
- args_list = match .args ()[1 :]
25
- case_id = match .args ()[0 ]
31
+ async def check_matrix_id (bot , message , room ):
32
+ res = requests .get (f"{ Config .FLOWINTEL_URL } /api/admin/user_matrix_id?matrix_id={ message .sender } " , headers = headers )
33
+ if "message" in res .json ():
34
+ loc_message = res .json ()["message" ]
35
+ await bot .api .send_markdown_message (room .room_id , loc_message , reply_to = message .event_id )
36
+ return False
37
+ return res
26
38
27
- data = { type : " " . join ( arg for arg in args_list )}
28
- res = request_post_flowintel ( f" { case_id } /edit" , data )
39
+
40
+ async def send_markdown ( bot , message , room , res ):
29
41
if "message" in res .json ():
30
42
loc_message = res .json ()["message" ]
31
43
else :
32
44
loc_message = f"```JSON\n { json .dumps (res .json (), indent = 2 )} \n ```"
33
- last_command = message
34
45
await bot .api .send_markdown_message (room .room_id , loc_message , reply_to = message .event_id )
35
- return last_command
46
+
47
+
48
+ async def modify_case (bot , match , message , room , type ):
49
+ """Modify title or description of a case"""
50
+ args_list = match .args ()[1 :]
51
+ case_id = match .args ()[0 ]
52
+
53
+ data = {type : " " .join (arg for arg in args_list )}
54
+ res = request_post_flowintel (f"{ case_id } /edit" , data , matrix_id = message .sender )
55
+ return send_markdown (bot , message , room , res )
36
56
37
57
38
58
async def case_check (bot , match , message , room ):
39
59
"""All ckeck for case part"""
40
60
last_command = ""
41
61
if match .command ("create_case" ):
42
- data = {"title" : " " .join (arg for arg in match .args ())}
43
- res = request_post_flowintel ("create" , data )
44
- if "message" in res .json ():
45
- loc_message = res .json ()["message" ]
46
- else :
47
- loc_message = f"```JSON\n { json .dumps (res .json (), indent = 2 )} \n ```"
48
62
last_command = message
49
- await bot .api .send_text_message (room .room_id , loc_message , reply_to = message .event_id )
63
+ if await check_format (bot , match , message , room , 1 ):
64
+ data = {"title" : " " .join (arg for arg in match .args ())}
65
+ res = request_post_flowintel ("create" , data , matrix_id = message .sender )
66
+ if "message" in res .json ():
67
+ loc_message = res .json ()["message" ]
68
+ else :
69
+ loc_message = f"```JSON\n { json .dumps (res .json (), indent = 2 )} \n ```"
70
+ await bot .api .send_text_message (room .room_id , loc_message , reply_to = message .event_id )
50
71
51
72
if match .command ("case_title" ):
52
- data = {"title" : " " .join (arg for arg in match .args ())}
53
- res = request_post_flowintel ("title" , data )
54
- if "message" in res .json ():
55
- loc_message = res .json ()["message" ]
56
- else :
57
- loc_message = f"```JSON\n { json .dumps (res .json (), indent = 2 )} \n ```"
58
73
last_command = message
59
- await bot .api .send_markdown_message (room .room_id , loc_message , reply_to = message .event_id )
74
+ if await check_format (bot , match , message , room , 1 ):
75
+ data = {"title" : " " .join (arg for arg in match .args ())}
76
+ res = request_post_flowintel ("title" , data )
77
+ await send_markdown (bot , message , room , res )
60
78
61
- if match .command ("case_id" ):
62
- res = request_get_flowintel (match .args ()[0 ])
63
- if "message" in res .json ():
64
- loc_message = res .json ()["message" ]
65
- else :
66
- loc_message = f"```JSON\n { json .dumps (res .json (), indent = 2 )} \n ```"
79
+ if match .command ("case" ):
67
80
last_command = message
68
- await bot .api .send_markdown_message (room .room_id , loc_message , reply_to = message .event_id )
81
+ if await check_format (bot , match , message , room , 1 ):
82
+ res = request_get_flowintel (match .args ()[0 ])
83
+ await send_markdown (bot , message , room , res )
84
+
69
85
70
86
if match .command ("modify_title" ):
71
- last_command = modify_case (bot , match , message , room , "title" )
72
-
87
+ last_command = message
88
+ if await check_format (bot , match , message , room , 2 ):
89
+ await modify_case (bot , match , message , room , "title" )
90
+
73
91
if match .command ("modify_description" ):
74
- last_command = modify_case (bot , match , message , room , "description" )
92
+ if await check_format (bot , match , message , room , 2 ):
93
+ await modify_case (bot , match , message , room , "description" )
75
94
76
95
if match .command ("complete_case" ):
77
- res = request_get_flowintel (f"{ match .args ()[0 ]} /complete" )
78
- if "message" in res .json ():
79
- loc_message = res .json ()["message" ]
80
- else :
81
- loc_message = f"```JSON\n { json .dumps (res .json (), indent = 2 )} \n ```"
82
96
last_command = message
83
- await bot .api .send_markdown_message (room .room_id , loc_message , reply_to = message .event_id )
97
+ if await check_format (bot , match , message , room , 1 ):
98
+ res = request_get_flowintel (f"{ match .args ()[0 ]} /complete" , matrix_id = message .sender )
99
+ await send_markdown (bot , message , room , res )
100
+
101
+ if match .command ("case_tasks" ):
102
+ last_command = message
103
+ if await check_format (bot , match , message , room , 1 ):
104
+ res = request_get_flowintel (f"{ match .args ()[0 ]} /tasks" )
105
+ await send_markdown (bot , message , room , res )
106
+
107
+ if match .command ("case_note" ):
108
+ last_command = message
109
+ if await check_format (bot , match , message , room , 1 ):
110
+ res = request_get_flowintel (f"{ match .args ()[0 ]} /get_note" )
111
+ await send_markdown (bot , message , room , res )
112
+
113
+ if match .command ("case_modify_note" ):
114
+ last_command = message
115
+ if await check_format (bot , match , message , room , 2 ):
116
+ args_list = match .args ()[1 :]
117
+ case_id = match .args ()[0 ]
118
+ data = {"note" : " " .join (arg for arg in args_list )}
119
+ res = request_post_flowintel (f"{ case_id } /modif_case_note" , data , matrix_id = message .sender )
120
+ await send_markdown (bot , message , room , res )
121
+
122
+
123
+ if match .command ("case_all_notes" ):
124
+ last_command = message
125
+ if await check_format (bot , match , message , room , 1 ):
126
+ res = request_get_flowintel (f"{ match .args ()[0 ]} /all_notes" )
127
+ await send_markdown (bot , message , room , res )
128
+
129
+ if match .command ("case_all_users" ):
130
+ last_command = message
131
+ if await check_format (bot , match , message , room , 1 ):
132
+ res = request_get_flowintel (f"{ match .args ()[0 ]} /get_all_users" )
133
+ await send_markdown (bot , message , room , res )
134
+
135
+ if match .command ("list_status" ):
136
+ last_command = message
137
+ if await check_format (bot , match , message , room , 1 ):
138
+ res = request_get_flowintel (f"list_status" )
139
+ await send_markdown (bot , message , room , res )
140
+
141
+ if match .command ("case_status" ):
142
+ last_command = message
143
+ if await check_format (bot , match , message , room , 1 ):
144
+ res = request_get_flowintel (match .args ()[0 ])
145
+ if "message" in res .json ():
146
+ loc_message = res .json ()["message" ]
147
+ else :
148
+ res_status = request_get_flowintel (f"list_status" )
149
+ loc_message = "Status not found"
150
+ for status in res_status .json ():
151
+ if status ["id" ] == res .json ()["status_id" ]:
152
+ loc_message = f"Case is `{ status ['name' ]} `"
153
+ await bot .api .send_markdown_message (room .room_id , loc_message , reply_to = message .event_id )
154
+
155
+ if match .command ("case_modify_status" ):
156
+ last_command = message
157
+ if await check_format (bot , match , message , room , 2 ):
158
+ case_id = match .args ()[0 ]
159
+ status_id = match .args ()[1 ]
160
+ data = {"status_id" : status_id }
84
161
162
+ res = request_post_flowintel (f"{ case_id } /change_status" , data , matrix_id = message .sender )
163
+ await send_markdown (bot , message , room , res )
85
164
86
165
87
166
if last_command :
88
- return last_command
167
+ return last_command
168
+
0 commit comments