no responses defined for platform: google_telephony at webhookclient.send_ - dialogflow-es

I am trying to integrate dialogflow phone gateway with my dialogflow bot.
one specific intent uses the response of function written in inline editor (fulfillment). when the function is called it throws following error:
Error: No responses defined for platform: GOOGLE_TELEPHONY
at WebhookClient.send_ (/srv/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:488:13)
at promise.then (/srv/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:306:38)
at
at process._tickDomainCallback (internal/process/next_tick.js:229:7)
this same flow works perfectly fine with google home and the action simulator.
I have tried:
https://github.com/dialogflow/dialogflow-fulfillment-nodejs/issues/117
let context = {'name': 'context-name', 'lifespan': 2, 'parameters': {'param': agent.parameters.param}};
agent.setContext(context);
agent.add(' this is the response text');

I was able to solve the problem by changing the version of dilogflow-fulfillment to the latest i.e. 0.6.1 in package.json, also replaced
agent.setContext();
With
agent.context.set();
Also you cannot use multiple agent.add() in single webhook call, because only the first one will get resolved.

I faced this problem and the following helped me
agent.end("");
This needs to be inserted at the end of the function
Try it

Related

What is the proper way to return a JSON object to Alexa Smart Home or end AWS Lambda in NodeJS?

I have seen three ways to return a JSON object or end a Lambda function. My trigger is Smart Home Alexa.
I am using now is context.succeed(response_JSON);This one works for me. Even if this instructions is inside a nested function. The whole Lambda ends and return the response_JSON to Smart Home Alexa.
I have seen in other blogs that say callback(response_error,response_JSON). This one did not work for me. It did not return anything to Smart Home.
Others just uses the return response_JSON. I have not used this one.
I am using now is context.succeed(response_JSON);This one works for me. Even if this instructions is inside a nested function. The whole Lambda ends and return the response_JSON to Smart Home Alexa.
context.succeed()/fail() causes the Lambda function to terminate immediately. However, I have not seen this documented in the context object docs, so it may get deprecated in later Node versions (?).
I have seen in other blogs that say callback(response_error,response_JSON). This one did not work for me. It did not return anything to Smart Home.
This one probably doesn't work for you because by default Node.js waits for the event loop to be empty before executing the callback statement. This may be due to open network/database connection. As per the doc, set the context.callbackWaitsForEmptyEventLoop variable to false to send the response right away.
Others just uses the return response_JSON. I have not used this one.
This should be used with async handlers. Read more about async and non-async handlers here: https://docs.aws.amazon.com/lambda/latest/dg/nodejs-handler.html

Get specific message from specific channel

Purpose: I'm trying to make my bot check for reactions from a specific message.
I've read this post: Get Message By ID: Discord.js
But it didn't help at all.
I've searched the internet to see how can I use .fetchMessage properly. But unfortunately didn't find any results.
This is my code:
client.channels.get('CHANNEL ID').fetchMessage('MESSAGE ID').then(async msg => { *CODE HERE* });
This is the error i get:
TypeError: client.channels.get is not a function
I do realise that client.channels.get is not a function and I should use this in a function but I don't know how to.
Discord.js version: 12.0.2
Node.js verison: 12.13
That answer was for v11, in v12 it has changed to:
client.channels.cache.get(chid).messages.cache.fetch(mesid)
However, it's important to note that client.channels.cache may contain non-text channels, if you are retrieving an ID that you know to be a TextChannel type, you will be fine but if the ID is being retrieved programmatically you need to check to ensure it is an instanceof TextChannel.
In v12 it has changed and uses managers and added this command to my bot and fixed it.
let channelMessage = client.channels.cache.get(channel_id) // Grab the channel
channelMessage.messages.fetch(message_id).then(messageFeteched => messageFeteched.delete({timeout: 5000})); // Delete the message after 5 seconds

Mocking LUIS response with LuisRecognizer not working

