can't reproduce examples
Opened this issue · 8 comments
Hello. I didn't know where to ask this, sorry if this isn't the place for it.
I'm trying to reproduce the examples on the readme file, but despite my efforts, I cant. I first created an app on heroku, then created a simple bot directly using methods that fb gives in its documentation. Now i'm trying to make broid-kit work but looks like i'm missing something.
index.js on heroku
const Bot = require("@broid/kit");
const BroidMessenger = require("@broid/messenger");
const token = process.env.FB_PAGE_ACCESS_TOKEN
const vtoken = process.env.FB_VERIFY_ACCESS_TOKEN
const express = require('express')
const app = express()
const bot = new Bot({
logLevel: "info"
});
bot.use(new BroidMessenger({token: token, tokenSecret: vtoken}));
app.use("/", bot.getRouter());
app.listen(process.env.PORT || 5000);
// Listening for public starting by regex match for `hello`
bot.hear(".*", "Group")
.subscribe((data) => {
console.log("Data:", JSON.stringify(data, null, 2));
// Reply to the message
bot.sendText("Hi, How are you?", data.message);
});
This should return a message at every message sent, right?
Yep it looks like that should work just fine, if you're in group messages. If you'd like to listen for both Group and Personal messages for example, you can do something like this.
const Observable = require('rxjs').Observable;
Observable.merge(bot.on('Group'), bot.on('Person'))
.subscribe((data) => {...})
We'll be adding a method in the future as something like all
or similar. Also, were you able to setup your Facebook application correctly where it was able to authorize with Broid?
Huh. Tried adding this lines, no difference though. Yeah, the fb app authtorize when it hits the webhook, it's webhook/messenger
right? And, when I send a chat message, messenger sends the event to the webhook, but is not sending back any message. Heroku's log when I send a massage to the bot.
2017-07-04T05:32:57.126294+00:00 heroku[router]: at=info method=POST path="/webhook/messenger" host=test-tbot.herokuapp.com request_id=85c17d7c-f48f-49f3-9e61-5f7e3fbf4ae9 fwd="173.252.88.191" dyno=web.1 connect=1ms service=84ms status=200 bytes=201 protocol=https
Also, when I deploy, heroku logs this. For what I've seen of broidkit's code, looks like just a building log
2017-07-04T05:31:20.574964+00:00 app[web.1]: {"pid":4,"hostname":"f906d43a-eaf8-4f57-943f-c95ac6ab8862","name":"broidkit","level":30,"time":1499146280571,"method":"use","message":"Integration: messenger","v":1}
I made the repository public if you want to check it out. I think I have all the dependencies.
This code should work. Do you have any other logs/info to help you?
Sadly I don't have anymore logs
Started to think that could be something with heroku. Could it be? huh
I'll try other host system by tomorrow
if it helps: my heroku logs from todays attempts. The log file is much larger, but these lines repeats on and on
2017-07-05T08:56:38.708829+00:00 heroku[web.1]: State changed from crashed to starting
2017-07-05T08:56:40.903107+00:00 heroku[web.1]: Starting process with command node index.js
2017-07-05T08:56:43.878050+00:00 app[web.1]: {"pid":4,"hostname":"44363248-f077-4fd7-a4b1-51e7349f9cfc","name":"broidkit","level":30,"time":1499245003876,"method":"use","message":"Integration: messenger","v":1}
2017-07-05T08:56:44.486363+00:00 heroku[web.1]: State changed from starting to up
2017-07-05T08:57:13.896908+00:00 heroku[router]: at=info method=POST path="/webhook/messenger" host=test-tbot.herokuapp.com request_id=45b01303-d1d3-42a2-b466-a75b5df287e2 fwd="173.252.90.241" dyno=web.1 connect=2ms service=15ms status=200 bytes=201 protocol=https
2017-07-05T08:57:14.175378+00:00 heroku[router]: at=info method=POST path="/webhook/messenger" host=test-tbot.herokuapp.com request_id=1bdb6ec9-bce9-4a1c-ab50-b3d080b5ebaa fwd="173.252.88.92" dyno=web.1 connect=0ms service=5ms status=200 bytes=201 protocol=https
2017-07-05T08:57:14.439266+00:00 heroku[router]: at=info method=POST path="/webhook/messenger" host=test-tbot.herokuapp.com request_id=770b7ec9-39bc-47b3-bd9f-108f751e02c7 fwd="173.252.90.101" dyno=web.1 connect=1ms service=3ms status=200 bytes=201 protocol=https
2017-07-05T08:58:40.174846+00:00 heroku[router]: at=info method=GET path="/" host=test-tbot.herokuapp.com request_id=a38b48a8-53fc-43e9-8257-ab5c5d28e622 fwd="143.54.171.119" dyno=web.1 connect=0ms service=14ms status=404 bytes=383 protocol=http
2017-07-05T08:58:40.411364+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=test-tbot.herokuapp.com request_id=82f54ff4-f903-42e5-acdf-4e8d1780fc25 fwd="143.54.171.119" dyno=web.1 connect=0ms service=2ms status=404 bytes=394 protocol=http
2017-07-05T08:58:51.447539+00:00 heroku[router]: at=info method=GET path="/webhook" host=test-tbot.herokuapp.com request_id=7ba634a8-8491-430c-bb3d-2a56d57c798d fwd="143.54.171.119" dyno=web.1 connect=10ms service=42ms status=404 bytes=390 protocol=http
2017-07-05T08:59:29.506280+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/webhook/messenger" host=test-tbot.herokuapp.com request_id=bb06040a-6e6a-459e-8ed5-23abf5275c77 fwd="143.54.171.119" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0 protocol=http
thanks, we will check. I think it's something around this log line:
2017-07-05T08:59:29.506280+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/webhook/messenger" host=test-tbot.herokuapp.com request_id=bb06040a-6e6a-459e-8ed5-23abf5275c77 fwd="143.54.171.119" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0 protocol=http
I understand better the issue, it's something around this line: L221
Can you please try to log the req
body directly on the @broid/messenger
lib?
Or if you can't explain us the exact step to try to repro in our side the issue.
Hey!
I gave up on heroku and started to https tunneling my localhost env, much better. Now I have a lot of logs for you :)
Here's the log on req at the facebook auth webhook, when I first create the webhook on fb dev page.
Webhook log
I also added a console.log(req) at the router.post
L232 method, so it would give me infos of the req
when I received a message, it doesn't log anything though.
@edit: the log on router.post does log, but took a little bit of time to... Here it is: router.post log
@edit: here is my rindex.js file
const Bot = require("@broid/kit");
const BroidMessenger = require("@broid/messenger");
const Observable = require('rxjs').Observable;
const express = require('express');
const app = express();
const bot = new Bot({
logLevel: "info"
});
const messengerT = {
token: "EAATePZAKKAlIBAOO4qwxRrPuJM0ON2F68sYbpKvtJa9gfgouKoeOLkCHUWYz7xqDRkyFkGIMI3QQT4gpyyd2lMyJ5a58ZBPuagfcDLRVz8vtsAzyxCkYVu3UhKJcTnOff89ixSQQSPu6xHC8Ul2vaw81ETqDZAbtC4P99Tawub8bPJZACSbo",
tokenSecret: "avocadotoken"
};
bot.use(new BroidMessenger({token: messengerT.token, tokenSecret: messengerT.tokenSecret}));
app.use("/", bot.getRouter());
app.listen(8080);
// Listening for public starting by regex match for `hello`
Observable.merge(bot.on('Group'), bot.on('Person'))
.subscribe((data) => {
// Reply to the message
bot.sendText("Hi, How are you?", data.message);
});
Today I tried to replicate it in another enviroment, this time at my workplace.
Here is the log of the req prop in router.post method.
I tought it had something to do with the fb app privileges so I checked every permission box possible and still the same problem.
@edit: Could it be something with express server? How do I use the natural bot router system?
Here what would be the host? 127.0.0.1
?
`const bot = new Bot({
logLevel: "info",
http: {
host: "0.0.0.0",
port: 8080,
}
});
@edit 2: yup, it was something with express server. Tried this and worked perfectly
const Bot = require("@broid/kit");
const BroidMessenger = require("@broid/messenger");
const express = require("express");
const Observable = require('rxjs').Observable;
const bot = new Bot({
logLevel: "info",
http: {
host: "127.0.0.1",
port: 8080,
}
});
const messengerT = {
token: "EAATePZAKKAlIBAIbPjbk6JqT2NZC2c1qEAWNYq1c4iwa5jUZCETZCiWFO2Qw2Cbt3Dry9LplqXQXAaZBy413MkcdU06FIfZAfWUMc59V5yaWm6yHypd25ToRPZBhCqqggl1KsRDvw2s8KndZAtcZBAha7yoaGd6ZAxsCZAVhqKyrErZBlQZDZD",
tokenSecret: "avocadotoken"
};
bot.use(new BroidMessenger({token: messengerT.token, tokenSecret: messengerT.tokenSecret}));
/*// Setup express
const app = express();
app.use("/", bot.getRouter());
app.listen(8080);*/
// Listening for public starting by regex match for `hello`
Observable.merge(bot.on('Group'), bot.on('Person'))
.subscribe((data) => {
console.log("Data:", JSON.stringify(data, null, 2));
// Reply to the message
bot.sendText("Hi, How are you?", data.message);
});
`
@edit 3: It's working as expect until now. But, I'm getting this error in console: https://pastebin.com/1Tm5FJs8
I don't know what it means, just informing you in case it's something important.
Hi, I got the same issue as you when deploying on Heroku.
To make it run on heroku just remove the host parameters :
const bot = new Bot({
logLevel: "trace",
http: {
port: process.env.PORT
}
});