MalformedResponse Error on Google Assistant - dialogflow-es

I am calling a third-party API to fetch data. In a situation when the API returns error I can't continue my user flow on the Google Assitant
Error I see in Google Cloud Console is as follows:
"MalformedResponse: ErrorId: c316c2bc-be3b-4c8f-8d9b-2b45434a0325.
Failed to parse Dialogflow response into AppResponse because of
invalid platform response. : Could not find a RichResponse or
SystemIntent in the platform response for agentId:
0bc4ed97-dfec-4936-b90d-28f047eb7b34 and intentId:
3dcf4b35-00e0-4c75-815c-d1a76494e08e"
Here is my intent code.
app.intent('askPin', (conv, params) => {
conv.user.storage.pin_prompt_count = conv.user.storage.pin_prompt_count + 1;
var member = services.getMemberDetails(memberId, params.account_pin);
return member.then(function (result) {
if (result) {
conv.user.storage.pin_prompt_count = 0; //reset prompt count once verified
conv.user.storage.account_pin = params.account_pin;
conv.contexts.delete('account-pin-context');//delete context to pin intent will not be invoked again.
return handleService(conv);
}
}).catch(function (err) {
console.log("Paresh Varde 1");
conv.ask("Invalid Pin. Please try again");
})
});
Here is the Response I see being generated from the log
{
"status": 200,
"headers": {
"content-type": "application/json;charset=utf-8"
},
"body": {
"payload": {
"google": {
"expectUserResponse": true,
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Invalid Pin. Please try again"
}
}
]
}
}
}
}
}
I don't see any error in the firebase console (where the function is deployed). However I see an error in Google Cloud console as follows:
MalformedResponse: ErrorId: c316c2bc-be3b-4c8f-8d9b-2b45434a0325. Failed to parse Dialogflow response into AppResponse because of invalid platform response. : Could not find a RichResponse or SystemIntent in the platform response for agentId: 0bc4ed97-dfec-4936-b90d-28f047eb7b34 and intentId: 3dcf4b35-00e0-4c75-815c-d1a76494e08e
I see a message on my simulator as "App isn't responding right now. Try again soon." and it leaves the conversation.
Please advise.

The problem was that my webhook call was taking more than 5 seconds to complete. Webhook must complete it's execution in less than 5 seconds to work properly and make the conversation smooth.
For now, I need to work out my REST interface so that API I am calling respond quickly to achieve this timeout limit.

Related

Messenger bot comment to message using node and private replies - read_page_mailboxes unobtainable

