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)
Related
I set the server address for the bot with /setwebhook, now how can I get the data with only node js and https package to access {message :{...} }? (like /getupdates method) but by webhook , probably I mean like the php code but in node js: file_get_contents("php://input") .
Should I use async or https.createServer ? If yes, how and please explain a little
You have to create a server that will handle receiving the data. You can do this by using http.createServer or, more conveniently, using a library such as Express. Simple implementation using Express would look like this:
const app = express();
app.post(`/api/telegram${process.env.TELEGRAM_BOT_TOKEN}`, async (req, res) => {
const message = req.body.message || req.body.edited_message;
...
});
In this example, I use bot token in the webhook url (since I and Telegram are the only entities that know the bot token, I can be sure that the requests to the url come from Telegram). There are better ways to make the webhook secure, such as using secret_token as specified in the docs for setWebhook method.
For development purposes, you can use a service like ngrok to redirect requests from the bot webhook to localhost.
To get an idea of a fully functioning example of implementing webhook with node.js and Express, you can check my open-source project on Github.
I need to send FCM push notification from a chrome extension. I've implemented at the moment the chrome.gcm api that is the easiest way to get FCM working and I'm able to get a registration token and get incoming notifications sended from the FCM console.
Since I need to use the server key into the POST requests to the fcm endpoint to send messages, I want to setup a simple heroku backend as an alternative to cloud functions.
at the moment I have this POST request in my client code, but I'm using it only for dev the chrome extension
axios.post('https://fcm.googleapis.com/fcm/send', {
to: 'APA91bELmJY8xTU...',
notification: {
title: 'Test notification',
body: 'Some cool text payload'
}
}, {
headers: {
'Authorization': 'key=AAAA6C5BuxA:...',
'Content-Type': 'application/json'
}
}).then( (res) => {
console.log(res)
})
Into the production version I want to move this code to the heroku app.
Is possible to use firebase-functions npm package on heroku or I need to setup an express app with an endpoint?
I've found this buildpack but I'm not sure if it will give me the ability to write my heroku nodejs code like a cloud function
functions.https.onRequest( (req, res) => { ... })
Is possible to use firebase-functions npm package on heroku?
The firebase-functions package is the glue between Google Cloud Functions and your (server-side) Firebase code. There is no simple way to use it on a Heroku instance.
Setting up a custom Express endpoint sounds like the more idiomatic approach here.
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.
I couldn't find this in Twilio's API docs.
I use NodeJS. When a user texts my Twilio number, I want to use NodeJS to retrieve the message.
Where can I find this in Twilio's API reference?
Twilio developer evangelist here.
When a user texts your Twilio number there are two ways to get that message.
The first is the most efficient and uses webhooks. When you purchase your Twilio number you can configure a URL for Twilio to make a request to every time it receives an SMS for that number. The request will include a bunch of parameters, including the number the message is from and the body of the message. You can receive the request with a Node.js app, here's a quick example using express:
var app = require("express")();
var bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({extended: false});
app.post("/messages", function(req, res) {
console.log(req.body.Body); // the message body
console.log(req.body.From); // the number that sent the message
res.send("<Response/>"); // send an empty response (you can also send messages back)
});
app.listen(3000); // listens on port 3000
When developing an app that uses webhooks like this, I recommend tunneling to your local machine using ngrok.
The other way to get your messages is by using Twilio's REST API. You can list all the messages to your numbers using the messages resource. In Node.js, this would look like:
var client = require('twilio')(accountSid, authToken);
client.messages.list(function(err, data) {
data.messages.forEach(function(message) {
console.log(message.body);
});
});
Let me know if this helps at all.
I'm using node.js and passport for authentication, and I need to send 'login failed' message to the client if a user failed to authenticate. My application uses also express middleware.
I'm using angular.js in the client.
Currently I'm using that command to show a static html:
var loginStatus = 'Failed';
res.sendfile('views/login.html'); // What should I add/change here in order to send the loginStatus variable ?
And this is my angular.js controller:
function MainController($scope) {
$scope.loginStatus = // What should I write here in order to get 'Failed' ?
}
I've posted my questions on the remarks above.