Polis: Getting the conversation_id from the iframe

Created on 8 Nov 2017  路  10Comments  路  Source: compdemocracy/polis

Hey guys !

As some of you might know at Open Source Politics we are working on a integration between Decidim and Pol.is. You can learn more about the project and how far we've gone so far by checking this issue out. I try to post updates regularly.

Now we are entering the phase where we want to give to the admin an easy access to:

  • Moderation
  • Statistics
  • Reports
  • Exports

To do that we wanted to provide a direct link to those actions in the Pol.is admin panel for each conversation. The problem we have is that we need to be able to get the conversation id related to the page-id the conversation was created for to actually make that link.

I talked to @colinmegill, he told me that we should be able to see the conversation_id in the iframe that gets loaded on the page or that you guys could set it so we could look for it.

We found it at the end of the window.preload:
window.preload = {"conversation":{"topic":null,"description":null,"created":"1509613843216","link_url":null,"parent_url":"http://localhost:3000/processes/maxime-impedit/f/13/dataviz/summary","vis_type":1,"write_type":1,"help_type":1,"socialbtn_type":0,"bgcolor":null,"help_color":null,"help_bgcolor":null,"style_btn":null,"auth_needed_to_vote":false,"auth_needed_to_write":true,"auth_opt_allow_3rdparty":true,"auth_opt_fb_computed":true,"auth_opt_tw_computed":true,"conversation_id":"7eb8famhep"}}

We tried to access it with custom js but for now we've been unable it's seems that something is missing. As Colin mentioned it, is there anything you could set up on your side we can access it ?

Thanks a lot guys !

Most helpful comment

Hi! The snippet I pasted would be added to your page. It does rely postMessage to forward the info you need from the iframe. The updated script is currently deployed on preprod at https://preprod.pol.is/embedPreprod.js

All 10 comments

I can add an event you can subscribe to that will include the conversation object.
That would look something like this:

<script>
  var polis = window.polis = window.polis || {};
  polis.on = polis.on || {};
  polis.on.init = [
    function(o) {
      if (o.status === "ok") {
        console.log("polis loaded");
        console.log(o.conversation.conversation_id);
      } else {
        console.error("error loading");
      }
    }
  ];
</script>

Would that work for you?

Hello guys !
(I worked with @virgile-dev)

That could work but I think it wasn't clear in the initial demand :
the idea is to get the conversation_id when we create a new conversation with a site_id and page_id.
This has to happen in the parent page hosting the pol.is iframe (loaded with embed.js).

The reason we don't have access to the window.preload object from the iframe page is an obvious cross domain issue.

Looking at your example, I fear we might step onto the same issue here.
Could it be available as a postMessage from the parent page (like the resize event I think) ?

Regards,
A.

Hi! The snippet I pasted would be added to your page. It does rely postMessage to forward the info you need from the iframe. The updated script is currently deployed on preprod at https://preprod.pol.is/embedPreprod.js

Thanks a lot @mbjorkegren ! We were able to get the id thanks to your update.
Sorry for being so long at getting back to you.

yay! feel free to close if there are no follow-up action items :)

(i could totally imagine there being doc reccos spun out of this before closing fwiw)

Hey guys,
I'll be closing this one soon, do you have any idea when and if it is going to be pushed on the prod embed.js ?

Thanks !

Sorry for that wait on that, just deployed.

Nice ! Closing then. @mbjorkegren

Could you check pol-is/polis-issues#88 ? We are stuck :(

Thanks a lot :)

This is missing documentation, so I'll leave a little context here:

Seems that postMessage is sent here:
https://github.com/pol-is/polisServer/blob/5ac29b7245a7b198e40d1727ea246ed25acfecb7/client-participation/js/util/postMessageUtils.js#L46-L52

And the conversation object that's sent through postMessage is created here:
https://github.com/pol-is/polisServer/blob/5ac29b7245a7b198e40d1727ea246ed25acfecb7/server/server.js#L14059-L14079

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joshsmith2 picture joshsmith2  路  9Comments

paulthistle picture paulthistle  路  6Comments

crkrenn picture crkrenn  路  7Comments

metasoarous picture metasoarous  路  7Comments

patcon picture patcon  路  10Comments