I have a messenger bot created in node. A user comments on the page and this kicks off a message sequence. It has previously been working however now I receive an error "The page does not have read_page_mailboxes or pages_messaging permission."
I have created a permanent access token as per instructions found in this overflow: facebook: permanent Page Access Token? - this did not work
I have tried to request to get the permission for read_page_mailboxes, however this was denied as this edge needs a platform to be included and login information, my bot uses none of these, just the comment-to-message functionality
I'm able to get the word that the user enters on the page however I'm unable to send a private message using the comment_id.
if(entry.hasOwnProperty('changes')) {
entry.changes.forEach(function(changes){
let comp_comment;
if(typeof changes.value.message !== "undefined") {
comp_comment = changes.value.message.replace(/[^\w\s]/gi, '').trim().toLowerCase();
}
if(changes.field=="feed" && changes.value.item=="comment" && changes.value.verb=="add" && comp_comment == "enter") {
let user = changes.value.from.name;
let comment_name = user.replace(/ .*/,'');
callPrivateReply(changes.value.comment_id, comment_name);
}
})
}
Then this is my request function
function callPrivateReply(comment_id, first_name) {
let messageData = {
"message": `this is the message I'm attempting to send`
}
request({
"uri": 'https://graph.facebook.com/v2.12/'+comment_id+'/private_replies',
"qs": { "access_token": PAGE_ACCESS_TOKEN },
"method": 'POST',
json: messageData
}, function (err, res, body) {
if (!err && res.statusCode == 200) {
console.log(body);
} else {
console.error("Failed calling Send API", res.statusCode, res.statusMessage, body.error);
}
});
You need to have pages_messages permission and read_mail_boxes set in to advance access from standed access by applying a app review. Check by visiting below path>>
messenger docs >> getting started >> messaging >> private replyies.

how to add update multiple response of a dialog node in IBM watson assistant with Nodejs

I have a node application which is interacting with IBM watson assistant.
I need to update the response output of a dialog node and I'm using the following watson api
var params = {
workspace_id: //,
dialog_node: 'greeting',
new_dialog_node: 'greeting',
new_output: {
text: 'Hello! What can I do for you?'
//add more than one text
}
};
assistant.updateDialogNode(params, function(err, response) {
if (err) {
console.error(err);
} else {
console.log(JSON.stringify(response, null, 2));
}
});
the API only accepts object type text:'Hello! What can I do for you?' this also overwrites the previous response
the error [ { message: 'output should be of type Object', path: '.output' } ]
How can I update the Dialog and add multiple responses at the same time or update the existing one?
thanks in advance!
Have you tried the following format for new_output?
{
"text": {
"values": [
"first response",
"second response"
],
"selection_policy": "sequential"
}

Google dialogflow small talk issue

i am developing chat bot application with google dialog flow. i am using node js client https://github.com/dialogflow/dialogflow-nodejs-client-v2 to access the data of my chat bot. i have enabled small talk from the dialog flow console and it works fine when i use it from the dialog flow web demo or the console it self
for the same chat application i have implemented a api by using dialogflow node js client.
if (req.body.text) {
query = req.body.text;
}
// Get the city and date from the request
var request = {
session: sessionPath,
queryInput: {
text: {
text: query,
languageCode: languageCode,
},
},
};
// Send request and log result
sessionClient
.detectIntent(request)
.then(responses => {
console.log('Detected intent');
const result = responses[0].queryResult;
console.log(` Query: ${result.queryText}`);
console.log(` Response: ${result.fulfillmentText}`);
if (result.intent) {
res.json({ "text": result.fulfillmentText });
} else {
res.json({ 'fulfillmentText': "No intent matched" });
console.log(` No intent matched.`);
}
})
.catch(err => {
console.error('ERROR:', err);
});
there i dont get the result i want. instead it goes to a different intent
what i have done incorrectly here..
Queries defined in Small Talk section of your Dialogflow agent will not have an associated intent. If there was a matching intent, then you shouldn't have really added that query into Small Talk. Therefore, since there is not matching intent, the Dialogflow Node library will return an unmatched intent.

AWS cognito: getCredentials not working

Im in the process of learning to use AWS Cognito. I have set up a userpool and a identity pool.
Code (simplified):
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: (result) => {
let cognitoGetUser = userPool.getCurrentUser();
if (cognitoGetUser != null) {
cognitoGetUser.getSession((err, result) => {
if (result) {
console.log ("Authenticated to Cognito User and Identity Pools!");
let token = result.getIdToken().getJwtToken();
let cognitoParams = {
IdentityPoolId: this.identityPool,
Logins: {}
};
cognitoParams.Logins["cognito-idp.eu-west-1.amazonaws.com/"+this.poolData.UserPoolId] = token;
AWS.config.credentials = new AWS.CognitoIdentityCredentials(cognitoParams);
AWS.config.getCredentials(() => {
console.log(AWS.config.credentials.accessKeyId)
console.log(AWS.config.credentials.secretAccessKey)
console.log(AWS.config.credentials.sessionToken)
}
}
}
}
},
onFailure: function(err) {
console.log('error');
console.log(err)
}
}
}
Most of the code works as expected: The authenticateUser fires the onSuccess and I can see a jwt token ect
Problem: I cant get the AWS.config.getCredentials to work. It executed without any errors, but accessKeyId, secretAccessKey and SessionToken are all undefined.
Any suggestions to what I'm doing wrong?
I cant get the AWS.config.getCredentials to work. It executed without any errors but,
This may be a mistaken assumption. Your abbreviated code is missing a couple of closing parentheses, but ran fine for me without any meaningful adjustments.
When calling getCredentials, any errors are "silently" reported through an error object. I would think you'd see a 400 response somewhere (network tab or console or both), but getCredentials() doesn't really report errors in a visible fashion by itself.
To see what is going wrong, you should add a parameter to the callback you pass to getCredentials():
AWS.config.getCredentials((err) => {
if (err) {
console.log(err);
} else {
console.log(AWS.config.credentials.accessKeyId)
console.log(AWS.config.credentials.secretAccessKey)
console.log(AWS.config.credentials.sessionToken)
}
});
For reference, one commonly encountered error object looks like this. Note that the useful message is found in originalError.message:
{
"message": "Could not load credentials from CognitoIdentityCredentials",
"code": "CredentialsError",
"time": "2018-06-03T15:19:02.078Z",
"requestId": "71b03b4a-6741-11e8-98af-b70a114474f8",
"statusCode": 400,
"retryable": false,
"retryDelay": 94.28032122526344,
"originalError": {
"message": "Invalid login token. Issuer doesn't match providerName",
"code": "NotAuthorizedException",
"time": "2018-06-03T15:19:02.078Z",
"requestId": "71b03b4a-6741-11e8-98af-b70a114474f8",
"statusCode": 400,
"retryable": false,
"retryDelay": 94.28032122526344
}
}
The corresponding 400 in the Network tab contains this response:
{"__type":"NotAuthorizedException","message":"Invalid login token. Issuer doesn't match providerName"}

OpenWhisk invoke watson text to speech action from an action

I am trying to invoke an action included into Watson system package (text to speech) from an OpenWhisk action.
I have binded the service and set-up the credentials and so from the CLI I can see
wsk list
entities in namespace: xxxxxx
packages
/xxxxxx/myWatson private binding
Here is my OpenWhisk action:
function main(param) {
//code here for my action. At the end, I invoke the text to speech
if (...) {
textToSpeech(param.text);
}
else {
return whisk.error(error);
}
return whisk.async();
}
function textToSpeech(text){
whisk.invoke({
name:'myWatson/textToSpeech',
parameters:{
payload: text,
voice: 'en-US_MichaelVoice',
accept: 'audio/wav',
encoding: 'base64'
},
blocking: true,
next: function(error, activation){
if(error){
return whisk.error(error);
}
else{
return whisk.done({msg:'success'});
}
}
});
}
And I get the following error
"response": {
"result": {
"error": "The requested resource does not exist. (undefined)"
},
"status": "application error",
"success": false
}
Can you help understanding what I am doing wrong?
The name of the action should be fully qualified to include the namespace. From your CLI output, it looks like your package is /xxxxxx/myWatson so your action reference in the whisk.invoke should be /xxxxxx/myWatson/textToSpeech.

Resources