Spaces:
Running
on
Zero
Running
on
Zero
test
Browse files- mysite/interpreter/google_chat.py +57 -0
- mysite/routers/fastapi.py +13 -4
mysite/interpreter/google_chat.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import json
|
3 |
+
|
4 |
+
def send_google_chat_card(webhook_url, title, subtitle, link_text, link_url):
|
5 |
+
headers = {
|
6 |
+
'Content-Type': 'application/json; charset=UTF-8'
|
7 |
+
}
|
8 |
+
|
9 |
+
subtitle = convert_newlines_to_google_chat_format(subtitle)
|
10 |
+
|
11 |
+
card_message = {
|
12 |
+
"cards": [
|
13 |
+
{
|
14 |
+
"header": {
|
15 |
+
"title": title,
|
16 |
+
},
|
17 |
+
"sections": [
|
18 |
+
{
|
19 |
+
"widgets": [
|
20 |
+
{
|
21 |
+
"textParagraph": {
|
22 |
+
"text": subtitle
|
23 |
+
}
|
24 |
+
},
|
25 |
+
{
|
26 |
+
"textParagraph": {
|
27 |
+
"text": "<b>{}</b>".format(link_text)
|
28 |
+
}
|
29 |
+
},
|
30 |
+
{
|
31 |
+
"buttons": [
|
32 |
+
{
|
33 |
+
"textButton": {
|
34 |
+
"text": "Open Link",
|
35 |
+
"onClick": {
|
36 |
+
"openLink": {
|
37 |
+
"url": link_url
|
38 |
+
}
|
39 |
+
}
|
40 |
+
}
|
41 |
+
}
|
42 |
+
]
|
43 |
+
},
|
44 |
+
]
|
45 |
+
}
|
46 |
+
]
|
47 |
+
}
|
48 |
+
]
|
49 |
+
}
|
50 |
+
|
51 |
+
|
52 |
+
response = requests.post(webhook_url, headers=headers, data=json.dumps(card_message))
|
53 |
+
|
54 |
+
if response.status_code == 200:
|
55 |
+
print("Message posted successfully.")
|
56 |
+
else:
|
57 |
+
print(f"Failed to post message: {response.status_code}, {response.text}")
|
mysite/routers/fastapi.py
CHANGED
@@ -46,7 +46,7 @@ def include_routers(app):
|
|
46 |
logger.error(f"Module not found: {e}")
|
47 |
except Exception as e:
|
48 |
logger.error(f"An error occurred: {e}")
|
49 |
-
|
50 |
#from routers.webhooks import router
|
51 |
def setup_webhook_routes(app: FastAPI):
|
52 |
from polls.routers import register_routers
|
@@ -78,10 +78,12 @@ def setup_webhook_routes(app: FastAPI):
|
|
78 |
logger.info("Received Body: %s", body_str)
|
79 |
body_json = json.loads(body_str)
|
80 |
events = body_json.get("events", [])
|
|
|
|
|
|
|
|
|
81 |
|
82 |
|
83 |
-
return
|
84 |
-
|
85 |
for event in events:
|
86 |
if event["type"] == "message" and event["message"]["type"] == "text":
|
87 |
user_id = event["source"]["userId"]
|
@@ -91,7 +93,14 @@ def setup_webhook_routes(app: FastAPI):
|
|
91 |
logger.info(f"User ID: {user_id}, Text: {text}")
|
92 |
#test_set_lide(text,"a1")
|
93 |
#no_process_file(text, "ai")
|
94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
for event in events:
|
97 |
if event["type"] == "message" and event["message"]["type"] == "text":
|
|
|
46 |
logger.error(f"Module not found: {e}")
|
47 |
except Exception as e:
|
48 |
logger.error(f"An error occurred: {e}")
|
49 |
+
from mysite.interpreter.google_chat import send_google_chat_card
|
50 |
#from routers.webhooks import router
|
51 |
def setup_webhook_routes(app: FastAPI):
|
52 |
from polls.routers import register_routers
|
|
|
78 |
logger.info("Received Body: %s", body_str)
|
79 |
body_json = json.loads(body_str)
|
80 |
events = body_json.get("events", [])
|
81 |
+
webhook_url = os.getenv("chat_url")
|
82 |
+
token = os.getenv("token")
|
83 |
+
url = github(token,foldername)
|
84 |
+
|
85 |
|
86 |
|
|
|
|
|
87 |
for event in events:
|
88 |
if event["type"] == "message" and event["message"]["type"] == "text":
|
89 |
user_id = event["source"]["userId"]
|
|
|
93 |
logger.info(f"User ID: {user_id}, Text: {text}")
|
94 |
#test_set_lide(text,"a1")
|
95 |
#no_process_file(text, "ai")
|
96 |
+
title = """本番テスト 入力内容のみ設定"""
|
97 |
+
subtitle = "prompt"
|
98 |
+
link_text = "test"
|
99 |
+
link_url = "url"
|
100 |
+
|
101 |
+
send_google_chat_card(webhook_url, title, subtitle, link_text, link_url)
|
102 |
+
|
103 |
+
return
|
104 |
|
105 |
for event in events:
|
106 |
if event["type"] == "message" and event["message"]["type"] == "text":
|