LuaLua Storage & Playback API Reference for Realtime Apps

Go to Presence


Requires Storage & Playback add-on XRequires that the Storage & Playback add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
This function fetches historical messages of a channel.
PubNub Storage/Playback Service provides real-time access to an unlimited history for all messages published to PubNub. Stored messages are replicated across multiple availability zones in several geographical data center locations. Stored messages can be encrypted with AES-256 message encryption ensuring that they are not readable while stored on PubNub's network.
It is possible to control how messages are returned and in what order, for example you can:
  • Search for messages starting on the newest end of the timeline (default behavior - reverse = false)
  • Search for messages from the oldest end of the timeline by setting reverse to true.
  • Page through results by providing a start OR end time token.
  • Retrieve a slice of the time line by providing both a start AND end time token.
  • Limit the number of messages to a specific quantity using the count parameter.
 
Start & End parameter usage clarity:
If only the start parameter is specified (without end), you will receive messages that are older than and up to that start timetoken value.
If only the end parameter is specified (without start) you will receive messages that match that end timetoken value and newer.
Specifying values for both start and end parameters will return messages between those timetoken values (inclusive on the end value).
Keep in mind that you will still receive a maximum of 100 messages even if there are more messages that meet the timetoken values. Iterative calls to history adjusting the start timetoken is necessary to page through the full set of results if more than 100 messages meet the timetoken values.
To run History you can use the following method(s) in the Lua SDK
  1. ParameterTypeRequiredDescription
    paramstableYesTable of history parameters. See History Parameters for more details.
    PropertiesTypeRequiredDefaultsDescription
    ChannelstringYesnoneThe channel to get history for.
    callbackfunction(r)YesnoneThe function to call with received history.
    errorfunction(r)Optionalfunction(r) endThe function to call on failure, with result.
    startinteger or stringOptionalnoneThe timetoken to start history from.
    stopinteger or stringOptionalnoneThe timetoken to stop history at.
    reversebooleanOptionalfalseWhether to get the history in reverse (from chronological) order.
    countintegerOptional10Maximum number of messages to get in history (cannot be more than 100).
Retrieve the last 100 messages on a channel:
pubnub_obj:history({
	channel = "demo",
	count = 50,
	callback = function(response)
		textout(response)
	end,
	error = function (response)
		textout(response)
	end
})

Go to MISCELLANEOUS