Backendless Support

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,


Leave a Comment

Comments (2)


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:

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


Perfect, done! Thank you very much!