Skip to content

Instantly share code, notes, and snippets.

@lunhg
Last active July 16, 2018 16:25
Show Gist options
  • Save lunhg/963242e0fa49e7897d2a3a2e728041a1 to your computer and use it in GitHub Desktop.
Save lunhg/963242e0fa49e7897d2a3a2e728041a1 to your computer and use it in GitHub Desktop.
feathers client service + telegram promised bot service
<main class="container">
<h2 class="center-text">Bot</h2>
<script async src="https://telegram.org/js/telegram-widget.js?4" data-telegram-login="<Bot username terminated with 'bot'>" data-size="large" data-onauth="onTelegramAuth(user).then(function(res){console.log(res)})" data-request-access="write"></script>
<footer>
</main>
<script type="text/javascript">
console.log("Loading feathers client...")
var app = window.app = feathers();
var rest = feathers.rest('http://<my registered bot domain that must not be you localhost machine but a DNS one>');
app.configure(rest.fetch(window.fetch));
console.log("done");
function onRadar(user){
console.log(user)
let clone = {}
let p = ['id', 'first_name', 'last_name', 'auth_date', 'hash']
for(let i in p) {
if (p[i] === 'id') {
clone['telegramId'] = user[p[i]]
} else {
clone[p[i]] = user[p[i]]
}
}
return app.service('users').create(clone)
}
function onTelegramAuth(user) {
return onRadar(user)
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment