Skip to content

Instantly share code, notes, and snippets.

@chinsyo
Forked from waylybaye/index.js
Created March 10, 2022 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chinsyo/850f6cff02c0c1ca4cd449a61e67f969 to your computer and use it in GitHub Desktop.
Save chinsyo/850f6cff02c0c1ca4cd449a61e67f969 to your computer and use it in GitHub Desktop.
Send Notification using Telegram when new IAP is purchased
const functions = require('firebase-functions');
const TelegramBot = require('node-telegram-bot-api');
const token = "***"
const chatID = 1024 // your telegram id, you must first send a message to your bot
exports.notifyIAP = functions.analytics.event('in_app_purchase').onLog((event) => {
const purchaseValue = event.valueInUSD;
if (purchaseValue > 0) {
const bot = new TelegramBot(token, {polling: false});
return bot.sendMessage(chatID, "苹果宝到账: $" + (purchaseValue * 0.7).toFixed(2))
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment