Asking for account linking in Google Actions v2 fails "ReferenceError: SignIn is not defined" - actions-on-google

I'm migrating the code over and i can't get my account linking sign in process to work. After looking at the documentation and code i don't see any error in the way i'm calling SignIn().
I've also made sure to update action.json and add the v2 account linking stuff in there, and my app always had account linking working so the account linking section in the Console is up to date. I'm using Action SDK and not Dialogflow.
const {actionssdk} = require('actions-on-google');
const app = actionssdk({debug: true});
app.intent('actions.intent.MAIN', conv => {
conv.ask(new SignIn())
})
app.intent('actions.intent.SIGN_IN', (conv, input, signin) => {
if (signin.status === 'OK') {
const access = conv.user.access.token // possibly do something with access token
conv.ask('Great, thanks for signing in! What do you want to do next?')
} else {
conv.ask(`I won't be able to save your data, but what do you want to do next?`)
}
})
module.exports.assistant = app;
Logs:
ReferenceError: SignIn is not defined
at app.intent.conv (/usr/local/lucida/web/client-apps/src/routes/google_home.js:4:16)
at Function.<anonymous> (/usr/local/lucida/web/client-apps/node_modules/actions-on-google/dist/service/actionssdk/actionssdk.js:138:23)
at next (native)
at /usr/local/lucida/web/client-apps/node_modules/actions-on-google/dist/service/actionssdk/actionssdk.js:22:71
at __awaiter (/usr/local/lucida/web/client-apps/node_modules/actions-on-google/dist/service/actionssdk/actionssdk.js:18:12)
at Function.handler (/usr/local/lucida/web/client-apps/node_modules/actions-on-google/dist/service/actionssdk/actionssdk.js:85:16)
at Object.<anonymous> (/usr/local/lucida/web/client-apps/node_modules/actions-on-google/dist/assistant.js:55:32)
at next (native)
at /usr/local/lucida/web/client-apps/node_modules/actions-on-google/dist/assistant.js:22:71
at __awaiter (/usr/local/lucida/web/client-apps/node_modules/actions-on-google/dist/assistant.js:18:12)
at standard (/usr/local/lucida/web/client-apps/node_modules/actions-on-google/dist/assistant.js:51:41)
at /usr/local/lucida/web/client-apps/node_modules/actions-on-google/dist/framework/express.js:23:13
at omni (/usr/local/lucida/web/client-apps/node_modules/actions-on-google/dist/assistant.js:44:53)
at Layer.handle [as handle_request] (/usr/local/lucida/web/client-apps/node_modules/express/lib/router/layer.js:95:5)
at next (/usr/local/lucida/web/client-apps/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/usr/local/lucida/web/client-apps/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/usr/local/lucida/web/client-apps/node_modules/express/lib/router/layer.js:95:5)
at /usr/local/lucida/web/client-apps/node_modules/express/lib/router/index.js:281:22
at param (/usr/local/lucida/web/client-apps/node_modules/express/lib/router/index.js:354:14)
at param (/usr/local/lucida/web/client-apps/node_modules/express/lib/router/index.js:365:14)
at Function.process_params (/usr/local/lucida/web/client-apps/node_modules/express/lib/router/index.js:410:3)
at next (/usr/local/lucida/web/client-apps/node_modules/express/lib/router/index.js:275:10)

You should include SignIn when you import the library:
const {actionssdk, SignIn} = require('actions-on-google');

Related

SolidJS Create Resource - Uncaught Error in Promise

I'm new to SolidJS and I'm having a weird error with resources. Here is my code:
export const authUserResource = createResource(
() => axios.get<AuthUser>('/expense-tracker/api/oauth/user').then((res) => res.data)
);
export const MyComponent = () => {
const [data] = authUserResource;
createEffect(() => console.log('HasChecked', data.loading, data.error, data()));
return (
// ...
)
}
The intent of the API call is to retrieve data on the currently authenticated user, or to return a 401 if the user is not currently authenticated. My intent is to then redirect the user based on their authentication status.
Well, the API is called and it is returning a 401 because the user is not authenticated. All of this is expected. What is not behaving is the SolidJS resource.
If the API returns a 401, I would expect the SolidJS resource data to meet these conditions:
data.loading === false
data.error instanceof Error
data() === undefined
Instead, I am finding that it is still at these conditions, based on the console.log statement in the above code example:
data.loading === true
data.error === undefined
data() === undefined
I also get an "Uncaught Error in Promise" error message in the browser JS console.
I'm hoping to figure out what I am doing wrong here to make the resource correctly handle the error so that I can gracefully handle this in my application.

