I'm trying to add API.AI middleware to my Botkit on Facebook Messenger.
However, it doesn't return anything from API.AI.
Anyone had success implementing API.AI with Botkit?
controller.middleware.receive.use(apiai.receive);
controller.hears(['apiai'],'message_received',apiai.hears,function(bot, message) {
console.log('APIAI: ', message)
});
P.S. Here's the API.AI middleware https://github.com/abeai/botkit-middleware-apiai
I had the same problem. Had to figure out, that the first argument of controller.heares (in your case 'apiai') has to exactly match the intent's name on your apiai agent. The other problem you may have is logging the message object to the console. I'd eighter stringify
JSON.stringify(message)
it or log message.intent to the console. Hope This helps.
Related
Can we use SSML in dialogflow JSON Response from webhook i.e. without using Google Assistant client library.
Basically I would like to return SSML subalias in the response from my webhook hosted on AWS Lambda.
I tried to search if it is possible using dialogflow JSON response, but not able to find it anywhere.
Added the following in
"textToSpeech": '<speak><sub alias="Indian Premier League"> IPL</sub></speak>'
This question already has an answer here:
Making an HTTP POST request from fulfillment in Dialogflow
(1 answer)
Closed 4 years ago.
We are creating an action that will take user's input and create an entity in our database (datastore).
Ideally, we would like to be able to access the user's raw input audio, but it doesn't seem that is possible.
As a work around we are going to send the speech-to-text of user's utterance to our backend services. We are using firebase cloud functions for our fulfillment and an external rest api for our crud operations.
We are trying to make a post request in a webhook to create an entity based on user's input, but when I check my logs it doesn't seem like the post request is reaching our service. I'm not able to debug what or if we are getting a response back
app.intent('favorite color', (conv, {color}) => {
const options = {
// options
};
function callback(error, response, body) {
// log response or error
}
request(options, callback);
const luckyNumber = color.length;
// Respond with the user's lucky number and end the conversation.
conv.close('This word has ' + luckyNumber + ' letters.');
});
// Set the DialogflowApp object to handle the HTTPS POST request.
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
This question is not the same as the one that it was marked as a duplicate because the solution was the account type not supporting POST requests to an external API and not the HTTP Client we were using
The Inline Editor in the Dialogflow console uses Firebase Cloud Functions, as you already know.
Unfortunately, Firebase Cloud Functions DOESN'T support external API calls in it's free plan. You may need to switch to blaze plan or deploy your fulfillment elsewhere.
I built a custom webhook as a fulfillment endpoint for a Dialogflow intent. It works fine when I respond with raw JSON, ie: {'fullfillmentText':'hi'},
but does not seem to work using the "actions-on-google" library.
The code from their website implies this should work:
app.intent('myintent', (conv) => {
conv.close('See you later!');
});
But it does not. Google Home just says my app isn't responding. It might be that as it stands my function (using Fn Project) has to return JSON and if I return JSON as a response that it isn't expecting it fails. Maybe someone can shed some light?
Edit 1:
I'm using a custom webhook using the Fn Project open source functions as a service. Demonstrating how to use the project is my purpose here so I don't want to use inline editor or Google Cloud Functions or firebase or any other default option.
Here's the rest of the code
const fdk = require('#fnproject/fdk');
const request = require('request');
const dialogflow = require('actions-on-google');
const app = dialogflow({
debug: true,
});
fdk.handle(function (input) {
app.intent('myintent', (conv) => {
conv.ask('I could not understand. Can you say that again?');
});
return {'fulfillmentText': 'response from webhook'}
});
Although you are creating the app object, which does the Intent handler processing and such, and registering a handler with it via app.intent(), you're not doing anything to "export" it so app's methods are called when the webhook is triggered. When called, it gets the body of the request and will format the JSON for the response.
If, for example, you were using Firebase functions, you would connect app to be handled through the functions with something like
exports.fulfillment = functions.https.onRequest(app);
But you're not. You're using a different framework.
The library comes with a number of frameworks that are supported out of the box, but the Fn Project isn't one of them. In theory, you can create your own Framework object which will do this for you (the "Frameworks" section of this article discusses it briefly, but doesn't go into details about how to do so).
As you surmise, it may be easiest for you to just read the JSON request and generate the JSON response yourself without using the actions-on-google library. Or you can look into a library such as multivocal to see if it would be easier to leverage its multi-framework support.
I've created a FB chatbot with botkit and I'm trying to connect a dialogflow middleware.
For some reason, when I connect the middleware like so I don't get any response:
bot.js:
var dialogflowMiddleware = require('botkit-middleware-dialogflow')({
token: process.env.dialogflow
});
controller.middleware.receive.use(dialogflowMiddleware.receive);
controller.hears('test', 'message_received', dialogflowMiddleware.hears, function(
bot,
message
) {
console.log('MESSAGE:', message);
bot.reply(message, 'Hello!');
});
Things I've done:
Use Dialogflow API v1
Use correct client access token
Corretly named my intent 'test'
Removed the middleware and tested it was working (to ensure problem is down to something else)
When a facebook messenger user start a conversation I want to get the data like name, photo, etc ... and send to my API.
But I'm doubtful when I should do this.
It would be in the:
bot.on('conversationUpdate', (session) => {
// On here??
})
Facebook doesn't support the conversationUpdate event. It won't send events when you start a conversation, however you could solve your issue in two different ways.
Create a custom middleware that checks if you already have the userData from Facebook and retrieve it when you don't have it yet.
Create a custom middleware that translates Facebook's callbacks to intents
I already created those for NodeJS, which you can use in your bot. BotBuilder-FacebookExtensions
If you need more guidance, you can read the blogs I wrote about this:
How to retrieve User Data from Facebook /
How to process Facebook Messenger callbacks