Passing request parameters from HipChat action to sidebar

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

This widget could not be displayed.

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!

This widget could not be displayed.

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.

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.

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

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
});

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published Aug 10, 2018 in Hipchat

What should I think about when migrating HipChat to Slack?

...from the beginning. We have built up a lot of content in HipChat, with it being a core tool in our distributed company model. While it is true that we didn’t need to move to Slack immediately, we felt it...

241 views 1 9
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