Skip to content

Instantly share code, notes, and snippets.

@pawelgagorowski pawelgagorowski/index.js
Last active Aug 3, 2019

Embed
What would you like to do?
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");
});
@himangipatel

This comment has been minimized.

Copy link

commented Aug 2, 2019

did you get any solution? I am facing the same issue

@pawelgagorowski

This comment has been minimized.

Copy link
Owner Author

commented Aug 3, 2019

hi there, first of all, the code is ok - it was somewhere in the action's configuration - don't know where exactly.
Maybe simply an action can not tolerate changing the configuration while the application is running - what I can advise you is to create a new action and carefully enter the data. Let me know if that helped..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.