forked from open-webui/open-webui
		
	feat: Teams MessageCard
refer to https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using\?tabs\=cURL\#example-of-connector-message
This commit is contained in:
		
							parent
							
								
									8d108060d5
								
							
						
					
					
						commit
						5eac5c54f8
					
				
					 1 changed files with 24 additions and 0 deletions
				
			
		|  | @ -1,4 +1,7 @@ | ||||||
|  | import json | ||||||
|  | 
 | ||||||
| import requests | import requests | ||||||
|  | from config import VERSION | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def post_webhook(url: str, message: str, event_data: dict) -> bool: | def post_webhook(url: str, message: str, event_data: dict) -> bool: | ||||||
|  | @ -9,6 +12,27 @@ def post_webhook(url: str, message: str, event_data: dict) -> bool: | ||||||
|             payload["text"] = message |             payload["text"] = message | ||||||
|         elif "https://discord.com/api/webhooks" in url: |         elif "https://discord.com/api/webhooks" in url: | ||||||
|             payload["content"] = message |             payload["content"] = message | ||||||
|  |         elif "webhook.office.com" in url: | ||||||
|  |             action = event_data.get("action", "undefined") | ||||||
|  |             facts = [ | ||||||
|  |                 {"name": name, "value": value} | ||||||
|  |                 for name, value in json.loads(event_data.get("user", {})).items() | ||||||
|  |             ] | ||||||
|  |             payload = { | ||||||
|  |                 "@type": "MessageCard", | ||||||
|  |                 "@context": "http://schema.org/extensions", | ||||||
|  |                 "themeColor": "0076D7", | ||||||
|  |                 "summary": message, | ||||||
|  |                 "sections": [ | ||||||
|  |                     { | ||||||
|  |                         "activityTitle": message, | ||||||
|  |                         "activitySubtitle": f"Open WebUI ({VERSION}) - {action}", | ||||||
|  |                         "activityImage": "https://openwebui.com/favicon.png", | ||||||
|  |                         "facts": facts, | ||||||
|  |                         "markdown": True, | ||||||
|  |                     } | ||||||
|  |                 ], | ||||||
|  |             } | ||||||
|         else: |         else: | ||||||
|             payload = {**event_data} |             payload = {**event_data} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 changchiyou
						changchiyou