dialogflow / dialogflow-cordova-client

Cordova library for Dialogflow
Apache License 2.0
42 stars 23 forks source link

Initiate dialogflow from my custom plugin #36

Closed teminnov closed 6 years ago

teminnov commented 6 years ago

Hi, I've integrated dialog flow in my custom plugin. Now i want to initiate the dialog flow methods from my plugin's java file. How can i do this?

teminnov commented 6 years ago

Any one know the solution other than calling java script function from java file?

teminnov commented 6 years ago

Make sendVoice function as global like

window.sendVoice = function(){
   try {
      ApiAIPlugin.requestVoice(
       {}, // empty for simple requests, some optional parameters can be here
       function (response) {
          alert(JSON.stringify(response));
       },
       function (error) {
          alert(error);
       });
       } catch (e) {
           alert(e);
       }
}

and from java file call the java script function like this

   cordova.getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            webView.loadUrl("javascript:sendVoice()");
        }
    });