How do i read the webhook data from Hipchat?

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

1 answer

1 accepted

0 votes
Accepted answer

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!!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 14, 2018 in Hipchat Cloud

Hipchat Cloud and Stride End of Life: Just over 90 days away

Earlier this year we made the difficult decision to discontinue our team messaging tools, Stride and Hipchat. The end of life date for Stride and Hipchat Cloud is quickly approaching - February 15, 2...

482 views 0 2
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you