14
14
* limitations under the License.
15
15
*/
16
16
// [START v2import]
17
+
17
18
const {
18
19
onNewFatalIssuePublished,
19
20
} = require ( "firebase-functions/v2/alerts/crashlytics" ) ;
21
+ const {
22
+ onNewTesterIosDevicePublished,
23
+ } = require ( "firebase-functions/v2/alerts/appDistribution" ) ;
20
24
const logger = require ( "firebase-functions/logger" ) ;
21
25
// [END v2import]
22
26
@@ -56,13 +60,14 @@ async function postMessageToDiscord(botName, messageBody) {
56
60
* to Discord whenever a new fatal issue occurs.
57
61
*/
58
62
// [START v2CrashlyticsAlertTrigger]
59
- exports . postmessagetodiscord = onNewFatalIssuePublished ( async ( event ) => {
63
+ exports . postfatalissuetodiscord = onNewFatalIssuePublished ( async ( event ) => {
60
64
// [END v2CrashlyticsAlertTrigger]
61
65
// [START v2CrashlyticsEventPayload]
62
66
// construct a helpful message to send to Discord
67
+ const appId = event . appId ;
63
68
const { id, title, subtitle, appVersion} = event . data . payload . issue ;
64
69
const message = `
65
- 🚨 New fatal issue in version ${ appVersion } 🚨
70
+ 🚨 New fatal issue for ${ appId } in version ${ appVersion } 🚨
66
71
67
72
**${ title } **
68
73
@@ -77,7 +82,7 @@ id: \`${id}\`
77
82
const response = await postMessageToDiscord ( "Crashlytics Bot" , message ) ;
78
83
if ( response . ok ) {
79
84
logger . info (
80
- `Posted fatal Crashlytics alert ${ id } to Discord` ,
85
+ `Posted fatal Crashlytics alert ${ id } for ${ appId } to Discord` ,
81
86
event . data . payload ,
82
87
) ;
83
88
} else {
@@ -86,7 +91,49 @@ id: \`${id}\`
86
91
// [END v2SendToDiscord]
87
92
} catch ( error ) {
88
93
logger . error (
89
- `Unable to post fatal Crashlytics alert ${ id } to Discord` ,
94
+ `Unable to post fatal Crashlytics alert ${ id } for ${ appId } to Discord` ,
95
+ error ,
96
+ ) ;
97
+ }
98
+ } ) ;
99
+
100
+ /**
101
+ * function triggered by App Distribution that publishes a message
102
+ * to Discord whenever a new iOS tester device is registered.
103
+ */
104
+ // [START v2AppDistributionAlertTrigger]
105
+ exports . postnewduuidtodiscord = onNewTesterIosDevicePublished ( async ( event ) => {
106
+ // [END v2AppDistributionAlertTrigger]
107
+ // [START v2AppDistributionEventPayload]
108
+ // construct a helpful message to send to Discord
109
+ const appId = event . appId ;
110
+ const {
111
+ testerDeviceIdentifier,
112
+ testerDeviceModelName,
113
+ testerEmail,
114
+ testerName,
115
+ } = event . data . payload ;
116
+ const message = `
117
+ 📱 New iOS device registered by ${ testerName } <${ testerEmail } > for ${ appId }
118
+
119
+ UDID **${ testerDeviceIdentifier } ** for ${ testerDeviceModelName }
120
+ ` ;
121
+ // [END v2AppDistributionEventPayload]
122
+
123
+ try {
124
+ // [START v2SendNewTesterIosDeviceToDiscord]
125
+ const response = await postMessageToDiscord ( "AppDistribution Bot" , message ) ;
126
+ if ( response . ok ) {
127
+ logger . info (
128
+ `Posted iOS device registration alert for ${ testerEmail } to Discord` ,
129
+ ) ;
130
+ } else {
131
+ throw new Error ( response . error ) ;
132
+ }
133
+ // [END v2SendNewTesterIosDeviceToDiscord]
134
+ } catch ( error ) {
135
+ logger . error (
136
+ `Unable to post iOS device registration for ${ testerEmail } to Discord` ,
90
137
error ,
91
138
) ;
92
139
}
0 commit comments