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 / firebase.json
Created January 28, 2020 12:02
Configuration in Firebase Hosting
{
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
]
},
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
@jirawatee
jirawatee / quickreply.json
Last active March 16, 2020 02:29
Sample in how to add LINE Quick Reply as JSON in Dialogflow
{
"line": {
"type": "flex",
"altText": "Rabbit LINE Pay",
"contents": {
"type": "carousel",
"contents": [
{
"type": "bubble",
"hero": {
@jirawatee
jirawatee / liff-init.html
Last active November 27, 2019 03:15
Initialize in LIFF
<script>
liff.init({ liffId: "1234567890-XXXXXXXXX" }, () => {
if (liff.isLoggedIn()) {
// ขั้นตอน 4.4 รออยู่
} else {
liff.login();
}
}, err => console.error(err.code, error.message));
</script>
@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 / index.html
Created October 26, 2019 18:23
LIFF v2 - Query String
<script>
const medium = 'https://medium.com/linedevth/';
const queryString = decodeURIComponent(window.location.search).replace("?liff.state=", "");
const params = new URLSearchParams(queryString);
const id = params.get('id');
if (id != null && id != '') {
window.location.assign(medium + id);
} else {
window.location.assign("https://developers.line.biz");
}
@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 = "[email protected]";
const serviceAccount = {
"type": "service_account",
"project_id": "line-bot",
@jirawatee
jirawatee / dialogflowFirebaseFulfillment.js
Last active October 5, 2019 07:48
Appointment code in dialogflowFirebaseFulfillment function
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
function confirmAppointment(agent) {
// ...
}
function makeAppointment(agent) {
const appointment_type = agent.parameters.AppointmentType;
const dateTimeStart = new Date(
@jirawatee
jirawatee / createCalendarEvent.js
Last active October 5, 2019 01:52
Creating Calendar Event script
function createCalendarEvent(dateTimeStart, dateTimeEnd, appointment_type) {
return new Promise((resolve, reject) => {
calendar.events.list({
auth: serviceAccountAuth, // List events for time period
calendarId: calendarId,
timeMin: dateTimeStart.toISOString(),
timeMax: dateTimeEnd.toISOString()
}, (err, calendarResponse) => {
// Check if there is a event already on the Calendar
if (err || calendarResponse.data.items.length > 0) {
@jirawatee
jirawatee / headers.json
Created August 4, 2019 12:07
LINE Webhook Headers
{
"host": "xxxxx.cloudfunctions.net",
"user-agent": "LineBotWebhook/1.0",
"transfer-encoding": "chunked",
"accept": "*/*",
"content-type": "application/json;charset=UTF-8",
"forwarded": "for=\"xxx.xxx.xxx.xxx\";proto=https",
"function-execution-id": "fh8e8wtjjumk",
"x-appengine-city": "minato city",
"x-appengine-citylatlong": "xxx,yyy",