Skip to content

Instantly share code, notes, and snippets.

@geoffmomin
Forked from pawelgagorowski/index.js
Created October 9, 2019 06:36
Show Gist options
  • Save geoffmomin/ebb4dd5c65c0c4f7d9edbd4c3e227b10 to your computer and use it in GitHub Desktop.
Save geoffmomin/ebb4dd5c65c0c4f7d9edbd4c3e227b10 to your computer and use it in GitHub Desktop.
error 401 - no authorization
'use strict';
const AWS = require('aws-sdk');
AWS.config.update({ region: 'us-east-1' })
const { dialogflow, SignIn } = require('actions-on-google');
const app = dialogflow();
const request = require('request-promise')
const rp = require('request-promise');
// Start SignIn Intention is assigned to the 'sign in' Training phrase
app.intent('Start SignIn', (conv) => {
conv.ask(new SignIn('To get your account details'));
});
// Get SignIn Intention is assigned to the 'Google Assistant Sign In' action
app.intent('Get SignIn', (conv, params, signin) => {
// tutaj występuje Error 401 - brak autoryzacji
if (signin.status === 'OK') {
const accessToken = conv.body.originalDetectIntentRequest.payload.user.accessToken;
const options = {
method: 'GET',
uri: 'https://dev-6cnet9rr.eu.auth0.com/userinfo',
headers: {
authorization: 'Bearer ' + accessToken
}
}
return rp(options).then(function (body) {
let data = JSON.parse(body);
conv.ask(`I got your account details, ${data.name}. What do you want to do next?`);
}).catch(function(err) {
conv.ask(`Sorry, but I could not sign you in.`);
})
} else {
conv.ask(`Sorry, but there was an error, and I could not sign you in.`);
}
});
app.intent('Default Welcome Intent', conv => {
conv.ask("Hello from Welcome Intent, udalo sie");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment