Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR: Tried calling: []("queryText") #21

Open
abbas-25 opened this issue Jan 31, 2020 · 24 comments
Open

ERROR: Tried calling: []("queryText") #21

abbas-25 opened this issue Jan 31, 2020 · 24 comments

Comments

@abbas-25
Copy link

abbas-25 commented Jan 31, 2020

import 'package:flutter/material.dart';
import 'package:flutter_dialogflow/dialogflow_v2.dart';

class Home extends StatefulWidget {
  Home({Key key}) : super(key: key);

  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {

  String query = "hi";

  void _sendQuery() async {
    try {
    AuthGoogle authGoogle = await AuthGoogle(fileJson: "assets/dependencies/dialogflow.json").build();
    Dialogflow dialogflow = Dialogflow(authGoogle: authGoogle,language: Language.ENGLISH);
    print(dialogflow.toString());
    AIResponse response = await dialogflow.detectIntent(query);
    print(response.getMessage());


    } catch(e) {
      print('------------------------------${e.toString()}');
    }
  
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
       appBar: AppBar(
         title: Text('Ask Now'),
       ),
       body: RaisedButton(
         onPressed: _sendQuery,
         color: Colors.black87,
         child: Text('Send Query', style: TextStyle(color: Colors.white)),
       ),
    );
  }
}

ERROR LOG -

I/flutter ( 9861): Instance of 'Dialogflow'
I/flutter ( 9861): ------------------------------NoSuchMethodError: The method '[]' was called on null.
I/flutter ( 9861): Receiver: null
I/flutter ( 9861): Tried calling: []("queryText")

I've taken all the necessary steps in my view. Is there anything missing out? in the code or in the process of GCP Json file downloading. I've not verified the OAuth screen though. And my GCP account is NOT payment verified.

@EvanFung
Copy link

EvanFung commented Feb 1, 2020

same here.
I found that whenever I type the query string with " ' " single quote that will trigger this error.

@abbas-25
Copy link
Author

abbas-25 commented Feb 1, 2020

same here.
I found that whenever I type the query string with " ' " single quote that will trigger this error.

You mean the query string should be in double quotes instead of single quotes? Like "hii" and not 'hi'?? Also my code uses double quotes but still it manages to find that error

@EvanFung
Copy link

EvanFung commented Feb 1, 2020

same here.
I found that whenever I type the query string with " ' " single quote that will trigger this error.

You mean the query string should be in double quotes instead of single quotes? Like "hii" and not 'hi'?? Also my code uses double quotes but still it manages to find that error

I mean that the query string includes single quote like [ I'm fine ] or [ thanks' ] that will trigger this error.

@abbas-25
Copy link
Author

abbas-25 commented Feb 1, 2020

same here.
I found that whenever I type the query string with " ' " single quote that will trigger this error.

You mean the query string should be in double quotes instead of single quotes? Like "hii" and not 'hi'?? Also my code uses double quotes but still it manages to find that error

I mean that the query string includes single quote like [ I'm fine ] or [ thanks' ] that will trigger this error.

Oh alright. I get it. However, my query string doesn't have any apostrophe or single quotes. Did you verify your OAuth screen? Just trying to know if it's needed.

@EvanFung
Copy link

EvanFung commented Feb 1, 2020

same here.
I found that whenever I type the query string with " ' " single quote that will trigger this error.

You mean the query string should be in double quotes instead of single quotes? Like "hii" and not 'hi'?? Also my code uses double quotes but still it manages to find that error

I mean that the query string includes single quote like [ I'm fine ] or [ thanks' ] that will trigger this error.

Oh alright. I get it. However, my query string doesn't have any apostrophe or single quotes. Did you verify your OAuth screen? Just trying to know if it's needed.

i have't verify my OAuth screen yet.

@abbas-25
Copy link
Author

abbas-25 commented Feb 2, 2020

same here.
I found that whenever I type the query string with " ' " single quote that will trigger this error.

You mean the query string should be in double quotes instead of single quotes? Like "hii" and not 'hi'?? Also my code uses double quotes but still it manages to find that error

I mean that the query string includes single quote like [ I'm fine ] or [ thanks' ] that will trigger this error.

Oh alright. I get it. However, my query string doesn't have any apostrophe or single quotes. Did you verify your OAuth screen? Just trying to know if it's needed.

i have't verify my OAuth screen yet.

I'll give it another try.

@javieralcantara
Copy link

I have the same issue. Any solutions?

@abbas-25
Copy link
Author

I have the same issue. Any solutions?

No. Can't even find anything on the internet.

@nandakumar111
Copy link

nandakumar111 commented Feb 20, 2020

You may get error response from dialogflow. Can you edit the library file

lib/v2/dialogflow_v2.dart (Line No: 134)

print the response. You will get what is the error (Notes: try flutter clean cache and reinstall it).

@0Vipin0
Copy link

0Vipin0 commented Mar 11, 2020

Any Solutions guys? I want to know what is the API used here so that I can manually get the response here. I tried in the Dialogflow docs but was unable to find anything on how to fetch the response using the API in v2.

@nandakumar111
Copy link

Any Solutions guys? I want to know what is the API used here so that I can manually get the response here. I tried in the Dialogflow docs but was unable to find anything on how to fetch the response using the API in v2.

Dialogflow detectIntent API Doc

Check the following code, take it as an example. Here I added payload, inputAudio and outputAudioConfig in body Params. Also I added extra attribute(_audioOutput) in AIResponse class and get attribute value in a function.

class AIResponse {
// Attribute Initialization
...
 String _audioOutput;


  AIResponse({Map body}) {
    ...
    _audioOutput=body['outputAudio'];
  }

 String getOutputAudio() {
    return _audioOutput;
  }
}

...

Future<AIResponse> detectIntent(Map data) async {
    String queryInput = "";
    String queryData = "";
    String outputAudioConfig = "'outputAudioConfig':{'audioEncoding':'OUTPUT_AUDIO_ENCODING_LINEAR_16','synthesizeSpeechConfig':{'voice':{'ssmlGender':'SSML_VOICE_GENDER_FEMALE'}}}";
    if(data["audioData"] != null){
      queryData = "'audioConfig':{'languageCode':'en-US'}";
    }else{
      queryData = "'text':{'text':'${data["query"]}','language_code':'$language'}";
    }
    queryInput = "'queryInput':{$queryData}" + (data["audioData"] != null ? (",'inputAudio': ${data["audioData"]}" ): "");

    String body = "{'queryParams':{'payload':{'userId':'${data["authUserId"]}'}},$queryInput,$outputAudioConfig}";

    var response = await authGoogle.post(_getUrl(),
        headers: {
          HttpHeaders.authorizationHeader: "Bearer ${authGoogle.getToken}"
        },
        body: body
    );
    return AIResponse(body: json.decode(response.body));
  }
...

@nandakumar111
Copy link

Any Solutions guys? I want to know what is the API used here so that I can manually get the response here. I tried in the Dialogflow docs but was unable to find anything on how to fetch the response using the API in v2.

If you get error like ERROR: Tried calling: [ ] ( " queryText " ) this, You may get an error in the response.
you can also see the error to print response.body in that code.

@mrhermina
Copy link

I'm having the same issue. Did you find any solution?

@abbas-25
Copy link
Author

I'm having the same issue. Did you find any solution?

No

@jmertl
Copy link

jmertl commented Apr 15, 2020

I found out I didn't saved Service account details in the https://console.cloud.google.com/iam-admin/serviceaccounts with the created JSON key.

Double-check if your account has the key saved.

@MahmouedMohamed
Copy link

MahmouedMohamed commented May 16, 2020

Hey i solved it by using Dialogflow v1
just import v1 lib and use it like this

import 'package:flutter_dialogflow/flutter_dialogflow.dart';
Dialogflow dialogflow = Dialogflow(token: "Your Token");
AIResponse response = await dialogflow.sendQuery("Your Query");
print('thing ${response.getMessageResponse()}');

your token can be found here https://dialogflow.cloud.google.com/#/editAgent/{your project id}/

@shuyttr
Copy link

shuyttr commented Jul 14, 2020

Hey i solved it by using Dialogflow v1
just import v1 lib and use it like this

import 'package:flutter_dialogflow/flutter_dialogflow.dart';
Dialogflow dialogflow = Dialogflow(token: "Your Token");
AIResponse response = await dialogflow.sendQuery("Your Query");
print('thing ${response.getMessageResponse()}');

your token can be found here https://dialogflow.cloud.google.com/#/editAgent/{your project id}/

At that link you get 'Project ID' and 'Service Account'. Where is the token? And if it has to do with the service account, which field is it?

@youraerials
Copy link

The docs for this package are not exactly right in the current version of Dialogflow as far as I can tell.

He advises to create a NEW service account and key in the docs, but with the current release of Dialogflow, you actually have to use the EXISTING service account which you can find in the settings for your Agent. That's under the General tab. Click that gear in the top left of dialog flow to get to settings and just under the project id you should see the service account it is actually using. Note what it is called!

From there, you need to go into Service Accounts in the GCP and find that same service account email and click it, then add a key, choose JSON, and download and link as described. This worked for me....

@yaa9oub
Copy link

yaa9oub commented Nov 29, 2020

