node.js - Slackbot running on express server, add response to store -
i trying make a simple slack bot work, @ time of day, private message sent out asking team member has learnt day, , want store response data store, , array of objects, team can reference when need know knows what, etc.
i using slackbots node wrapper calls, , bot running on express server want use hand db stuff (it filesystem db @ moment diskdb). can functions of bot work, easy enough, don't know how can save message response db.
the bot code this
const slackbot = require('slackbots'); const http = require('http'); const bot = new slackbot({ token: 'xoxb-161286416421-euhc2t0a96gsykddjpk2zjrt', name: 'botivate' }); const params = { icon_emoji: ':robot_face:' } const options = { host: 'localhost', port: '9000', path: '/responses', method: 'post' }; bot.on('start', function() { bot.postmessagetouser('locky', 'botivate online', params); }); bot.on('message', function(data) { if(data.type === 'message') { let postdata = { user: data.user, text: data.text, dateadded: new date() } [here save postdata] } }) bot.on('close', function(data) { bot.postmessagetouser('locky', 'botivate powering down', params); }) module.exports = bot;
i want save postdata
store.
i have route this:
const express = require('express'); const bodyparser = require('body-parser'); const router = express.router(); let db = require('diskdb'); db = db.connect('./database',['responses']); router.route('/') .post((req, res) => { let response = { user: req.body.user, text: req.body.text, dateadded: new date(), dateupdated: null }; console.log(response); res.json(db.responses.save(response)); }) .get((req, res) => { res.json(db.responses.find()); }) module.exports = router;
diskdb has similar scheme mongoose mongodb
how can send postdata
route save it? tried use http.request
kept getting errors buffer. file diskdb saves .json , 1 big array.
could require in jquery , use ajax shorthand within server, pass onto route?
Comments
Post a Comment