2121 crashlytics_fn ,
2222 performance_fn ,
2323)
24+
2425# [END v2import]
2526
2627import requests
2728
2829DISCORD_WEBHOOK_URL = params .SecretParam ("DISCORD_WEBHOOK_URL" )
2930
3031
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 :
3335 """Posts a message to Discord with Discord's Webhook API.
3436
3537 Params:
@@ -58,9 +60,10 @@ def post_message_to_discord(bot_name: str, message_body: str,
5860# [START v2CrashlyticsAlertTrigger]
5961@crashlytics_fn .on_new_fatal_issue_published (secrets = ["DISCORD_WEBHOOK_URL" ])
6062def post_fatal_issue_to_discord (
61- event : crashlytics_fn .CrashlyticsNewFatalIssueEvent ) -> None :
63+ event : crashlytics_fn .CrashlyticsNewFatalIssueEvent ,
64+ ) -> None :
6265 """Publishes a message to Discord whenever a new Crashlytics fatal issue occurs."""
63- # [END v2CrashlyticsAlertTrigger]
66+ # [END v2CrashlyticsAlertTrigger]
6467 # [START v2CrashlyticsEventPayload]
6568 # Construct a helpful message to send to Discord.
6669 app_id = event .app_id
@@ -78,8 +81,9 @@ def post_fatal_issue_to_discord(
7881
7982 try :
8083 # [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+ )
8387 if response .ok :
8488 print (
8589 f"Posted fatal Crashlytics alert { issue .id } for { app_id } to Discord."
@@ -97,11 +101,13 @@ def post_fatal_issue_to_discord(
97101
98102# [START v2AppDistributionAlertTrigger]
99103@app_distribution_fn .on_new_tester_ios_device_published (
100- secrets = ["DISCORD_WEBHOOK_URL" ])
104+ secrets = ["DISCORD_WEBHOOK_URL" ]
105+ )
101106def post_new_udid_to_discord (
102- event : app_distribution_fn .NewTesterDeviceEvent ) -> None :
107+ event : app_distribution_fn .NewTesterDeviceEvent ,
108+ ) -> None :
103109 """Publishes a message to Discord whenever someone registers a new iOS test device."""
104- # [END v2AppDistributionAlertTrigger]
110+ # [END v2AppDistributionAlertTrigger]
105111 # [START v2AppDistributionEventPayload]
106112 # Construct a helpful message to send to Discord.
107113 app_id = event .app_id
@@ -115,8 +121,9 @@ def post_new_udid_to_discord(
115121
116122 try :
117123 # [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+ )
120127 if response .ok :
121128 print (
122129 f"Posted iOS device registration alert for { app_dist .tester_email } to Discord."
@@ -135,9 +142,10 @@ def post_new_udid_to_discord(
135142# [START v2PerformanceAlertTrigger]
136143@performance_fn .on_threshold_alert_published (secrets = ["DISCORD_WEBHOOK_URL" ])
137144def post_performance_alert_to_discord (
138- event : performance_fn .PerformanceThresholdAlertEvent ) -> None :
145+ event : performance_fn .PerformanceThresholdAlertEvent ,
146+ ) -> None :
139147 """Publishes a message to Discord whenever a performance threshold alert is fired."""
140- # [END v2PerformanceAlertTrigger]
148+ # [END v2PerformanceAlertTrigger]
141149 # [START v2PerformanceEventPayload]
142150 # Construct a helpful message to send to Discord.
143151 app_id = event .app_id
@@ -159,8 +167,9 @@ def post_performance_alert_to_discord(
159167
160168 try :
161169 # [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+ )
164173 if response .ok :
165174 print (
166175 f"Posted Firebase Performance alert { perf .event_name } to Discord."
@@ -174,4 +183,6 @@ def post_performance_alert_to_discord(
174183 f"Unable to post Firebase Performance alert { perf .event_name } to Discord." ,
175184 error ,
176185 )
186+
187+
177188# [END v2Alerts]
0 commit comments