How to end the conversation with API.AI - dialogflow-es

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.

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.

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.

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):

Related

Is there any way to resume a chat in dialogflow cx?

I'm trying to build a chatbot with DialogFlow CX. We have an existing chatbot built on DF ES where with the help of contexts we have implemented a resume chat feature, which enables our end users to come back to the chat anytime and continue from where they left off. So currently we are building out the exact same bot in CX and we are facing challenges in recreating the resume chat flow.
So any help regarding how to to do this will be really helpful.
Thanks in advance
Dialogflow CX conversation (session) can be described and visualized as a state machine, configured to collect information or parameters from the end-user. This information is relevant to the conversation state on that page. Please be noted that for each conversational turn, the current page will either stay the same or transition to another page. This also applies for resuming or continuing the current state of the conversation.
Here are possible ways to continue/resume a conversation by passing previously collected customer data from a previous conversation into a new conversation:
You can create a custom implementation using a webhook wherein a function will store the parameter and forms you collected and use that to continue the chat from where the user left off during a conversation flow or a session. In the webhookResponse you can set the fulfillment_response, target_page fields and session_info field to update and send back the stored parameters you collected from the previous conversation.
Here’s an example of how to pass the session parameter, target page and fulfillment response from your webhook response:
{
sessionInfo: {
parameters: {
param1: {
value: "sample1"
}
}
},
targetPage: projects/<Project ID>/locations/<Location ID>/agents/<Agent ID>/flows/<Flow ID>/pages/<Page ID>,
fulfillment_response: {
messages: [{
text: [“This is where you left”],
}]
}
}
You can use APIs or Client Libraries to set the queryParams.parameters and queryParams.currentPage in the detectIntent method.
Here’s a sample reference using REST API to set the QueryParameters of the detectIntent method request body:
{
queryParams: {
parameters: {
param1: {
value: "sample1"
},
currentPage: projects/<Project ID>/locations/<Location ID>/agents/<Agent ID>/flows/<Flow ID>/pages/<Page ID>,
}
}
}

createNewDiscussion/createNewDiscussionReply via JSOM in SharePoint Discussion Board from external Angular SPA

Scenario:
I have an Angular SPA and a SharePoint 2013, installed in separated servers. I would like to consume a SharePoint discussion board in my SPA, means I would like to use my customized UI to perform CRU(D) operations on the SharePoint discussion board.
Through some workarounds I already achieved this objective using the SP REST API, but unfortunately since REST API doesn't allow setting some parameters for the discussion board (in particular the ParentID) I am not really able to use REST API in a satisfactory way.
In order to make it possible to work through the REST API I had to change the configuration in the IIS of the SharePoint Server to rewrite the headers and allow the Cross-Domains Call. Moreover I pass as options in the http call the digest from the context info. As I said, the comunication works, I can create new discussions or replies, but these are malformed because the API itself doesn't offer the methods that I need, but just some workaround to post not-so-good-looking messages in the discussion board (for example the threading is completely lost).
With JSOM I am doing this (I simpliefied a bit):
createReply() {
let clientContext = new SP.ClientContext("otherserver.sharepoint.com");
    let list = clientContext.get_web().get_lists().getByTitle("myDiscussionBoardName");
    let discussionItem = list.getItemById(parentTopicId); //eg. parentTopicId === 10
    let properties = {'Body': 'My Message'};
    let messageItem = SP.Utilities.Utility.createNewDiscussionReply(clientContext, discussionItem);
    for (var propName in properties) {
messageItem.set_item(propName, properties[propName])
    }
messageItem.update();
    clientContext.executeQueryAsync(() => 
{ console.log("Gotcha!", messageItem); },
  (error: any) => { console.log('Request failed', error); });
  }
But unfortunately I get a 401 error. My understanding would also be that I won't need to provide a digest, since JSOM should take care of it by itself, but I am not sure of this, nor I am aware of how I could provide the digest within a JSOM call.
Honestly this message is my last hope to get to the bottom of this. I actually am already planning to use different solutions, but I can't believe that a solution doesn't exist, in particular because using a local proxy (sp-rest-proxy, you may know it well if you develop angular application based on SP) the connection somehow works correctly.
check the below link and also I just put one the example from our code
http://sharepointsanjay.blogspot.com/2016/05/how-to-refresh-request-digest-token.html
var headers = {
"Accept": "application/json; odata=verbose",
"Content-Type": "application/json; odata=verbose",
"X-RequestDigest": document.getElementById("__REQUESTDIGEST").value,
"X-HTTP-Method": "MERGE",
"If-Match": "*"
};
return $http({
headers: headers,
method: "POST",
url: url,
data: JSON.stringify(data)
}).then(complete, failed);

