I've written this module for Kassy to search anime via the HummingBird API. The module loads fine and even the help command /help humming
returns the appropriate help message. But I can't get it to respond to search queries
The console just displays
An unhandled error occurred. Start as debug for details.
and continues listening to the next message. I have tried running the console in debug mode (as mentioned in the Kassy docs) but the console displays the same message. I have tried installing the module with KPM but same results.
These are the two files in the directory named humming
inside the modules
directory
humming.js
console.debug('line 10');
var request = require.safe('request');
/*
* Paths
*/
var HUMMINGBIRD_HOST = "hummingbird.me/api/v1";
var HUMMINGBIRD_SEARCH = "/search/anime/";
exports.match = function(text, commandPrefix) {
console.debug('line 23');
return text.startsWith(commandPrefix + 'humming');
};
/*
Method that provides help strings for use with this module.
*/
exports.help = function(commandPrefix) {
return [[commandPrefix + 'humming <query>','Searches Anime or Manga when you are too lazy to make a few clicks']];
};
/*
The main entry point of the module. This will be called by Kassy whenever the match function
above returns true.
*/
exports.run = function(api, event) {
var query = event.body.substr(8);
console.debug('line 40');
search(query, function(error, response){
// Callback calls the parser if no errors were registered
if(error !== null){
api.sendMessage(parse(response), event.thread_id);
} else{
console.debug(error);
}
});
};
function parse(query){
// testing
return JSON.stringify(query);
// return 'parser reached';
}
/**
* Retrieves information about an anime as a JSON object.
*
* query: string to search
* callback: takes the error, and data
*/
function search(query, callback) {
request.get({
url: "https://" + HUMMINGBIRD_HOST +
HUMMINGBIRD_SEARCH + "?query=" + query,
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
}, function(err, res, body) {
console.debug('line 73');
if(err) {
if(res) {
callback("Request error: " + err + ", " + res.statusCode, body);
}
else {
callback("Connection error: not connected to internet", body);
}
}
else {
callback(null, body);
}
});
}
kassy.json
{
"name": "humming",
"version": 2.0,
"startup": "humming.js"
}
You will notice some calls to the debugger log but those are never shown in debug mode, so I'm not sure whether the module isn't being executed at all or if my debugging is faulty. This is the startup command I used to enable debugging
node debug main.js facebook test
I have tried renaming the module as well to test
, manga
, anime
, etc. assuming there might be ambiguity in the system but nothing changed.
I'm unsure about my implementation of request.get
method as I'm new to Javascript and have followed the method syntax from this GitHub project
You can find my module's files on Github as well And find out more about Kassy here