How to end the conversation with API.AI

3.1k views Asked by At

Is there a way to end Google Home's conversation with the server using API.AI?

I am assuming that somehow I need to access expect_user_response and set it to false.

I also see with the actions SDK you can use 'assistant.tell()', but that does not seem accessible with API.AI.

3

There are 3 answers

1
assist ant On BEST ANSWER

Yes, you can. In your app, write a function that sends the query "stop" to your agent.

function stop_conversation(){ var api_request = new Request('https://api.api.ai/v1/query?v=20150910', {
        method: 'POST',
        mode: 'cors',
        redirect: 'follow',
        headers: {
            'Authorization': 'Bearer 21f6a5778d484870ad46be4d34ac2eeb',
            'content-Type': 'application/json; charset=utf-8'
        },
        body: JSON.stringify({
            q: 'stop',
            lang: 'en',
            sessionId: '44628d21-d7a4-47d5-b1c6-a7f851be65fv'
        })
    });
}

If you're using the fulfillment library then invoke Assist('stop');.

...

In the "Intent" pane, under fulfillment, there is an "Actions on Google" section that you can expand. Under that, you will see "End Conversation" check that box.

In your fulfillment include the following:

data: {
  google: {
    expect_user_response: false,
  }
}

Add this at the same level as your speech property in your response.

2
SysCoder On

For people that are not using the SDK. There are two ways that I found to stop the mic on Google Home while using API.AI.

In the "Intent" pane, under fulfillment, there is an "Actions on Google" section that you can expand. Under that you will see "End Conversation" check box. Check that box.

In your fulfillment include the following:

data: {
  google: {
    expect_user_response: false,
  }
}

Add this at the same level as your speech property in your response.

0
AdamK On

For those using the Node.js client library, this is accomplished programmatically via the tell() function (docs for ActionsSdk client, docs for API.AI client).

Even though the docs simply say:

Tells the Assistant to render the speech response and close the mic.

this does effectively end communication with your Assistant app, returning the user back to Google Assistant.

The same thing can be accomplished by checking the "End Conversation" box in the API.AI web GUI within a specific Intent (however of course this is not dynamic and will end the conversation every time that Intent is invoked): enter image description here