Microsoft Graph API - AuthenticationError when accessing mail

I'm currently implementing an Outlook Add-In that should access certain mail fields. So I setup a starter project and set the delegated Mail.Read permission in the Microsoft Azure Active Directory settings and added it to my scope configuration.
However, when I send the request for
graph.microsoft.com/v1.0/me/messages/
I get this as a response:
Error: Bad Request
at IncomingMessage.<anonymous> (C:\Users\zz\public\javascripts\odata-helper.js:53:29)
at IncomingMessage.emit (events.js:322:22)
at endReadableNT (_stream_readable.js:1187:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
code: 400,
bodyCode: 'AuthenticationError',
bodyMessage: 'Error authenticating with resource'
}
I don't understand why this error appears since the user authentication works and I don't have any problems with other Graph Endpoints (e.g. retrieving a list of my OneDrive files from /me/drive/root/children)
I am using this as a codebase:
https://learn.microsoft.com/en-us/office/dev/add-ins/develop/create-sso-office-add-ins-nodejs
I didn't reproduce your issue and graph.microsoft.com/v1.0/me/messages works fine in the sample you shared.
Please refer to my configuration.
In addition to the configuration mentioned in the documentation, I also made the following changes.
Add a Mail.Read Delegated permission in Azure AD app.
Modify the Microsoft Graph endpoint in app.js file. Please note I'm querying the subject property of messages. So I modified the two places: $select=subject&$top=10 and itemNames.push(item['subject']).
app.get('/getuserdata', async function(req, res, next) {
const graphToken = req.get('access_token');
const graphData = await getGraphData(graphToken, "/me/messages", "?$select=subject&$top=10");
if (graphData.code) {
next(createError(graphData.code, "Microsoft Graph error " + JSON.stringify(graphData)));
}
else
{
const itemNames = [];
const oneDriveItems = graphData['value'];
for (let item of oneDriveItems){
itemNames.push(item['subject']);
}
res.send(itemNames)
}
}
In the add-in manifest file "manifest\manifest_local.xml", I add a scope "Mail.Read".
<WebApplicationInfo>
<Id>a7eb1d00-f724-4799-8a46-809f2dba63f8</Id>
<Resource>api://localhost:44355/a7eb1d00-f724-4799-8a46-809f2dba63f8</Resource>
<Scopes>
<Scope>Files.Read.All</Scope>
<Scope>profile</Scope>
<Scope>Mail.Read</Scope>
</Scopes>
</WebApplicationInfo>
In the file routes\authRoute.js, I add the 'Mail.Read' like this:
else {
const [schema, jwt] = authorization.split(' ');
const formParams = {
client_id: process.env.CLIENT_ID,
client_secret: process.env.CLIENT_SECRET,
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
assertion: jwt,
requested_token_use: 'on_behalf_of',
scope: ['Files.Read.All', 'Mail.Read'].join(' ')
};
These are all the configurations and I can get the subject of messages in Microsoft Word addin:

Paypal sandbox post error 401 (Unauthorized)

enter image description hereI have been following a tutorial for a paypal sandbox using react-paypal-express-checkout and have followed it exactly, but when I try to open the paypal window it closes instantly and throws this error.
Photo:Photo Here
Text:
http.js:147 POST https://www.sandbox.paypal.com/v1/payment-experience/web-profiles 401 (Unauthorized)
types.js:121 Uncaught Error: Request to post https://www.sandbox.paypal.com/v1/payment-experience/web-profiles failed with 401 error. Correlation id: bfca9a9c3fdfc
{
"name": "AUTHENTICATION_FAILURE",
"debug_id": "bfca9a9c3fdfc",
"message": "Authentication failed due to invalid authentication credentials or a missing Authorization header",
"information_link": "https://developer.paypal.com/docs/api/payment-experience/#errors",
"details": []
}
at XMLHttpRequest.xhrLoad (http.js:114)
at Object._RECEIVE_MESSAGE_TYPE.<computed> [as postrobot_message_response] (types.js:121)
at receiveMessage (index.js:114)
at messageListener (index.js:140)
at Object._RECEIVE_MESSAGE_TYPE.<computed> [as postrobot_message_response] (types.js:121)
at receiveMessage (index.js:114)
at messageListener (index.js:140)
_RECEIVE_MESSAGE_TYPE.<computed> # types.js:121
receiveMessage # index.js:114
messageListener # index.js:140
setTimeout (async)
dispatchPossiblyUnhandledError # exceptions.js:16
(anonymous) # promise.js:122
setTimeout (async)
reject # promise.js:120
dispatch # promise.js:179
reject # promise.js:127
dispatch # promise.js:179
reject # promise.js:127
dispatch # promise.js:186
reject # promise.js:127
(anonymous) # promise.js:157
dispatch # promise.js:184
reject # promise.js:127
(anonymous) # promise.js:51
respond # client.js:147
_RECEIVE_MESSAGE_TYPE.<computed> # types.js:126
receiveMessage # index.js:114
messageListener # index.js:140
serialize.js:175 Uncaught Error: Error: Request to post https://www.sandbox.paypal.com/v1/payment-experience/web-profiles failed with 401 error. Correlation id: bfca9a9c3fdfc
{
"name": "AUTHENTICATION_FAILURE",
"debug_id": "bfca9a9c3fdfc",
"message": "Authentication failed due to invalid authentication credentials or a missing Authorization header",
"information_link": "https://developer.paypal.com/docs/api/payment-experience/#errors",
"details": []
}
at XMLHttpRequest.xhrLoad (http.js:114)
at Object._RECEIVE_MESSAGE_TYPE.<computed> [as postrobot_message_response] (types.js:121)
at receiveMessage (index.js:114)
at messageListener (index.js:140)
at Object._RECEIVE_MESSAGE_TYPE.<computed> [as postrobot_message_response] (types.js:121)
at receiveMessage (index.js:114)
at messageListener (index.js:140)
at deserializeError (serialize.js:175)
at serialize.js:212
at util.js:140
at eachArray (util.js:102)
at each (util.js:116)
at replaceObject (util.js:138)
at util.js:147
at eachObject (util.js:109)
at each (util.js:118)
at replaceObject (util.js:138)
Heres the page for my button and all the tutorial guy changes is the sandbox id which I did:
import React from 'react';
import PaypalExpressBtn from 'react-paypal-express-checkout';
export default class MyApp extends React.Component {
render() {
const onSuccess = (payment) => {
// Congratulation, it came here means everything's fine!
console.log("The payment was succeeded!", payment);
// You can bind the "payment" object's value to your state or props or whatever here, please see below for sample returned data
}
const onCancel = (data) => {
// User pressed "cancel" or close Paypal's popup!
console.log('The payment was cancelled!', data);
// You can bind the "data" object's value to your state or props or whatever here, please see below for sample returned data
}
const onError = (err) => {
// The main Paypal's script cannot be loaded or somethings block the loading of that script!
console.log("Error!", err);
// Because the Paypal's main script is loaded asynchronously from "https://www.paypalobjects.com/api/checkout.js"
// => sometimes it may take about 0.5 second for everything to get set, or for the button to appear
}
let env = 'sandbox'; // you can set here to 'production' for production
let currency = 'USD'; // or you can set this value from your props or state
let total = 1; // same as above, this is the total amount (based on currency) to be paid by using Paypal express checkout
// Document on Paypal's currency code: https://developer.paypal.com/docs/classic/api/currency_codes/
const client = {
sandbox: 'ASloDPNYZO9LtigzQd58tcYQHuORCH3TlvPS-LWMdwzIWiEiefonUQE7KmWCE-WkaEaiiJb54RSNcrLE',
production: 'YOUR-PRODUCTION-APP-ID',
}
// In order to get production's app-ID, you will have to send your app to Paypal for approval first
// For sandbox app-ID (after logging into your developer account, please locate the "REST API apps" section, click "Create App"):
// => https://developer.paypal.com/docs/classic/lifecycle/sb_credentials/
// For production app-ID:
// => https://developer.paypal.com/docs/classic/lifecycle/goingLive/
// NB. You can also have many Paypal express checkout buttons on page, just pass in the correct amount and they will work!
return (
<PaypalExpressBtn env={env} client={client} currency={currency} total={total} onError={onError} onSuccess={onSuccess} onCancel={onCancel} />
);
}
}
The react-paypal-express-checkout repository does not reference v1/payment-experience/web-profiles , so I am not sure where your error is actually coming from
The v1/payment-experience/web-profiles API requires a valid ClientId and a Secret for authentication.

SignIn not defined google action

I am trying to request a user's sign in details using this guide:
account linking guide]
I am using the node js actions on google library and have copied the guide so I have the following fufillment code:
const app = dialogflow({debug: true, clientId:'*.apps.googleusercontent.com'});
var firebase = require('firebase');
const {dialogflow} = require('actions-on-google');
const functions = require('firebase-functions');
app.intent('Default Welcome Intent',(conv) =>{
conv.ask(new SignIn('To get your account details'));
});
app.intent('Get Signin', (conv, signin) => {
if (signin.status === 'OK') {
const payload = conv.user.profile.payload
conv.ask(`I got your account details, ${payload.name}. What do you want to do next?`)
} else {
conv.ask(`I won't be able to save your data, but what do you want to do next?`)
}
});
when I play the action in the simulator it says 'final response must be set'. I checked my logs in my firebase function and got the following error:
ReferenceError: SignIn is not defined
at app.intent (/srv/index.js:167:15)
at Function.<anonymous> (/srv/node_modules/actions-on-google/dist/service/dialogflow/dialogflow.js:149:23)
at Generator.next (<anonymous>)
at /srv/node_modules/actions-on-google/dist/service/dialogflow/dialogflow.js:22:71
at new Promise (<anonymous>)
at __awaiter (/srv/node_modules/actions-on-google/dist/service/dialogflow/dialogflow.js:18:12)
at Function.handler (/srv/node_modules/actions-on-google/dist/service/dialogflow/dialogflow.js:84:16)
at Object.<anonymous> (/srv/node_modules/actions-on-google/dist/assistant.js:55:32)
at Generator.next (<anonymous>)
at /srv/node_modules/actions-on-google/dist/assistant.js:22:71
You need to import the SignIn object from the actions-on-google library, in the same way as you have imported the dialogflow method. You can do this with
const {
dialogflow,
SignIn
} = require('actions-on-google');
Located before you use those objects.

Use of Expected Conditions on Non Angular Site with Protractor Leads to "Type Error: Cannot read property 'bind' of undefined"

I am seeing following issue when I am using Expected Conditions on webelements returned through element object of Protractor. I tried with $ as well, that resulted in the same thing. I am using Protractor 3.1.1 on Node 4.2.4, Chrome V47.*
"Type Error: Cannot read property 'bind' of undefined"
Before asking, I searched the forums, and understood there are some known issues with using Expected Conditions with selenium elements using driver.findElement.
However, I could not come across a similar issues reported while using element object itself.
https://github.com/angular/protractor/issues/1853
We have a non angular app for login page, which will be switched to Angular, post login. So, I have set ignoreSynchronization=true and later planned to reset it to false after login. Below is the sample code, appreciate any thoughts from community.
Page Objects File
module.exports = {
login: element(by.model('credentials.username')),
password: element(by.model('credentials.password')),
user: "Email",
passwd: "Password",
goButton: $('input.btn.btn-primary'),
EC: protractor.ExpectedConditions,
go: function() {
browser.get("Application URL",30000);
browser.wait(this.EC.elementToBeClickable(this.login),30000);
},
Below is my Sample Test Suite
var VMPage = require('./LoginPage.js');
describe('App Demo', function() {
beforeEach(function() {
console.log("Before Each Started");
browser.driver.manage().timeouts().implicitlyWait(30000);
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1800000;
browser.ignoreSynchronization = true;
VMPage.go();
VMPage.login();
});
it('Test Case', function() {
console.log("***Test Started***");
});
});
Stack trace reported looks as follows:
Stack:
TypeError: Cannot read property 'bind' of undefined
at [object Object].ExpectedConditions.presenceOf (C:\Users\PJ\Ap
pData\Roaming\npm\node_modules\protractor\lib\expectedConditions.js:289:33)
at [object Object].ExpectedConditions.visibilityOf (C:\Users\PJ\
AppData\Roaming\npm\node_modules\protractor\lib\expectedConditions.js:328:10)
at [object Object].ExpectedConditions.elementToBeClickable (C:\Users\PJ0
0366401\AppData\Roaming\npm\node_modules\protractor\lib\expectedConditions.js:17
8:12)
at Object.module.exports.go (D:\protractor_git\Demo\\Log
inPage.js:14:24)
at Object.<anonymous> (D:\protractor_git\Demo\\LoginTest
.js:9:10)
at C:\Users\PJ\AppData\Roaming\npm\node_modules\protractor\node_
modules\jasminewd2\index.js:96:23
at new wrappedCtr (C:\Users\PJ\AppData\Roaming\npm\node_modules\
protractor\node_modules\selenium-webdriver\lib\goog\base.js:2468:26)
at controlFlowExecute (C:\Users\PJ\AppData\Roaming\npm\node_modu
les\protractor\node_modules\jasminewd2\index.js:82:18)
From: Task: Run beforeEach in control flow
at Object.<anonymous> (C:\Users\PJ\AppData\Roaming\npm\node_modu
les\protractor\node_modules\jasminewd2\index.js:81:14)
at attemptAsync (C:\Users\PJ\AppData\Roaming\npm\node_modules\pr
otractor\node_modules\jasmine\node_modules\jasmine-core\lib\jasmine-core\jasmine
.js:1916:24)
at QueueRunner.run (C:\Users\PJ\AppData\Roaming\npm\node_modules
\protractor\node_modules\jasmine\node_modules\jasmine-core\lib\jasmine-core\jasm
ine.js:1871:9)
at QueueRunner.execute (C:\Users\PJ\AppData\Roaming\npm\node_mod
ules\protractor\node_modules\jasmine\node_modules\jasmine-core\lib\jasmine-core\
jasmine.js:1859:10)
at Spec.Env.queueRunnerFactory (C:\Users\PJ\AppData\Roaming\npm\
node_modules\protractor\node_modules\jasmine\node_modules\jasmine-core\lib\jasmi
ne-core\jasmine.js:697:35)
at Spec.execute (C:\Users\PJ\AppData\Roaming\npm\node_modules\pr
otractor\node_modules\jasmine\node_modules\jasmine-core\lib\jasmine-core\jasmine
.js:359:10)
at Object.fn (C:\Users\PJ\AppData\Roaming\npm\node_modules\protr
actor\node_modules\jasmine\node_modules\jasmine-core\lib\jasmine-core\jasmine.js
:2479:37)
at attemptAsync (C:\Users\PJ\AppData\Roaming\npm\node_modules\pr
otractor\node_modules\jasmine\node_modules\jasmine-core\lib\jasmine-core\jasmine
.js:1916:24)
at QueueRunner.run (C:\Users\PJ\AppData\Roaming\npm\node_modules
\protractor\node_modules\jasmine\node_modules\jasmine-core\lib\jasmine-core\jasm
ine.js:1871:9)
at QueueRunner.execute (C:\Users\PJ\AppData\Roaming\npm\node_mod
ules\protractor\node_modules\jasmine\node_modules\jasmine-core\lib\jasmine-core\
jasmine.js:1859:10)
From asynchronous test:
Error
at Suite.<anonymous> (D:\protractor_git\Demo\\LoginTest.
js:3:2)
at addSpecsToSuite (C:\Users\PJ\AppData\Roaming\npm\node_modules
\protractor\node_modules\jasmine\node_modules\jasmine-core\lib\jasmine-core\jasm
ine.js:833:25)
at Env.describe (C:\Users\PJ\AppData\Roaming\npm\node_modules\pr
otractor\node_modules\jasmine\node_modules\jasmine-core\lib\jasmine-core\jasmine
.js:802:7)
at jasmineInterface.describe (C:\Users\PJ\AppData\Roaming\npm\no
de_modules\protractor\node_modules\jasmine\node_modules\jasmine-core\lib\jasmine
-core\jasmine.js:3375:18)
at Object.<anonymous> (D:\protractor_git\Demo\\LoginTest
.js:2:1)
Your page object should be defined as a function:
var Page = function () {
this.login = element(by.model('credentials.username'));
this.password = element(by.model('credentials.password'));
this.user = "Email";
this.passwd = "Password";
this.goButton = $('input.btn.btn-primary');
this.EC = protractor.ExpectedConditions;
this.go = function() {
browser.get("Application URL", 30000);
browser.wait(this.EC.elementToBeClickable(this.login), 30000);
};
};
module.exports = new Page();
Thanks for the suggestion, I agree it should work the way you mentioned, however, it’s strange that we still get into unrecognized types issue.
We are a bit new to the node js and this stack. I tried multiple options including the one you mentioned, by wrapping everything into a function, by individually exposing the elements/functions as module exports etc..
Finally, I found the following one to be working for me, using prototyping.
var AngularPage = function () {
};
AngularPage.prototype.login = element(by.model('credentials.username'));
AngularPage.prototype.password = element(by.model('credentials.password'));
AngularPage.prototype.goButton = $('input.btn.btn-primary');
AngularPage.prototype.user = "username";
AngularPage.prototype.passwd = "password";
AngularPage.prototype.EC = protractor.ExpectedConditions;
AngularPage.prototype.go = function(){
browser.get("Application URL",30000)
.then(browser.wait(this.EC.elementToBeClickable(this.login),30000));
expect(browser.getTitle()).toContain(‘String’);
};
AngularPage.prototype.loginMethod = function(){
console.log("Login started");
this.login.sendKeys(this.user);
this.password.sendKeys(this.passwd);
this.goButton.click();
browser.wait(this.EC.elementToBeClickable(this.compute));
};
module.exports = AngularPage;
In the test file, this is how, I was able to import and call it, a sample snippet.
var page = require('./LoginPage_Export_As_Prototype.js');
var LoginPage = new page();
LoginPage.go();
LoginPage.loginMethod();
Thanks,
Prakash