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
let prefix = `https://firebasestorage.googleapis.com/v0/b/${bucket.name}/o` | |
let suffix = `alt=media&token=${uuid}` | |
return { | |
original: `${prefix}/${encodeURIComponent(file[0].name)}?${suffix}`, | |
thumb: `${prefix}/photos${encodeURIComponent(`/${event.source.userId}/thumbs/${event.timestamp}_200x200.jpg`)}?${suffix}` | |
} |
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') | |
// สำหรับการเข้าถึง Cloud Storage | |
const admin = require('firebase-admin') | |
admin.initializeApp() | |
// สำหรับสร้าง public url ใน Cloud Storage | |
const UUID = require('uuid-v4') |
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 reply = (replyToken, payload) => { | |
request.post({ | |
uri: `${LINE_MESSAGING_API}/message/reply`, | |
headers: LINE_HEADER, | |
body: JSON.stringify({ | |
replyToken: replyToken, | |
messages: [payload] | |
}) | |
}) | |
} |
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 reply = (replyToken, payload) => { | |
request.post({ | |
uri: `${LINE_MESSAGING_API}/message/reply`, | |
headers: LINE_HEADER, | |
body: JSON.stringify({ | |
replyToken: replyToken, | |
messages: [payload] | |
}) | |
}) | |
} |
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 upload = async (event) => { | |
// ดาวน์โหลด binary จาก LINE | |
const LINE_CONTENT_API = 'https://api-data.line.me/v2/bot/message' | |
let url = `${LINE_CONTENT_API}/${event.message.id}/content` | |
let buffer = await request.get({ | |
headers: LINE_HEADER, | |
uri: url, | |
encoding: null // กำหนดเป็น null เพื่อให้ได้ binary ที่สมบูรณ์ | |
}) |
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.uploadPhoto = functions.https.onRequest(async (req, res) => { | |
let event = req.body.events[0] | |
if (event.type === 'message' && event.message.type === 'image') { | |
// เรียกฟังก์ชัน upload เมื่อเข้าเงื่อนไข | |
let urls = await upload(event) | |
// reply ตัว URL ที่ได้กลับไปยังห้องแชท | |
await reply(event.replyToken, { type: "text", text: urls }) | |
} | |
}) |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>LIFF - LINE Front-end Framework</title> | |
<style> | |
body { margin: 16px } | |
button, img { display: none; width: 40% } | |
button { padding: 16px } |
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 promiseA = () => new Promise(resolve => { | |
setTimeout(() => resolve("result of promiseA"), 2000) | |
}) | |
const promiseB = () => new Promise(resolve => { | |
setTimeout(() => resolve("result of promiseB"), 3000) | |
}) | |
const promiseC = () => new Promise(resolve => { | |
setTimeout(() => resolve("result of promiseC"), 1000) | |
}) |
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
{ | |
"line": { | |
"type": "flex", | |
"altText": "LIFF", | |
"contents": { | |
"type": "carousel", | |
"contents": [ | |
{ | |
"type": "bubble", | |
"body": { |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0,viewport-fit=cover"> | |
<title>My LIFF App</title> | |
<style> | |
body { padding: 256px } | |
button { display: none; width: 50%; padding: 16px 0; margin: 16px auto } | |
</style> |