Closed kamikazechaser closed 8 years ago
@kamikazechaser I think you can use middleware for that:
tg.before((update, callback) => {
//This code will be executed for all updates
//here you can call Botan.io API
callback(true) //if you pass false - update will not be handled
})
The problem is that it still crashes. Here is the code. Have you tried it any bot. if so tell me how you did it. This is how I tried
var botan = require('botanio')(000000-Kl89000) //Token Looks Something Like That
tg.before((update, callback) => {
//This code will be executed for all updates
//here you can call Botan.io API
botan.track(message, 'start');
callback(true) //if you pass false - update will not be handled
})
Do you have a sample code?
@kamikazechaser How it crashes? Show me logs.
var botan = require('botanio')(6xL22Qf6W7-1JZNIvFTKHe3So8imD9Gh)
tg.before((update, callback) => {
//This code will be executed for all updates
//here you can call Botan.io API
botan.track(message, 'start')
callback(true) //if you pass false - update will not be handled
})
With the Above i get this
/root/bot/bot.js:7
var botan = require('botanio')(6xL22Qf6W7-1JZNIvFTKHe3So8imD9Gh)
^
SyntaxError: missing ) after argument list
at Object.exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:513:28)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.runMain (module.js:575:10)
at run (node.js:348:7)
at startup (node.js:140:9)
at node.js:463:
However If I add quotes to the token like this var botan = require('botanio')('6xL22Qf6W7-1JZNIvFTKHe3So8imD9Gh')
, the bot starts and immediately stops with NO error message or stack trace
@kamikazechaser
Thats because you dont have such variable message
You can do it like this:
const botan = require('botanio')('BOTAN_IO_TOKEN')
tg.before((update, callback) => {
if (update.message && update.message.text) {
botan.track(update.message, 'Start', (error, response, body) => {
if (body && body.status === 'accepted') {
console.log(`logged message - ${update.message.text}`)
}
})
}
callback(true)
})
Hmm no errors but botan doesnt seem to be tracking. I think event listener is not set well. What do you think. have you tried it before
@kamikazechaser If there is log - "logged message" then the request to Botan was sent.
If possible integrate botan analytics with 2-3 lines.