0

When I followed this tutorial: https://blog.jscrambler.com/build-a-chatbot-with-dialogflow-and-react-native/ I'm having an error within the handleGoogleResponse() method as result.queryResult is undefined. If I send a message as a user, there is no response collected from Dialogflow and presented back to the user.

What does this line of code mean in the handleGoogleResponse() method?

let text = result.queryResult.fulfillmentMessages[0].text.text[0];

What is result.queryResult? What do I do since result.queryResult is undefined?

I noticed that once I open the chatbot screen my console shows: "generating jwt for "Object {\n "email": "integrate-dialogflow@mt-bot-wkgm.iam.gserviceaccount.com",\n "key": ....." with the key information for my service account. This means it is able to read my env.js file?

Edit:

console.log(result) returns [object Object]

console.log(result.responseID) returns undefined

console.log(result.queryResult) returns undefined

console.log(result.webhookStatus) returns undefined

console.log(result.outputAudio) returns undefined

console.log(result.outputAudioConfig) returns undefined

console.log(JSON.stringify(result)) returns

{"error":{"code":401,"message":"Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","status":"UNAUTHENTICATED"}}

  • Can you try printing `result` and check it it has a value? If it does not have a value, it means that you are not able to properly pass a value from your app to dialogflow in function `onSend()`. – Ricco D Jul 06 '21 at 02:55
  • @RiccoD Thanks for your response. When I print result, it returns "object Object", but when I print result.queryResult or result.responseId, it returns undefined. – Anne Willow Jul 07 '21 at 02:28
  • Since it returns an object, you can debug this further by inspecting the actual values under `result`. Check [how to display the entire object in console in react native](https://stackoverflow.com/a/50904697/14733669). Edit your post and include the contents of the object. You should get a data structure that looks like this https://cloud.google.com/dialogflow/es/docs/reference/rest/v2/DetectIntentResponse since the back end of "react-native-dialogflow" is just calling `dectectIntent` via HTTP request from dialogflow API. – Ricco D Jul 07 '21 at 04:00
  • @RiccoD I have edited my post. All the values under result are undefined. – Anne Willow Jul 08 '21 at 00:50
  • Instead of directly printing, can you do `console.log(JSON.stringify(result));` which is the test done from the Stackoverflow link I mentioned on my previous comment. – Ricco D Jul 08 '21 at 00:54
  • @RiccoD I included my error above, I'm looking for the right way to fix this since this I am make a React Native iOS app, not a web app. I also already created a service account and key before. – Anne Willow Jul 08 '21 at 13:05
  • Now that we have a descriptive error, what you can do is check the credentials you placed in your file **env.js ->** `dialogflowConfig`. If you think you were able to put the correct credentials and it won't work, I suggest to try creating a new service account and use that for authentication and check if it will work. – Ricco D Jul 09 '21 at 00:36
  • @RiccoD I created a new service account and I'm having the same error. I think it is able to detect my service account (I added to my post above). Should I be doing this https://cloud.google.com/docs/authentication/end-user? I'm reading this to understand if there is another step I should be taking other than creating a service account https://help.mypurecloud.com/articles/configure-the-oauth-client-credential-for-google-dialogflow/ – Anne Willow Jul 09 '21 at 01:45
  • Apparently there were also other users that encounter your error and posted a workaround here is the [git issue](https://github.com/innFactory/react-native-dialogflow/issues/84). Can you try it if it is working for you as well? – Ricco D Jul 09 '21 at 02:14
  • @RiccoD Right now, I have my Dialogflow configuration under a componentDidMount() but I did it both ways presented in that link, and I am facing the same error. – Anne Willow Jul 09 '21 at 13:44
  • What I meant for you to try is the [latest comment in the git issue](https://github.com/innFactory/react-native-dialogflow/issues/84#issuecomment-679957807). – Ricco D Jul 09 '21 at 15:46
  • @RiccoD Yes, I tried that and it didn't change the error. – Anne Willow Jul 11 '21 at 02:19
  • I see. Since the problem is on the library that you are using (probably since it is old and the last update was July 2019) it was not able to keep up with the updates of Dialogflow. What I could suggest is to either look for a different library that integrates Dialoglflow for React or use the [Dialogflow REST API](https://cloud.google.com/dialogflow/es/docs/reference/rest/v2-overview) and send HTTP request directly. – Ricco D Jul 12 '21 at 00:48

1 Answers1

0

If you don't pass authorization you don't get queryResult since an exception is raised before.

I think it is clear that you have an auth problem.

Could you show your env.js (withe modified key, etc...) and the code of dialogflow lib configuration ?

MilacH
  • 280
  • 2
  • 12