Run-headless is not working
Closed this issue · 2 comments
I maintain the chatbot John Cavil in Root Access. For some time (I'm not sure how long; maybe a couple weeks?), the driver I wrote to start the chatbot in PhantomJS using Selenium/Java has not worked.
Thinking that maybe you guys hit a similar problem and fixed it, I then tried your run-headless.js
script. I did edit the script to configure it for our room, but the bot never even shows up in our room.
var config = {
email: 'my_email@gmail.com',
password: 'my password',
siteUrl: 'https://superuser.com',
roomUrl: 'https://chat.stackexchange.com/rooms/118'
};
My specs:
- Ubuntu 14.04.2 LTS 64-bit
- PhantomJS 2.x compiled from git master 07/29/2015
- NodeJS from the official NodeSource repository, version 0.12.7
- Nightmare installed fresh via
npm
- SE user account specifically for the bot, who has >20 rep (and has for years) and is able to manually login and chat in Root Access with no issues
- Bot account authenticates via Stack Exchange (not Google or any of the OpenID alternatives)
- Bot script is a minor fork of Zirak upstream with modifications for Root Access (removing the
summon
command,welcome
is manual only, etc.) - here; diffs here
Questions:
- Why no worky?
- Does it work for anyone else, or is it just me?
Console output, which looks suspicious but I'm not sure what exactly is wrong:
$ nodejs run-headless.js
Need to authenticate
Injected chatbot.
phantom stdout: SyntaxError: JSON Parse error: Unrecognized token '<'
phantom stdout: https://raw.githubusercontent.com/allquixotic/SO-ChatBot/master/master.js:2653 in parse
https://raw.githubusercontent.com/allquixotic/SO-ChatBot/master/master.js:2653 in finish
https://raw.githubusercontent.com/allquixotic/SO-ChatBot/master/master.js:306
Should be done loading stuff.
You are now in a REPL with the remote page. Have fun!
In master.js:
//the input is not used by the bot directly, so you can implement it however
// you like
var polling = bot.adapter.in = {
//used in the SO chat requests, dunno exactly what for, but guessing it's
// the latest id or something like that. could also be the time last
// sent, which is why I called it times at the beginning. or something.
times : {},
firstPoll : true,
interval : 5000,
init : function ( roomid ) {
var that = this,
providedRoomid = ( roomid !== undefined );
roomid = roomid || bot.adapter.roomid;
IO.xhr({
url : '/ws-auth',
data : fkey({
roomid : roomid
}),
method : 'POST',
complete : finish
});
function finish ( resp ) {
///The offending line is the following
resp = JSON.parse( resp );
bot.log( resp );
that.openSocket( resp.url, providedRoomid );
}
},
I ended up having to alter the script to add a few delays between inputs. Not sure if this is the root of the issue, but it did solve it for me.
function seLogin () {
hound
.type('#email', config.email)
.wait()
.type('#password', config.password)
.wait()
.click('#submit-button')
.....
note: I also changed the selectors. #se-login is now #se-login-form if you prefer to use the attribute selectors... but the inputs have id's so why not use them.
allquixotic@88d9eac works for me. You guys can pull to Zirak master if you wish, but I've already pushed this to my fork.