node.jsexpresswebhookshipchat

How do i read the webhook data from Hipchat?


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 sent from hipchat. Would I need to have something specific to handle the incoming data?

 app.post("/notes", function(req, res) {

  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 send from Hipchat:

{
    "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 endpoint? Would I need to use JSON.parse or stringify or something like that? I really am clueless at this point.

Many Thanks in Advance.


Solution

  • This is all that was needed in the end. I knew it would be something simple!

       app.post("/notes", function(req, res) {
    
          var value = req.body.item.message.message;