Last active
September 23, 2020 11:52
-
-
Save gijsepping/c9cf1ea32923f0af6a1519bf0dc70e8f to your computer and use it in GitHub Desktop.
Roam zend block to zapier zap
This file contains hidden or 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
document.addEventListener('input', function(e){ | |
if ('_webhookHook' in window) { | |
setTimeout(function(){ window._webhookHook(e); }, 0); | |
} | |
}); | |
window._webhookHook = async function(e) { | |
// logging | |
window._e = e; | |
// exit if not target | |
var elem = e.target | |
console.log(elem.value); | |
var res = elem.value.match(/#zap/g); | |
if(res){ | |
elem.value = elem.value.replace('#zap', '#really-done'); | |
(async () => { | |
const rawResponse = await fetch('https://hooks.zapier.com/hooks/catch/2323232323236/', { | |
method: 'POST', | |
headers: { | |
'Accept': 'application/json' | |
}, | |
body: JSON.stringify({zap: 'teams', message: elem.value}) | |
}); | |
const content = await rawResponse.json(); | |
console.log(content); | |
})(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment