21
21
crashlytics_fn ,
22
22
performance_fn ,
23
23
)
24
+
24
25
# [END v2import]
25
26
26
27
import requests
27
28
28
29
DISCORD_WEBHOOK_URL = params .SecretParam ("DISCORD_WEBHOOK_URL" )
29
30
30
31
31
- def post_message_to_discord (bot_name : str , message_body : str ,
32
- webhook_url : str ) -> requests .Response :
32
+ def post_message_to_discord (
33
+ bot_name : str , message_body : str , webhook_url : str
34
+ ) -> requests .Response :
33
35
"""Posts a message to Discord with Discord's Webhook API.
34
36
35
37
Params:
@@ -58,9 +60,10 @@ def post_message_to_discord(bot_name: str, message_body: str,
58
60
# [START v2CrashlyticsAlertTrigger]
59
61
@crashlytics_fn .on_new_fatal_issue_published (secrets = ["DISCORD_WEBHOOK_URL" ])
60
62
def post_fatal_issue_to_discord (
61
- event : crashlytics_fn .CrashlyticsNewFatalIssueEvent ) -> None :
63
+ event : crashlytics_fn .CrashlyticsNewFatalIssueEvent ,
64
+ ) -> None :
62
65
"""Publishes a message to Discord whenever a new Crashlytics fatal issue occurs."""
63
- # [END v2CrashlyticsAlertTrigger]
66
+ # [END v2CrashlyticsAlertTrigger]
64
67
# [START v2CrashlyticsEventPayload]
65
68
# Construct a helpful message to send to Discord.
66
69
app_id = event .app_id
@@ -78,8 +81,9 @@ def post_fatal_issue_to_discord(
78
81
79
82
try :
80
83
# [START v2SendToDiscord]
81
- response = post_message_to_discord ("Crashlytics Bot" , message ,
82
- DISCORD_WEBHOOK_URL .value ())
84
+ response = post_message_to_discord (
85
+ "Crashlytics Bot" , message , DISCORD_WEBHOOK_URL .value ()
86
+ )
83
87
if response .ok :
84
88
print (
85
89
f"Posted fatal Crashlytics alert { issue .id } for { app_id } to Discord."
@@ -97,11 +101,13 @@ def post_fatal_issue_to_discord(
97
101
98
102
# [START v2AppDistributionAlertTrigger]
99
103
@app_distribution_fn .on_new_tester_ios_device_published (
100
- secrets = ["DISCORD_WEBHOOK_URL" ])
104
+ secrets = ["DISCORD_WEBHOOK_URL" ]
105
+ )
101
106
def post_new_udid_to_discord (
102
- event : app_distribution_fn .NewTesterDeviceEvent ) -> None :
107
+ event : app_distribution_fn .NewTesterDeviceEvent ,
108
+ ) -> None :
103
109
"""Publishes a message to Discord whenever someone registers a new iOS test device."""
104
- # [END v2AppDistributionAlertTrigger]
110
+ # [END v2AppDistributionAlertTrigger]
105
111
# [START v2AppDistributionEventPayload]
106
112
# Construct a helpful message to send to Discord.
107
113
app_id = event .app_id
@@ -115,8 +121,9 @@ def post_new_udid_to_discord(
115
121
116
122
try :
117
123
# [START v2SendNewTesterIosDeviceToDiscord]
118
- response = post_message_to_discord ("App Distro Bot" , message ,
119
- DISCORD_WEBHOOK_URL .value ())
124
+ response = post_message_to_discord (
125
+ "App Distro Bot" , message , DISCORD_WEBHOOK_URL .value ()
126
+ )
120
127
if response .ok :
121
128
print (
122
129
f"Posted iOS device registration alert for { app_dist .tester_email } to Discord."
@@ -135,9 +142,10 @@ def post_new_udid_to_discord(
135
142
# [START v2PerformanceAlertTrigger]
136
143
@performance_fn .on_threshold_alert_published (secrets = ["DISCORD_WEBHOOK_URL" ])
137
144
def post_performance_alert_to_discord (
138
- event : performance_fn .PerformanceThresholdAlertEvent ) -> None :
145
+ event : performance_fn .PerformanceThresholdAlertEvent ,
146
+ ) -> None :
139
147
"""Publishes a message to Discord whenever a performance threshold alert is fired."""
140
- # [END v2PerformanceAlertTrigger]
148
+ # [END v2PerformanceAlertTrigger]
141
149
# [START v2PerformanceEventPayload]
142
150
# Construct a helpful message to send to Discord.
143
151
app_id = event .app_id
@@ -159,8 +167,9 @@ def post_performance_alert_to_discord(
159
167
160
168
try :
161
169
# [START v2SendPerformanceAlertToDiscord]
162
- response = post_message_to_discord ("App Performance Bot" , message ,
163
- DISCORD_WEBHOOK_URL .value ())
170
+ response = post_message_to_discord (
171
+ "App Performance Bot" , message , DISCORD_WEBHOOK_URL .value ()
172
+ )
164
173
if response .ok :
165
174
print (
166
175
f"Posted Firebase Performance alert { perf .event_name } to Discord."
@@ -174,4 +183,6 @@ def post_performance_alert_to_discord(
174
183
f"Unable to post Firebase Performance alert { perf .event_name } to Discord." ,
175
184
error ,
176
185
)
186
+
187
+
177
188
# [END v2Alerts]
0 commit comments