1

What I want to do

I want to subscribe to push notifications notifying me when I make changes to items in Podio.

What I have done to achieve this

I am using the Podio JS library and have read the documentation and gone through the detailed example. I have in accordance with the instructions:

  • successfully authenticated with the PODIO api; and
  • successfully made a podio.request call (receiving responseBody with push property)

The next step in my code is as follows:

var subscribe = getItem.then (function (responseBody){ 
    return podio.push(responseBody.push).subscribe(callback);
});

var notification = subscribe.then (function () { // never gets here!
    console.log ('subscribed');
});

What is not working

The code never gets to the notification part and consequently does not execute console.log ('subscribed'). The callback I pass to podio.push(responseBody.push).subscribe(callback) never gets invoked even though I make changes to the relevant item in my Podio account.

When I run console.log(subscribe) at an interval of 1000 ms the output is and stays:

lib$es6$promise$promise$$Promise {
  _id: 2,
  _state: undefined,
  _result: undefined,
  _subscribers: 
   [ lib$es6$promise$promise$$Promise {
       _id: 3,
       _state: undefined,
       _result: undefined,
       _subscribers: [] },
     [Function],
     undefined ],
  _onerror: null }

What my question is

I would very much appreciate help identifying why the push service is not working even though I - as I see it - as done exactly as instructed by the documentation.

Thank you in advance!

rabbitco
  • 2,790
  • 3
  • 16
  • 38
  • As experiment, can you try and test if it will work if changes are done by another person. I'm referring to this part `even though I make changes to the relevant item in my Podio account.`. Can you ask somebody else to make those changes (or do them from different account)? – Pavlo - Podio Oct 21 '16 at 01:09
  • @Pavlo: I have now tried that and it does not change anything. The outcome is the same. I am wondering whether I should somehow myself connect [Faye](https://faye.jcoglan.com) to server. But the instructions concerning Podio JS does not mention anything in that regard .... ? – rabbitco Oct 21 '16 at 12:02

1 Answers1

0

The subscription to push services was actually broken in podio-js and it has been fixed in version 1.6.0. (See this PR if interested in the code changes)

Please upgrade to the latest version of podio-js and you should be good to go.

A small example (using ES6 notation)

// assuming you already have an authenticated SDK in the variable podio

const onNotificationReceived = (message) => {
  console.log(message);
};

const subscribeToPushNotifications = (itemId) => {

  podio.request('GET', `/item/${itemId}`).then((data) => {
    podio.push(data.push).subscribe(this.onNotificationReceived)
      .then(() => console.log(`All is well, we've been subscribed!`));
  }).catch(err => { 
    throw new Error(err) 
  });

};

// Whatever item you want to receive notifications about
const itemId = 99999999;

subscribeToPushNotifications(itemId);
domokun
  • 3,013
  • 3
  • 29
  • 55
  • Is it possible to subscribe to an APP so you get notifications from every item on the APP instead of subscribing to each item? – SCabralO Jun 06 '17 at 18:46
  • 1
    You can't subscribe to an app, but you can subscribe to [/user/status](https://developers.podio.com/doc/users/get-user-status-22480) that, once you're following the app, will give you all the notifications about items created/updated. You will then have to filter out the one not related to the app you're interested in (e.g. other apps, notifications, chat messages, ...) – domokun Jun 07 '17 at 20:59