Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the message sender UUID/metadata from pubnub history?

Tags:

pubnub

I want to know who sent the messages when retrieved from the pubnub.history!

pubnub.history() only returns timetoken and the message.

like image 447
Ash0ur Avatar asked Oct 16 '22 17:10

Ash0ur


1 Answers

PubNub Sender UUID: realtime vs history

The sender (publisher) UUID is provided in the message you receive in realtime as a subscriber, but PubNub only stores the actual message you published along with any meta data that provided:

PubNub JavaScript SDK publish docs sample code

pubnub.publish(
    {
        channel: 'my_channel',
        message: { 
            such: 'object'
        },
        meta: { 
            "cool": "meta"
        }
    }, 
    function (status, response) {
        if (status.error) {
            // handle error
            console.log(status)
        } else {
            console.log("message Published w/ timetoken", response.timetoken)
        }
    }
);

Best practice would be to add the publisher's UUID to the meta parameter which will not only allow you to get this value using history API, but you can also use it to filter out messages that the client has sent (don't receive your own messages using Stream Filter).

like image 181
Craig Conover Avatar answered Oct 21 '22 00:10

Craig Conover