Refresh a sidebar after pushing a card to the room

php
hipchat
javascript

#1

So, to start off, Im developing an integration for my company in PHP. Its ben pretty successful so far and have only hit a couple of road blocks.

In my integration, my room user will type in a slash command, lets call that ‘/doit some stuff’, and my integration pulls his user info and the message, stores it in my DB, and returns a card to the room with whatever info should be on the card. This is all working flawlessly.

I have a web panel/right sidebar view with a list view of all the entries in that DB, from each time a user entered /doit

I want this web panel to refresh after that card is posted to the room (I’m posting the card to the room via curl to a notification URL) and I have not been able to do that.

I feel like I can keep checking the latest history in the room via JS and refresh the sidebar via js whenever I find a card, but then Im hitting the api server constantly.

Better suggestions?


#2

There are a couple of JavaScript events you can listen to and refresh the sidebar if the message matches what you’re looking for. Take a look at the docs here https://developer.atlassian.com/hipchat/guide/javascript-api#JavascriptAPI-RespondingtoUpdates


#3

I thought those would help me also about a week ago, but I couldnt get them to work. The eceive-parameters func right above it works, but the message-received func doesnt fire. Ive had other tests after that didnt fire either, heres my code, perhaps you can tell me why?

HipChat.register({
			  'receive-parameters': function(p) { 
                                           //this works and I do get params from the Hipchat.opn.sideview event
                                            alert(JSON.stringify(p)); 
				  
			  },
			  
			"message-received": function(data) {
					// Event is triggered when messages are received from your addon
					//this is alerting nothing
                                         alert(JSON.stringify(data));
			    },

			});

#4

@rwhitbeck I was just messing with something and this alert started to go off, so I thought I would drop some comments on this thread really quick:

I was posting cards into the room from my addon via slash command and this alert did not fire at all. I would enter “/something and heres more stuff” and the card would get curl’ed into the room with no problem, and this message-received function did nothing.

So today I happen to messing with my other webhook functions (adding conditionals as you suggested as no one else has posted any better way, thanks!) and so I enter “/anothercommand some more stuff” and I get that stringified alert from message-received when my function echos back its json ( literally: echo ‘{“message”:"’.$data[‘id’].’ Unacknowledged"}’; ) . I had not been messing around in the webhook functions until today and this was totally unexpected!

So I guess I need to ask a better question. I feel like typing into the room/getting a card back are both message-received events. Just as entering “/something some stuff” and getting back echo ‘{“message”:"’.$data[‘id’].’ Unacknowledged"}’;. For the sake of argument, lets assume that only the “getting a card back” and “echo '{“message”:”’.$data[‘id’].’ Unacknowledged"}’;" are the only things that count as message-received. What makes one different than the other, what makes one response to the room fire an event and not the other? Is it because the card is HTML (I am passing the plain text “message” field in the json fyi) and the echo is plain text json?


#5

@rwhitbeck I should also add to this that after having my computer on all night with hipchat running. I came back this morning and the js alert for message-received would NOT fire when I entered the same commands that worked yesterday. I closed and restarted hipchat and those commands then triggered the message-received alert. I cant really force my users to restart their client to re-up the javascript engine or whatever is running this, so what to do?