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.html
Last active April 2, 2024 17:14
LIFF Share Target Picker
<!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>
@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 / thaiid.js
Created February 22, 2022 15:18
Extract data from Thai ID card
const functions = require("firebase-functions");
exports.myCallable = functions.https.onCall(async (data, context) => {
// รับค่า base64 ที่ได้จาก LIFF app โดย split เพื่อตัด type ที่นำหน้าออก
const base64 = data.base64.split(",")
// import และ initial ตัว lib ของ Cloud Vision API
const vision = require('@google-cloud/vision')
const client = new vision.ImageAnnotatorClient()
@jirawatee
jirawatee / dialogflow-firestore.js
Last active February 21, 2024 23:42
Dialogflow integrate with Cloud Functions - Cloud Firestore
"use strict";
const functions = require("firebase-functions");
const { WebhookClient } = require("dialogflow-fulfillment");
const { Card, Suggestion } = require("dialogflow-fulfillment");
const admin = require("firebase-admin");
admin.initializeApp({
credential: admin.credential.applicationDefault(),
databaseURL: 'https://<YOUR-PROJECT-ID>.firebaseio.com'
@jirawatee
jirawatee / confirmAppointment.js
Created October 5, 2019 02:23
Appointment confirmation
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
function confirmAppointment(agent) {
const dateTimeStart = new Date(
Date.parse(agent.parameters.date.split('T')[0] + 'T' + agent.parameters.time.split('T')[1])
);
const appointmentTimeString = dateTimeStart.toLocaleString(
'en-US',
{ weekday: 'short', day: 'numeric', month: 'short', hour: 'numeric', minute: 'numeric', timeZone: 'Asia/Bangkok' }
);
@jirawatee
jirawatee / appointment.js
Created October 5, 2019 02:09
Appointment Scheduler in Fulfillment
"use strict";
const { WebhookClient, Payload } = require("dialogflow-fulfillment");
const functions = require("firebase-functions");
const { google } = require('googleapis');
const calendarId = "88888888888888@group.calendar.google.com";
const serviceAccount = {
"type": "service_account",
"project_id": "line-bot",
@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 / liffv2.html
Last active November 27, 2022 05:11
LIFF v2 Sample Code
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My LIFF v2</title>
<style>
#pictureUrl { display: block; margin: 0 auto }
</style>
</head>
<body>
@jirawatee
jirawatee / liff-login.html
Last active August 27, 2022 18:17
How to hack LIFF Login in external browser
<!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 }
@jirawatee
jirawatee / FlexMessage.js
Created April 2, 2019 06:27
Flex Message in LINE Messaging API
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 <CHANNEL-ACCESS-TOKEN>"
};
exports.AdvanceMessage = functions.https.onRequest((req, res) => {