Hey,
I've created a custom slash command to return data when a user writes in a specific room. This is only working if I hard code a value on my API endpoint. I'd really like to return "12345" from a message sent like "/notes 12345"
I can't figure out how I need to configure my node API endpoint to get the value contained in the message body. Would i need to have something specific to handle the incoming data?
app.post("/notes", function(req, res, body) { var value = req.body.message; //This works if I use Postman but I want it to be from the entered value in the room //by the user.
I've used RequestBin to get the raw data
{ "event": "room_message", "item": { "message": { "date": "2016-11-01T16:24:35.109356+00:00", "from": { "id": int, "links": { "self": "string" }, "mention_name": "DannyDainton", "name": "Danny Dainton", "version": "string" }, "id": "string", "mentions": [], "message": "/notes 67898", <<<---- I want this value "type": "message" }, "room": { "id": int, "is_archived": bool, "links": { "members": "string", "participants": "string", "self": "string", "webhooks": "string" }, "name": "string", "privacy": "string", "version": "string" } }, "oauth_client_id": "string", "webhook_id": int }
How would I get this working on a POST request to my node express API. Would I need to use JSON.parse or stringify or something like that? I really am clueless at this point.
Many Thanks in Advance,
Danny
It sounds like you're using the tutorial for Node connect-expression. I think the example you're looking for can be found at: https://developer.atlassian.com/hipchat/tutorials/getting-started-with-atlassian-connect-express-node-js#Gettingstartedwithatlassian-connect-express(Node.js)-AddingaWebhook
app.post('/echo-webhook', addon.authenticate(), //JWT validation function(req, res) { var messageTxt = req.body.item.message.message; hipchat.sendMessage(req.clientInfo, req.identity.roomId, messageTxt) .then(function(data){ res.sendStatus(200); }); } );
The data you're looking for should be able to be found in req.body.item.message.message. You shouldn't need to do any special JSON parsing, that part is already done for you by the framework.
Thanks Chris!
It wasn't a tutorial i was following, it was my own attempt to knock something together.
Your answer gave my brain a kick though and the "req.body.item.message.message" help me out loads and now it's all working great!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.