Created
September 23, 2020 12:04
-
-
Save kichiemon/57b8fdfc5ae19e30b6089ca73d0ba0bc to your computer and use it in GitHub Desktop.
アプリ内課金の発生時にSlack通知する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as functions from "firebase-functions"; | |
import * as request from "request"; | |
exports.sendSlackMessageOnPurchaseCoin = functions | |
.region("asia-northeast1") | |
.analytics.event("in_app_purchase_coins") | |
.onLog((event) => sentMessageToSlack(event, "コインが購入されました")); | |
exports.sendSlackMessageOnPurchaseSubscription = functions | |
.region("asia-northeast1") | |
.analytics.event("in_app_purchase_subscription") | |
.onLog((event) => sentMessageToSlack(event, "サブスクが購入されました")); | |
const sentMessageToSlack = ( | |
event: functions.analytics.AnalyticsEvent, | |
message: string | |
): request.Request => { | |
const url = functions.config().slack.url; | |
const user = event.user; | |
const purchaseValue = event.valueInUSD; // Amount of the purchase in USD. | |
const userLanguage = user?.deviceInfo.userDefaultLanguage; // The user language in language-country format. | |
const screenName = event.params["firebase_screen_class"]; | |
return request.post(url, { | |
json: { | |
text: | |
`${message}💰 $${purchaseValue} \n` + | |
"```\n" + | |
`at time: ${event.logTime} \n` + | |
`lang: ${userLanguage} \n` + | |
`country: ${event.user?.geoInfo.country} \n` + | |
`model: ${event.user?.deviceInfo?.mobileModelName} \n` + | |
`appId: ${event.user?.appInfo?.appId} \n` + | |
`appVersion: ${event.user?.appInfo?.appVersion} \n` + | |
`screen: ${screenName} \n` + | |
"```\n", | |
}, | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment