innFactory / react-native-dialogflow

A React-Native Bridge for the Google Dialogflow (API.AI) SDK
https://innfactory.de/softwareentwicklung/ui-ux/sprachsteuerung-mit-api-ai-in-einer-react-native-app/
MIT License
200 stars 64 forks source link

hey @spoeck, is there is any way to send additional parameter to api.ai intents ( except speech text ) i.e like i want to send access_token to my intent which later will send this token to my node web-hook #14

Closed Aashish-1008 closed 7 years ago

spoeck commented 7 years ago

You can try using the context:

const contexts = [{
  name: "config",
  lifespan: 1,
  parameters: {
      access_token: "your access token"
  }
}];

ApiAi.setContexts(contexts);
Aashish-1008 commented 7 years ago

Cann't we do this using events which attached to intent and then we will set the event data to params.

Also is there any way to set some global context . From where i can access data in all my intents like access_token, otherwise everytime i need to set in context and give some life span.

spoeck commented 7 years ago

I could implement a method which sets a "permanent" context:

ApiAi.setPermanentContexts([{name: "sample", parameters: {access_token: "your access token"}])

Then I would set this context on every request with lifespan 1.

Would this help you?

Aashish-1008 commented 7 years ago

perfect thanks !! One more thing const contexts = [{ name: "config", lifespan: 1, parameters: { access_token: "your access token" } }];

Using set contexts i able to trigger my corresponding intent. But i don't know how to get those sent parameters to my node web hook.

when this intent triggers the post request API.ai is making sends empty contexts object to my web hook.

This is how i am setting action parameter in API.ai

screen shot 2017-10-05 at 8 00 03 pm
spoeck commented 7 years ago

Ok.. I will implement setPermanentContexts next weekend.

I've not done something with webhooks so far but the whole contexts should accessible via the request object req of the official example: https://api.ai/docs/getting-started/basic-fulfillment-conversation

Aashish-1008 commented 7 years ago

Thanks !!

Aashish-1008 commented 7 years ago

Hey, i guess sending events is not present in this module. Can you add support for that also. It will be highly appreciated. Thanks.

spoeck commented 7 years ago

Yepp I'm planning to add events, but I stuck on one issue a little bit. It will take some more time for events and it is not on the top position on my todo list. If you need events urgent I recommend following workaround:

  1. make an intent
  2. add a context for this intent with the name of your event
  3. set this context in your app via ApiAi.setContext
  4. call ApiAi.requestQuery("", ()=>{},()=>{}) with an empty query
  5. may ignore fulfillment speech

This is actually the same as request an event.

Aashish-1008 commented 7 years ago

I found a another way to send events. As api.ai is totally exposed via api endpoints .So we can also send events by making a api post request to api.ai .

This is code: var data = { "event": { "name": "YOUR_EVENT_NAME", "data": { "token": "aashish.." } }, "timezone": 'America/New_York', 'lang': "en", "sessionId": currentSessionId }

  fetch("https://api.api.ai/api/query?v=20150910", {
      method: "POST",
      headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer DEVELOPER_ACCESS_TOKEN',
        'charset': "utf-8"
      },
      body: JSON.stringify(data)
    })
    .then(function(response) {
      var json =  response.json().then(function(res){
        console.log('---rrr--',res)
      })
    })
    .then(function(data) {
      console.log(data)
    });

  }, error=>console.log(error))
Arafath-misree commented 7 years ago

Guys does this support latest version of react-native i am getting an error ld: library not found for -lRNSpeechToTextIos clang: error: linker command failed with exit code 1 (use -v to see invocation)

spoeck commented 7 years ago

@Aashish-1008 Thanks for your fetch-method. I implemented it in ApiAi. With version v1.4.0 your have your permanentContext and the ability to requestEvents!

@Arafath-misree I will look into this problem. This is also total out of context of this issue, so I will put your description to a new one and close this one.