Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Passing request parameters from HipChat action to sidebar

Rob Laveaux June 14, 2016

I'm developing an add-on that uses a message action. The action opens a sidebar view.

How can I send the ID of the message as a request parameter to the sidebar view?

I need to know which message the user clicked, so that I can fill the sidebar with data related to this message.

 

2 answers

2 votes
rich
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 15, 2016

Here's how it works. First, you register your message action in your descriptor:

...
    "action": [
        {
          "key": "my.message.action",
          "name": {
            "value": "Send this to the sidebar"
          },
          "target": "my.sidebar",
          "location": "hipchat.message.action"
        }
      ]
...

Take note of the action's key (my.message.action). That's the event you need to subscribe to in your JS:

HipChat.register({
  "my.message.action": function(message) {
    console.log(message)
  }
});

That's it!

Now, when you click on the "Send this to the sidebar" action on a message, you should get something like this in your console:

{
  "body": "This is a test",
  "sender": {
    "id": 51380,
    "name": "Rich Manalang",
    "mention": "rich"
  },
  "mid": "a4444933-56ca-4fb8-8f1c-319635835617",
  "type": "message",
  "metadata": {}
}

Cheers!

0 votes
Steffen Opel _Utoolity_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 14, 2016

Pages loaded in HipChat dialogs or the sidebar can facilitate the Javascript API - in particular, you might want to look into Working with Sidebar Views, which illustrates how to pass parameters to the sidebar view and and receive them fin the sidebar iframe in turn.

Rob Laveaux June 14, 2016

Hi Steffen, thank you for your answer. I have already read this part of the documentation, but can't get it to work. I'm calling AP.register from the sidebar during $(document).ready(), using the action key in the parameters. But the callback function is not triggered.

Where and when does AP.register need to be called?

Secondly is it possible to call a JavaScript function when a message action gets clicked? This way I could use HipChat.sidebar.openView and pass the required request parameters.

Please provide examples if you can, because the documentation lacks some important details to get things working.

Steffen Opel _Utoolity_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 15, 2016

@Rob Laveaux - it's been a while since I last worked with those APIs myself in a PoC, so I'm unable to provide more detailed guidance myself right now. That being said, if you are looking for specific examples, I recommend checking out the well maintained HipChat Connect Tester sources, which should at least provide more insight/guidance on how those APIs are supposed to be used, or by chance even provide the exact code you are looking for - good luck!

Rob Laveaux June 17, 2016

Thank you, I found my mistake. I was calling AP.register multiple times to register different handlers. This overwrites the handlers on each call.

Instead I need to call AP.register once with an array of handlers. Like this:

AP.register({
      "message.send.to.addon": showMessage,
      "receive-parameters": showMessage
});
Fernando Boucquez (PPL) September 6, 2016

In addition to Rob's comments, It looks like HipChat.register and Ap.register overwrite each other so second call may unregister first even listeners.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events