I am trying to mock calls to LUIS via nock, which uses the LuisRecognizer from botbuilder-ai. Here is the relevant information.
The bot itself is calling LUIS and getting the result via const recognizerResult = await this.dispatchRecognizer.recognize(context);. I grabbed the actual result as below:
{"text":"I want to look up my order","intents":{"viewOrder":{"score":0.996454835},"srStatus":{"score":0.0172454268},"expediteOrder":{"score":0.0108480565},"escalate":{"score":0.007967358},"qna":{"score":0.00694736559},"Utilities_Cancel":{"score":0.005627355},"manageProfile":{"score":0.004953466},"getPricing":{"score":0.001781322},"Utilities_Help":{"score":0.0007197641},"getAvailability":{"score":0.0005667514},"None":{"score":0.000321137835}},"entities":{"$instance":{}},"sentiment":{"label":"negative","score":0.171873689},"luisResult":{"query":"I want to look up my order","topScoringIntent":{"intent":"viewOrder","score":0.996454835},"intents":[{"intent":"viewOrder","score":0.996454835},{"intent":"srStatus","score":0.0172454268},{"intent":"expediteOrder","score":0.0108480565},{"intent":"escalate","score":0.007967358},{"intent":"qna","score":0.00694736559},{"intent":"Utilities.Cancel","score":0.005627355},{"intent":"manageProfile","score":0.004953466},{"intent":"getPricing","score":0.001781322},{"intent":"Utilities.Help","score":0.0007197641},{"intent":"getAvailability","score":0.0005667514},{"intent":"None","score":0.000321137835}],"entities":[],"sentimentAnalysis":{"label":"negative","score":0.171873689}}}
For the sake of brevity, I'll just call this "recognizerResult" in the below. I'm successfully intercepting the API call in my test file with nock, with the configuration as follows:
nock('https://westus.api.cognitive.microsoft.com')
.post(/.*/)
.reply(200,{recognizerResult});
I've tried returning both as a JSON object and a string, though I'm almost certain this needs to be JSON object as shown (I'm mocking a call to QnA maker with the same approach that is working). When I run this test via mocha, I get the following error:
TypeError: Cannot read property 'replace' of undefined
at LuisRecognizerV2.normalizeName (node_modules\botbuilder-ai\src\luisRecognizerOptionsV2.ts:96:21)
at luisResult.intents.reduce (node_modules\botbuilder-ai\src\luisRecognizerOptionsV2.ts:104:31)
at Array.reduce (<anonymous>)
at LuisRecognizerV2.getIntents (node_modules\botbuilder-ai\src\luisRecognizerOptionsV2.ts:102:32)
at LuisRecognizerV2.<anonymous> (node_modules\botbuilder-ai\src\luisRecognizerOptionsV2.ts:81:27)
at Generator.next (<anonymous>)
at fulfilled (node_modules\botbuilder-ai\lib\luisRecognizerOptionsV2.js:11:58)
at process._tickCallback (internal/process/next_tick.js:68:7)
I've looked at the code in question within the luisRecognizerOptionsV2.ts file, but can't see where there's an issue. The replace is part of normalizing the intent name, which is there to replace unsupported characters with an "_". The bot runs normally when deployed to Azure (and locally), and the tests work without mocking the call. However, I really want to be able to test this without making actual LUIS calls. Any ideas why I am getting this error and how to fix?
For reference, here is the mock to QnA Maker that is working, though note that I'm using a simple REST call for that instead of the recognizer.
nock('https://myqnaservicename.azurewebsites.net')
.post(/.*/)
.reply(200, {"answers": [{"questions": ["I need an unrecognized utterance for testing"], "answer": "I can hear you now!", "score": 28.48, "id": 1234}]});
The issue is that your {recognizerResult} is what gets saved to const recognizerResult, but is not what gets returned by that API call.
It takes a lot of digging to find it all, but a V2 LUIS client gets the API response, then converts it into recognizerResult.
You've got a few options for "fixing" this:
Set a breakpoint in that node_modules\botbuilder-ai\src\luisRecognizerOptionsV2 file on that const result = line and grab luisResult.
Use something like Fiddler to record the actual API response and use that
Write it manually
For reference, you can see how we do this in our tests:
nock()
Recorded response
You can see that our nock() returns response.v2, which does not contain .topScoringIntent, which is what it's looking for, which is why the error is throwing.
Specifically, the mock response needs to be just the v2/luisResults attributes. In other words, when using the luisRecognizer, the response set in nock needs to be
.reply(200,{ "query": "Sample query", "topScoringIntent": { "intent": "desiredIntent", "score":1}, "entities":[]});
If you look at the test data linked above, there are other attributes in the actual response. But this is the minimum required response if you are just trying to get topIntent to test routing. If you needed other attributes you could add them, e.g. you could add everything within v2 as in this file or some of the more involved files with things like multiple intents.

DiscordAPIError: Invalid Form Body when trying to send embeds

This is one of the first commands I wrote whilst I've been learning, and recently it stopped working. I fiddled with it a little, but can't see where the problem comes from. When I run ~userinfo the following error comes up in the console:
Unhandled Rejection at: DiscordAPIError: Invalid Form Body
embed.footer.icon_url: Not a well formed URL.
This is the code for userinfo:
if (command === 'userinfo') {
var embed = new Discord.RichEmbed()
.setTitle('User Info')
.addField('Username', message.author.tag)
.addField('Server', message.guild.name)
.setColor(0xFF8AFF)
.setThumbnail(message.author.avatarURL)
.setFooter('Akasuki', version, client.user.avatarURL);
message.channel.send(embed);
}
Changing message.channel.send() to message.channel.sendEmbed() brings up errors, and there's been nothing wrong with using send() so far.
Also, this isn't necessary but if anyone knows how to add when the users account was created, to this embed it would be very helpful. Or even a resource or couple? Thanks for reading.
Used Cursed's solution (in comments):
"Change .setFooter('Akasuki', version, client.user.avatarURL); to .setFooter(`Akasuki ${version}`, client.user.avatarURL);"
Works perfectly! Thank you so much!

Sheets doesn't exist on my googleapis object

I'm trying to use the google sheets api. I've followed this tutorial
https://developers.google.com/sheets/api/quickstart/nodejs
But every time i execute this line
var sheets = google.sheets('v4');
I get this error
TypeError: Object #<GoogleApis> has no method 'sheets'
Any ideas where i'm going wrong? I followed the guide pretty precisely.
Thanks
You may refer with this post. You might encounter this error if you are trying to call a method of an object which does not exist. However, if the property does exist, but is not a function, you'll get an error like: TypeError: Property 'bar' of object #<Object> is not a function. It is simply the default error thrown when a property doesn't exist on an object.
It turned out I was using an old enough verison of node that it the googleapi doesn't support sheets yet.
Updating my node version fixes the issue.

Resources