It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How do i read the webhook data from Hipchat?

Danny Dainton Nov 01, 2016

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
Answer accepted
Christopher Rivers Atlassian Team Nov 01, 2016

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.

Danny Dainton Nov 01, 2016

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
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Hipchat Cloud

Hipchat Cloud and Stride have reached End of Life (updated)

All good things come to an end - thanks to all our customers and partners who have been along the Hipchat and Stride journey with us.  As of Feb 15th 2019, Hipchat Cloud and Stride have reached ...

33,182 views 7 8
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you