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
exports.finalScore = functions.region(region).pubsub | |
.schedule('02 of jun 04:00') | |
.timeZone('Asia/Bangkok') | |
.onRun(async context => { | |
// ดึงผลการแข่งขันล่าสุด | |
let result = await admin.database().ref('ucl/score').once('value'); | |
broadcast(`จบการแข่งขัน\n${result.val()}`); // ส่งข้อความหาทุกคนที่เป็น friend | |
}); |
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
exports.liveScore = functions.region(region).runWith(runtimeOpts) | |
.database.ref('ucl/score') | |
.onWrite(async (change, context) => { | |
let latest = change.after.val(); // ดึงค่าล่าสุดหลังการอัพเดทของ score ออกมา | |
// ดึงข้อมูลผู้ใช้ที่ subscribe ทั้งหมด | |
let userIds = await admin.database().ref('ucl/uid').once('value') | |
Object.keys(userIds.val()).forEach(userId => { |
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
exports.logoDetection = functions.region(region).runWith(runtimeOpts) | |
.storage.object() | |
.onFinalize(async (object) => { | |
const fileName = object.name // ดึงชื่อไฟล์มา | |
const userId = fileName.split('.')[0] // แยกชื่อไฟล์ออกมา ซึ่งมันก็คือ userId | |
// ทำนายโลโกที่อยู่ในภาพด้วย Cloud Vision API | |
const [result] = await client.logoDetection(`gs://${object.bucket}/${fileName}`); | |
const logos = result.logoAnnotations; | |
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
const doImage = async (event) => { | |
const path = require("path"); | |
const os = require("os"); | |
const fs = require("fs"); | |
const UUID = require("uuid-v4"); | |
// กำหนด URL ในการไปดึง binary จาก LINE กรณีผู้ใช้อัพโหลดภาพมาเอง | |
let url = `${LINE_CONTENT_API}/${event.message.id}/content`; | |
// ตรวจสอบว่าภาพนั้นถูกส่งมจาก LIFF หรือไม่ |
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
exports.UCL = functions.region(region).runWith(runtimeOpts) | |
.https.onRequest(async (req, res) => { | |
let event = req.body.events[0] | |
switch (event.type) { | |
case 'message': | |
if (event.message.type === 'image') { | |
// [8.3] | |
} else if (event.message.type === 'text' && event.message.text === 'subscribe') { | |
// [8.2] | |
} else { |
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
// Push Message | |
const push = (userId, msg, quickItems) => { | |
return request.post({ | |
headers: LINE_HEADER, | |
uri: `${LINE_MESSAGING_API}/push`, | |
body: JSON.stringify({ | |
to: userId, | |
messages: [{ type: "text", text: msg, quickReply: quickItems }] | |
}) | |
}) |
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
const functions = require('firebase-functions'); | |
const request = require("request-promise"); | |
const admin = require('firebase-admin'); | |
admin.initializeApp(); | |
const region = 'asia-east2'; | |
const runtimeOpts = { | |
timeoutSeconds: 4, | |
memory: "2GB" |
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
const functions = require("firebase-functions"); | |
const request = require("request-promise"); | |
const OPENWEATHER_APPID = "<YOUR-OPEN-WEATHER-APP-ID>"; | |
const LINE_MESSAGING_API = "https://api.line.me/v2/bot/message"; | |
const LINE_UID = "<YOUR-LINE-ID>"; | |
const LINE_HEADER = { | |
"Content-Type": "application/json", | |
Authorization: |

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
const functions = require('firebase-functions'); | |
const request = require('request-promise'); | |
const LINE_MESSAGING_API = 'https://api.line.me/v2/bot/message'; | |
const LINE_HEADER = { | |
'Content-Type': 'application/json', | |
'Authorization': `Bearer xxxxx` | |
}; | |
exports.LineBotBroadcast = functions.https.onRequest((req, res) => { |