1

I am prototyping a mobile app and i want to make it quickly. For that purpose, i am using pubnub chat engine.

However, i plan to migrate to a postgresql database after the end of the beta test. But i don't want to lose the existing data already stored in pubnub. Are there some possibilities to export my chat data to my own postgreSQL database ?

John doe
  • 3,680
  • 7
  • 31
  • 65

1 Answers1

1

Export PubNub Chat Messages to your PostgeSQL Database

While many approaches exist. One is best. Using PubNub Functions. You will asynchronously save messages reliably to your Database. Using an OnAfter Publish Event. Your database needs to be accessible via a secured HTTPS endpoint.

Stackoverflow Answer: PubNub: What is the right way to log all published message to my db - You will want to Save your JSON Messages to a Private Database using the method described in the links. Example code referenced below in this post.

export default request => { 
    const xhr  = require('xhr');
    const post = { method : "POST", body : request.message };
    const url  = "https://my.company.com/save";

    // save message asynchronously
    xhr.fetch( url, post ).then( serverResponse => {
        // DB Save Success! 
    }).catch( err => {
        // DB Save Failed! handle err
    });
    return request.ok();
}
Stephen Blum
  • 6,498
  • 2
  • 34
  • 46
  • what if this was not set up and now, you want to export all existing messages to postgres for instance, is their an effective approach for this other than https://www.pubnub.com/docs/chat/sdks/messages/message-history which I recently came across – Abdullah Oladipo Oct 14 '22 at 09:34