Want to preserve persistent values - dialogflow-es

We want to preserve persistent values.
We tried it with the following simple code, but the value was not preserved.
What did we make a mistake?
index.js
'use strict';
const functions = require('firebase-functions');
const { dialogflow } = require('actions-on-google');
const app = dialogflow();
app.intent('FirstIntent', conv => {
conv.user.storage.value = 'A';
conv.followup('SecondEvent');
});
app.intent('SecondIntent', conv => {
conv.close('value is ' + conv.user.storage.value);
});
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
package.json
{
"name": "dialogflowFirebaseFulfillment",
"description": "This is the default fulfillment for a Dialogflow agents using Cloud Functions for Firebase",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
"engines": {
"node": "8"
},
"scripts": {
"start": "firebase serve --only functions:dialogflowFirebaseFulfillment",
"deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment"
},
"dependencies": {
"actions-on-google": "^2.2.0",
"firebase-admin": "^5.13.1",
"firebase-functions": "^2.0.2",
"dialogflow": "^0.6.0",
"dialogflow-fulfillment": "^0.6.1"
}
}
FirstIntent is called at startup.
Save the persistent value in FirstIntent and raise a SecondEvent.
SecondIntent is called.
Read a persistent value in SecondIntent to create a response.
"Value is undefined" is displayed.
We found the following log.
Billing account not configured.
External network is not accessible and quotas are severely limited.
Configure billing account to remove these restrictions
We upgraded to flame and confirmed that the log is not displayed, but the persistent value has not been saved yet. Can we solve this problem without charging?

This behavior (that is, the value set to the user.storage is not passed via followup() function) is a specification of actions-on-google-nodejs SDK.
Actually, this is not only the specification of the SDK, but this also is caused by incompatible between the user.storage feature and the Dialogflow followup events feature used by the followup() function. When calling the followup() function, the "followupEventInput" response is returned from the fulfillment to Dialogflow. After receiving the response, Dialogflow decides an intent that can handle the specified event and triggers the intent directly without returning any response to the Actions on Google. The user.storage is a feature of Actions on Google, therefore, the Dialogflow has to return the new values to the Actions on Google to update the user.storage values so that the Actions on Google sends the new values to the next request. However, the Dialogflow doesn't pass the control to the Actions on Google when calling the followup(). As the result, even if setting the values to the user.storage, unfortunately these values are ignored.
Instead, the SDK can store the new user.storage values temporarily to return the values to the Actions on Google at the next webhook. However, the intent triggered by the followup event does not always call a webhook. Therefore, this idea cannot cover all cases. As the result of a discussion, the current SDK does not support this idea.
This specification is described at the following API reference.
https://actions-on-google.github.io/actions-on-google-nodejs/classes/dialogflow.dialogflowconversation.html#followup
Also, you can read the discussion at deciding this specification at the following:
https://github.com/actions-on-google/actions-on-google-nodejs/pull/211#issuecomment-412942410

The problem in your case is that the call to conv.followup() negates most things that you do in the original intent handler, instead replacing them with what you do in the followup intent.
user.storage should preserve values between Intents that are triggered by user actions.

Related

MS Bot Framework Direct Line API 3.0: Get starting message

I published a bot using the Azure bot framework to the Azure cloud servers, and made an application that uses the Direct Line API 3.0 to send user responses and receive bot messages through HTTP requests. Everything works except that I'm not sure how to get the starting message of the bot at the start of the conversation. I open the conversation with the /v3/directline/conversations endpoint, but I'm not sure how to receive the first message of the bot (that is normally sent without any user interaction). A message request after opening the conversation doesn't include any bot responses, but the next message request after sending the first user input includes the first two messages of the bot (starting message and response to the user).
EDIT: From reading this I came to the conclusion that it will be easier to just use a custom event as a trigger for the welcome message. I updated my bot as follows to reflect this within bot composer, adding a new CUSTOM event trigger with a test response message:
However, I still can't seem to trigger this event via the Direct Line API. Currently, I send a request as follows, following the event activity structure:
{
"type": "event",
"channelId": "directline",
"from": { "id": "UnityUserId", "name": "Unity User 1" },
"value": "test",
"name": "welcome"
}
I then get a response with ID, normally indicating that the request was successfull. However, upon requesting the bot response messages, I get the following:
{
"activities": [
{
"type": "event",
"id": "5FZsHpWBxm1hjhWQYY7gr-eu|0000000",
"timestamp": "2022-04-09T14:39:15.90169Z",
"serviceUrl": "https://directline.botframework.com/",
"channelId": "directline",
"from": {
"id": "UnityUserId",
"name": "Unity User 1"
},
"conversation": {
"id": "5FZsHpWBxm1hjhWQYY7gr-eu"
},
"value": "test",
"name": "welcome"
}
],
"watermark": "0"
}
Indicating that the bot has no responses, which doesn't seem quite right when looking at the bot composer screenshot above. Is there something wrong with my current method?
Regards
The onMembersAdded event usually does the trick. Sample code is in https://learn.microsoft.com/en-us/azure/bot-service/bot-builder-send-welcome-message?view=azure-bot-service-4.0&tabs=csharp
I thought I remembered seeing the bot's welcome message when using Direct Line, so I tried to quickly repro it again. I connected a simple echo bot via Direct Line. Then I created a conversation, sent a simple message, and then retrieved all activities (all via REST calls), and the bot's welcome message was indeed present in the response, as you can see in this screenshot:
Perhaps you should use these Direct Line 3.0 API reference docs as opposed to the one you linked above. I followed these steps using the basic Echo bot sample, Postman, and a bot resource in Azure for simple and easy testing, but you could use a full application if you wish.

