Save messages


I am quite new of backendless so I am probably missing something big here. However, in my android application I set a chat activity like the one given by the Code Generator, how can I now make the server save the messages, do I need to create a table in the data for them or can I just use the channels (there messages seems to be deleted after 30 sec)?

Thank you very much,


Hi Gabriele,

The messages are not saved by default. You can change that behavior by injecting your own server-side logic. It can be done in a “beforePublish” event handler. For example, the following event handler would save every single published message in the “Messages” table:

/* global Backendless */
* @param {Object} req The request object contains information about the request
* @param {Object} req.context The execution context contains an information about application, current user and event
* @param {Object} req.message 
* @param {Object} req.publishOptions 
* @param {Object} req.deliveryOptions 
* @returns {Object|Promise.<Object>|void} By returning a value you can stop further event propagation and return
*          a specific result to the caller
Backendless.ServerCode.Messaging.beforePublish('*', function(req) {
  Backendless.Data.of( "Messages" ).save( req.message );

Perfect, done! Thank you very much!