Skip to content

Instantly share code, notes, and snippets.

View jirawatee's full-sized avatar
🔥
Better Together

Jirawat Karanwittayakarn jirawatee

🔥
Better Together
View GitHub Profile
@jirawatee
jirawatee / index.js
Last active February 6, 2025 04:28
x-line-signature validation
const functions = require("firebase-functions");
const request = require("request-promise");
const LINE_HEADER = {
"Content-Type": "application/json",
Authorization: "Bearer YOUR-CHANNEL-ACCESS-TOKEN"
}
const LINE_MESSAGING_API = "https://api.line.me/v2/bot/message";
// 1. Copy your Channel Secret from LINE Developers Console then paste is as a value
const LINE_CHANNEL_SECRET = "YOUR-CHANNEL-SECRET";
@jirawatee
jirawatee / richmenu.html
Created July 15, 2019 12:23
Sign in before link Rich menu
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rich Menu Demo</title>
<style>
body { margin: 0; padding: 20px }
input { width: 90%; height: 32px; display: block; margin: 0 auto }
input[type=text], input[type=password] { padding: 16px; font-size: 24px }
@jirawatee
jirawatee / richmenu.js
Last active July 4, 2023 12:02
Link Rich Menu
const functions = require("firebase-functions");
const request = require("request-promise");
exports.RichMenu = functions.https.onRequest((req, res) => {
// เปิดทางให้ Ajax จาก LIFF มา Request
res.header('Access-Control-Allow-Origin', '*')
let richMenuId1 = 'YOUR-RICH-MENU-ID-1';
let richMenuId2 = 'YOUR-RICH-MENU-ID-2';
@jirawatee
jirawatee / richmenu-creat.json
Last active January 26, 2025 05:53
Rich Menu JSON for creating
{
"size": {
"width": 2500,
"height": 843
},
"selected": true,
"name": "Rich Menu 1",
"chatBarText": "คลิกบอลที่ชอบ",
"areas": [
{
@jirawatee
jirawatee / index.js
Created May 29, 2019 07:27
UCL - Reply how to subscribe
...
} else if (event.message.type === 'text' && event.message.text === 'subscribe') {
// [8.2]
reply(event.replyToken, {
type: 'text',
text: 'กรุณายืนยันตัวตนด้วยการอัพโหลดรูปที่มีโลโกทีมที่คุณชื่นชอบ'
});
}
...
@jirawatee
jirawatee / index.js
Created May 29, 2019 07:26
UCL - Reply latest score
...
} else {
// [8.1]
// Firebase Realtime Database
let latest = await admin.database().ref('ucl/score').once('value')
reply(event.replyToken, { type: 'text', text: latest.val() })
// Cloud Firestore
/*
@jirawatee
jirawatee / index.js
Last active November 21, 2019 08:46
UCL - Postback
...
case 'postback': {
// [8.4]
let msg = 'ทีมที่คุณเลือกมันเข้ารอบมาชิง UCL ซะทีไหนเล่า ปั๊ดโถ่!';
let team = event.postback.data.split('=')[1].toLowerCase()
if (team.indexOf('liverpool') >= 0 || team.indexOf('tottenham') >= 0) {
// Firebase Realtime Database
await admin.database().ref('ucl/uid').child(event.source.userId).set(true)
@jirawatee
jirawatee / index.js
Last active May 27, 2019 21:36
Livescore in UCL by Cloud Firestore
exports.liveScore = functions.region(region).runWith(runtimeOpts)
.firestore.document('ucl/final')
.onWrite(async (change, context) => {
let latest = change.after.data().score; // ดึงค่าล่าสุดหลังจาก score อัพเดท
// ดึงข้อมูลผู้ใช้ที่ subscribe ทั้งหมด
let userIds = await admin.firestore().doc('ucl/final').collection('uid').get()
userIds.forEach(doc => {
@jirawatee
jirawatee / index.js
Last active May 27, 2019 20:47
Reply by Flex Message
reply(event.replyToken, {
"type": "flex",
"altText": "Flex Message",
"contents": {
"type": "bubble",
"direction": "ltr",
"hero": {
"type": "image",
"url": "https://4.bp.blogspot.com/-j0d1WQiF-iU/XGxYdwp9C8I/AAAAAAAAUME/8IbomE8q9TUd3tUxWd5yV7-jz9YPVcxXACLcBGAs/s1600/Ucl19.jpg",
"size": "full",
@jirawatee
jirawatee / index.js
Created May 27, 2019 20:15
Broadcast final score in UCL by Cloud Firestore
exports.finalScore = functions.region(region).pubsub
.schedule('02 of jun 04:00')
.timeZone('Asia/Bangkok')
.onRun(async context => {
// ดึงผลการแข่งขันล่าสุดจาก Firestore
let result = await admin.firestore().doc('ucl/final').get()
broadcast(`จบการแข่งขัน\n${result.data().score}`); // ส่งข้อความให่ทุกคนที่เป็น friend
});