OpenSea 3.1 API Validation Errors

I believe OS's OpenApi definition is invalid at version v1.0#1e41yo45l0vihg6s. When I attempt to use it from Node using the api package in my project I get validation errors. Simple steps to reproduce:
Create a new Node project and initialize
mkdir os-api-test
cd os-api-test
npm init
Per OS docs/examples, install the api package:
npm install api --save
Create file index.js and populate it with the example code (address and API key omitted here, but they're valid and I can use them via the API UI):
const sdk = require('api')('#opensea/v1.0#1e41yo45l0vihg6s');
sdk['retrieving-a-single-contract']({
asset_contract_address: 'REDACTED',
'X-API-KEY': 'REDACTED'
})
.then(res => console.log(res))
.catch(err => console.error(err));
Run the example
node index.js
Output:
Looking at the API definition here and specifically at the /assets/get path, there are indeed duplicate owner parameters:
"parameters": [
{
"name": "owner",
"in": "query",
"description": "The address of the owner of the assets",
"schema": {
"type": "string"
}
},
...
{
"name": "owner",
"in": "query",
"schema": {
"type": "string"
}
}
...
And per the OpenApi 3.1 spec, in reference to the path item object:
A list of parameters that are applicable for all the operations described under this path. These parameters can be overridden at the operation level, but cannot be removed there. The list MUST NOT include duplicated parameters.
Obviously I can't change the API definition but is there any way to work around this, perhaps via configuration of the api package? I dug into its code but nothing jumped out at me. It's surprising that such a widely used API would have a bug that renders it unusable, yet I can't find any other mentions of it. I realize I may be able to use fetch to hit the API directly but I'd like to use the api package.
Interestingly the testnet API does not suffer from this same bug.
Thank you for surfacing this. We had documented the owner parameter twice, which led to this issue. It is fixed it now.

I'm trying to receive a webhook from an Autodesk Forge workflow.transition event but they aren't firing

I've been experimenting with the Fusion Lifecycle webhooks in Forge and have been successful using the item created/updated events but the workflow transition webhooks aren't firing.
The webhooks are created in Forge according to the Docs, as you can see below, but none of the transitions performed in the workspace will trigger the call.
They were created using a three-legged token associated with a Fusion Lifecycle user that has the proper workflow permissions on the workspace.
The following JSON excerpt is the workflow. transition webhook as returned from developer.api.autodesk.com/webhooks/v1/hooks endpoint on Forge showing it was indeed created.
​
{
"hookId": "909fd040-4e34-11ea-a842-651c9013b5e8",
"tenant": "TENANTNAMEREMOVED4SO",
"callbackUrl": "callbackurl removed for SO",
"createdBy": "46FGNL6DBN6D",
"event": "workflow.transition",
"createdDate": "2020-02-13T07:43:45.988+0000",
"system": "adsk.flc.production",
"creatorType": "O2User",
"status": "active",
"scope": {
"workflow.transition": "urn:adsk.plm:tenant.workspace.workflow.transition:TENANTNAMEREMOVED4SO.119.1.765"
},
"hookAttribute": {
"creator": "D3 Forge Playground",
"notification": {
"class": "alert-danger",
"system": "flc"
}
},
"urn": "urn:adsk.webhooks:events.hook:909fd040-4e34-11ea-a842-651c9013b5e8",
"__self__": "/systems/adsk.flc.production/events/workflow.transition/hooks/909fd040-4e34-11ea-a842-651c9013b5e8"
}
I've pushed the workflow through the transition events numerous times and no webhook is being fired and no failed requests on our webhook receiving server either. if I mimic the payload for the workflow. transition event and post it to our endpoint, it is received as expected.
I have yet to see a live example of the workflow. transition webhook being fired and can't find any sample code from Autodesk using them. Not sure the service is even working as expected at this point even though the item.created and item.updated webhook events seem to work fine.
Has anyone successfully received a workflow. transition webhook from Autodesk Forge? If yes, could you provide some guidance on how?
Seems to be working fine on my end in a Production tenant. This is the payload I used to create the webhook:
{
"callbackUrl": "https://webhook.site/SOME_ID",
"scope": {
"workflow.transition": "urn:adsk.plm:tenant.workspace.workflow.transition:TENANT.107.1.421"
}
}
Does it look like the payload you used when creating the hook?
Greg, any chance you can try to trigger it again, and send me the date/time stamp with tenant name via a private message? I just tried it again in my Production tenant, and it seems to be working just fine when I perform the operation from both a v3 API call, and the UI. Feel free to file a support case if you want, too, and let me know the case number. I'd like to help you out here in understanding what's going on, because overall it looks OK from your side.

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"
}]
}

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