- Run bot as a pear app (via Pear.worker)
- Auto restart bot on update (via Pear.updates)
- create
index.js
as the main entry point, then runbotService.main(<path-to-bot>)
- create
bot.js
, then implement the bot handler insidebotService.run(<bot-handler>)
bot-handler
receives paramsargs
bot-handler
should return aclose
function to teardown the bot
// index.js
const botService = require('@holepunchto/bot-service')
botService.main('bot.js')
// bot.js
const botService = require('@holepunchto/bot-service')
botService.run(async (args) => {
// bot handler goes here
const interval = setInterval(() => {
console.log('I am bot', args)
}, 1000)
return {
// return 'close' function to teardown bot
close: () => clearInterval(interval)
}
})