The docs for this package are not exactly right in the current version of Dialogflow as far as I can tell.

He advises to create a NEW service account and key in the docs, but with the current release of Dialogflow, you actually have to use the EXISTING service account which you can find in the settings for your Agent. That's under the General tab. Click that gear in the top left of dialog flow to get to settings and just under the project id you should see the service account it is actually using. Note what it is called!

From there, you need to go into Service Accounts in the GCP and find that same service account email and click it, then add a key, choose JSON, and download and link as described. This worked for me....

Yarhem waldin waldik <3

@taharh
Copy link

taharh commented Nov 29, 2020

The docs for this package are not exactly right in the current version of Dialogflow as far as I can tell.

He advises to create a NEW service account and key in the docs, but with the current release of Dialogflow, you actually have to use the EXISTING service account which you can find in the settings for your Agent. That's under the General tab. Click that gear in the top left of dialog flow to get to settings and just under the project id you should see the service account it is actually using. Note what it is called!

From there, you need to go into Service Accounts in the GCP and find that same service account email and click it, then add a key, choose JSON, and download and link as described. This worked for me....

Thank you man you're a life saver

@daniele777
Copy link

Guys help i follow all instruction but i have complain ...

E/flutter ( 1598): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: The method '[]' was called on null.
E/flutter ( 1598): Receiver: null
E/flutter ( 1598): Tried calling:
E/flutter ( 1598): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
E/flutter ( 1598): #1 new QueryResult (package:flutter_dialogflow/v2/dialogflow_v2.dart:26:21)
E/flutter ( 1598): #2 new AIResponse (package:flutter_dialogflow/v2/dialogflow_v2.dart:64:24)
E/flutter ( 1598): #3 Dialogflow.detectIntent (package:flutter_dialogflow/v2/dialogflow_v2.dart:124:12)
E/flutter ( 1598):
E/flutter ( 1598): #4 _FlutterFactsChatBotState.agentResponse (package:agentai/dialog_flow.dart:51:44)
E/flutter ( 1598):
E/flutter ( 1598): #5 _FlutterFactsChatBotState._submitQuery (package:agentai/dialog_flow.dart:73:5)
E/flutter ( 1598): #6 EditableTextState._finalizeEditing (package:flutter/src/widgets/editable_text.dart:1819:25)
E/flutter ( 1598): #7 EditableTextState.performAction (package:flutter/src/widgets/editable_text.dart:1688:9)
E/flutter ( 1598): #8 TextInput._handleTextInputInvocation (package:flutter/src/services/text_input.dart:1168:37)
E/flutter ( 1598): #9 MethodChannel._handleAsMethodCall (package:flutter/src/services/platform_channel.dart:430:55)
E/flutter ( 1598): #10 MethodChannel.setMethodCallHandler. (package:flutter/src/services/platform_channel.dart:383:34)
E/flutter ( 1598): #11 _DefaultBinaryMessenger.handlePlatformMessage (package:flutter/src/services/binding.dart:283:33)
E/flutter ( 1598): #12 _invoke3. (dart:ui/hooks.dart:280:15)
E/flutter ( 1598): #13 _rootRun (dart:async/zone.dart:1190:13)
E/flutter ( 1598): #14 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter ( 1598): #15 _CustomZone.runGuarded (dart:async/zone.dart:997:7)
E/flutter ( 1598): #16 _invoke3 (dart:ui/hooks.dart:279:10)
E/flutter ( 1598): #17 _dispatchPlatformMessage (dart:ui/hooks.dart:154:5)
E/flutter ( 1598):

@chamikara1998
Copy link

Had the same issue.
For my error happened I downloaded another project service key file. downloaded correct file and issue fixed. make sure to enable dialog flow API and download the correct Service Account JSON file

@daniele777
Copy link

daniele777 commented Feb 3, 2021

Nothing still problem i create new key with admin dialogflow

Cattura

but still have problem... help! i created key in json from dialog flow api enabled

@thisishardik
Copy link

The docs for this package are not exactly right in the current version of Dialogflow as far as I can tell.

He advises to create a NEW service account and key in the docs, but with the current release of Dialogflow, you actually have to use the EXISTING service account which you can find in the settings for your Agent. That's under the General tab. Click that gear in the top left of dialog flow to get to settings and just under the project id you should see the service account it is actually using. Note what it is called!

From there, you need to go into Service Accounts in the GCP and find that same service account email and click it, then add a key, choose JSON, and download and link as described. This worked for me.

You're a life saver man. Spent around 4-5 hours on this issue. But finally resolved it. For me though, creating a new project with just 1 service account worked. Earlier I was trying to create a service account for an older project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests