Skip to content

Instantly share code, notes, and snippets.

Avatar
🔥
Better Together

Jirawat Karanwittayakarn jirawatee

🔥
Better Together
View GitHub Profile
@jirawatee
jirawatee / richmenu.js
Last active May 28, 2021
Display Rich Menu to match the user's device language
View richmenu.js
const functions = require("firebase-functions");
const request = require("request-promise");
const LINE_MESSAGING_API = "https://api.line.me/v2/bot";
const LINE_HEADER = {
"Content-Type": "application/json",
Authorization: "Bearer YOUR-CHANNEL-ACCESS-TOKEN"
};
exports.LineBot = functions.https.onRequest(async (req, res) => {
View share1.js
// ต.ย รองรับการเปิด LIFF ทั้งในแอป LINE และ External browser
await liff.init({ liffId: "YOUR-LIFF-ID" })
if (liff.isLoggedIn()) {
// Login แล้วจ้า
} else {
liff.login()
}
View share2.js
// ต.ย ข้อความแบบ text จำนวน 2 bubbles
const result = await liff.shareTargetPicker([
{
"type": "text",
"text": "Hello World!"
},
{
"type": "text",
"text": "Messages from Share Target Picker"
}
View share3.js
if (result) {
// ผู้ใช้งานได้กดแชร์ข้อความ แต่จะสำเร็จหรือไม่ให้ดูที่ ${result.status}
alert(`[${result.status}] Message sent!`)
} else {
// ผู้ใช้งานกดปิดหน้า ShareTargetPicker หรือใช้แอป LINE เวอร์ชันต่ำกว่า 10.10.1
// ใช้ liff.getLineVersion() เพื่อดึงเลขเวอร์ชันจากแอป LINE ของผู้ใช้
const [majorVer, minorVer, patchVer] = (liff.getLineVersion() || "").split('.');
// alert ในกรณที่ใช้งาน LIFF ใน external browser ค่า minorVer จะเป็น undefined
@jirawatee
jirawatee / storage5.html
Last active Apr 27, 2021
Full source code
View storage5.html
<!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>Listing files in Cloud Storage for Firebase</title>
<link rel="shortcut icon" href="favicon.ico">
<style>
ul { list-style-type: none; padding:0 }
li { float: left; width:200px; height:232px; margin:8px; text-align:center; border:1px solid #ddd }
@jirawatee
jirawatee / storage4.html
Last active Jun 27, 2020
Share Target Picker
View storage4.html
<script>
function shareMsg(i, thumbUrl) {
// Ensure before calling shareTargetPicker()
if (confirm(`Share photo ${i}?`)) {
// Get original image from Image Resizes of Firebase Extentions
const origitalUrl = thumbUrl.replace('%2Fthumbs', '').replace('_200x200', '')
// Call Share Target Picker feature
liff.shareTargetPicker([
View storage3.html
<script src="https://static.line-scdn.net/liff/edge/2/sdk.js"></script>
<script>
async function main() {
// LIFF Initialize
await liff.init({ liffId: "LIFF-ID" })
// Support external browser openning
if (liff.isLoggedIn()) {
// Get user profile from LINE
const profile = await liff.getProfile()
@jirawatee
jirawatee / storage2.html
Last active Jun 27, 2020
Get file list from Cloud Storage
View storage2.html
<script>
async function getImageList(profile) {
// Define reference path in Cloud Storage for Firebase
const storage = firebase.storage()
const storageRef = storage.ref()
const listRef = storageRef.child(`photos/${profile.userId}/thumbs`)
// Get file list
let listImage = await listRef.listAll()
@jirawatee
jirawatee / storage.html
Last active Apr 19, 2021
Template for storage listing
View storage.html
<!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>Listing files in Cloud Storage for Firebase</title>
<link rel="shortcut icon" href="favicon.ico">
<style>
ul { list-style-type: none; padding:0 }
li { float: left; width:200px; height:232px; margin:8px; text-align:center; border:1px solid #ddd }
@jirawatee
jirawatee / uploadPhoto.js
Last active Jul 7, 2021
Resize image by Firebase Extensions - 5
View uploadPhoto.js
const functions = require('firebase-functions')
const request = require('request-promise')
const admin = require('firebase-admin')
const UUID = require('uuid-v4')
const path = require('path')
const os = require('os')
const fs = require('fs')
admin.initializeApp()
const LINE_MESSAGING_API = 'https://api.line.me/v2/bot'