| 
									
										
										
										
											2024-03-21 09:35:02 +08:00
										 |  |  | import requests | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-21 09:47:13 +08:00
										 |  |  | def post_webhook(url: str, message: str, event_data: dict) -> bool: | 
					
						
							| 
									
										
										
										
											2024-03-21 09:35:02 +08:00
										 |  |  |     try: | 
					
						
							| 
									
										
										
										
											2024-03-21 09:47:13 +08:00
										 |  |  |         payload = {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if "https://hooks.slack.com" in url: | 
					
						
							|  |  |  |             payload["text"] = message | 
					
						
							|  |  |  |         elif "https://discord.com/api/webhooks" in url: | 
					
						
							|  |  |  |             payload["content"] = message | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             payload = {**event_data} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         r = requests.post(url, json=payload) | 
					
						
							| 
									
										
										
										
											2024-03-21 09:35:02 +08:00
										 |  |  |         r.raise_for_status() | 
					
						
							|  |  |  |         return True | 
					
						
							|  |  |  |     except Exception as e: | 
					
						
							|  |  |  |         print(e) | 
					
						
							|  |  |  |         return False |