This file contains 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
function handlePostback(sender_psid, postbackMessage){ | |
const {payload} = postbackMessage; | |
switch(payload){ | |
case "Welcome_Screen": welcome_option(sender_psid); break; | |
} | |
} | |
function welcome_option(sender_psid){ |
This file contains 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
app.post('/webhook', (req, res) => { | |
let body = req.body; | |
if (body.object === 'page') { | |
body.entry.forEach(function(entry) { | |
let webhook_event = entry.messaging[0]; | |
console.log(webhook_event); |
This file contains 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
<html> | |
<head> | |
<link href="./style.css" rel ="stylesheet" /> | |
</head> | |
<body> | |
<h1>OOps you are offline but please keep viewing the pics</h1> | |
<img src="./wallpaper.jpg" alt ="random-image" id="image"/> | |
</body> | |
</html> |
This file contains 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 urlToAdd =[ | |
'./style.css', | |
'./wallpaper.jpg', | |
'./offline.html' | |
] | |
self.addEventListener('install', (event) => { | |
event.waitUntill( | |
caches.open('SERVICE_WORKER') |
This file contains 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 urlToAdd =[ | |
'./style.css', | |
'./wallpaper.jpg', | |
'./offline.html' | |
] | |
self.addEventListener('install', (event) => { | |
event.waitUntill( | |
caches.open('SERVICE_WORKER') |
This file contains 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
self.addEventListener('activate', (event)=>{ | |
const whiteList =['SERVICE_WORKER','my-page']; | |
event.waitUntil( | |
caches.keys().then(function(cacheNames) { | |
return Promise.all( | |
cacheNames.map(function(cacheName) { | |
if (whiteList.indexOf(cacheName) === -1) { | |
return caches.delete(cacheName); | |
} |
This file contains 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
self.addEventListener('fetch', (event)=>{ | |
console.log('fetch event'); | |
if (event.request.method === 'GET' && event.request.headers.get('accept').includes('text/html')) { | |
event.respondWith( | |
fetch(event.request.url).catch(error => { | |
// Return the offline page | |
return caches.match('./offline.html'); | |
}) | |
); |
This file contains 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
self.addEventListener('activate', (event)=>{ | |
console.log('Service worker activated'); | |
}) |
This file contains 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 urlToAdd =[ | |
'./style.css', | |
'./wallpaper.jpg', | |
'./offline.html' | |
] | |
self.addEventListener('install', (event) => { | |
event.waitUntill( | |
caches.open('SERVICE_WORKER') |
This file contains 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
<html> | |
<head> | |
<link href="./style.css" rel ="stylesheet" /> | |
</head> | |
<body> | |
<h1> Service Workers</h1> | |
<img src="./wallpaper.jpg" alt ="random-image" id="image"/> | |
<script> | |
if('serviceWorker' in navigator){ | |
window.addEventListener('load', function() { |
NewerOlder