Why does Dialogflow nodejs sdk "detect Intent with Knowledge Base" method responds with null ? ( V2Beta)

I am integrating the Dialogflow Nodejs sdk into my application to detect the knowledge base intent with the help of the following document nodejs-dialoglowflow-detect-knowledgebase-intent.
Below is my query request
const request = {
session: sessionPath,
queryInput: {
text: {
// The query to send to the dialogflow agent
text: message,
// The language used by the client (en-US)
languageCode: 'en-US',
},
},
queryParams: {
knowledgeBaseNames: ['projects/my-project-id/knowledgeBases/my-knowledge-base-name'],
},
};
When I test the FAQ in dialogflow console it works, but when I try to do the same with Dialoglflow Nodejs SDK, the knowledgeAnswers object from dialogflow response is null.
Any help is appreciated. Thanks
This is happening because of the incorrect value in knowledgeBaseNames property.
When you create a knowledge base it returns below response:
{
"name": "projects/project-id/knowledgeBases/NDA4MTM4NzE2MjMwNDUxMjAwMA",
"displayName": "knowledge-base-display-name"
}
knowledgeBaseNames property accepts the array of name. It is different than displayName.
In case you have created the Konwledgebase form Dialogflow dashboard, you won't see this detail in the dashboard. However, Dialogflow SDKs Provide APIs to get the list of knowledgebase of an agent. Node js V2Beta1 SDK has a method projects.knowledgeBases.list, which, when given a project name, will list all of the knowledge bases along with their display name and their name. You can send the list of names into the detect intent request.
If your use case only requires knowing the ID for the knowledge base then you can get if from "Try it out" section of the Dialogflow console. Type a question you have added in knowledgebase and click on diagnostic info. It will show the dialogflow response in JSON. Look for the knowledgeAnswers object. The knowledgebase ID is the part of source property as mentioned below:
"knowledgeAnswers": {
"answers": [{
"source": "projects/project-id/knowledgeBases/knowledgebase-id/documents/document-id"
}]
}

In a chatbot conversation using dialogflow, Is there a way to make the bot speak first?

Is it possible to format a conversation so that the bot initiates conversation using dialogflow in a web demo integration?
The objective is to say something like “Hi, I’m a bot, I can do x” to establish that it’s a chatbot rather than a human.
Can anyone suggest any idea for this?
You can set a welcome intent, then send a /query request containing an event parameter. Set the event parameter to WELCOME and your chatbot will respond with whatever conversation opening you set.
More info here: https://dialogflow.com/docs/events
If you are using something other than the API for interacting with your Dialogflow agent (Slack, Facebook Messenger, etc.) you will need to add an appropriate event under "intents" in your console (such as the "Facebook Welcome" event).
For interacting with your Dialogflow agent via the API, see below.
In the API interaction quickstart documentation, Dialogflow gives you the SessionClient's detectIntent method for sharing messages with your bot.
Each language has a different solution. But on an abstract level, you want to change the request object that you send to Dialogflow to include a "Welcome" event (no input message required), as Omegastick described.
For example, in Node.js, your request object would look like this:
// The text query request.
const request = {
session: sessionPath,
queryInput: {
event: {
name: "Welcome",
languageCode: languageCode
}
},
};
This assumes you have an appropriate intent set up in your Dialogflow console to handle Welcome events. One is provided by default that you can observe.
You can also add contexts, so that your agent gives a different greeting message based on some condition.

How to end session through Dialogflow api v2 webhook response?

I am developing Google Assistant Action (for google home) using the Dialogflow and the API v2 webhooks
I am having trouble finding how to end session!
There was expectUserResponse in API v1, there is shouldEndSession on Alexa, but I can not find anything similar for Dialogflow v2.
In the Dialogflow console, select the intent you want, and go to the Responses section.
Select Set this intent as end of conversation.
You do not need to specify a response to send back (you can do that in your code as long as Fulfillment is set to Enable webhook call for this intent)
For Dialogflow v2 the expectUserResponse attribute still works for ending a conversation on Actions on Google, its just in a slightly different place (... indicates the rest of your Actions on Google payload):
{
"fulfillmentMessages": [
{
"payload": {
"expectUserResponse": true,
...
},
"platform": "ACTIONS_ON_GOOGLE"
}
]
}

Resources