Saturday, June 18, 2016

Simple chat messaging system with Delphi and Firebase

Hi all,
some time ago I posted about my open source project: Firebase4Delphi. Well, Firebase was acquired by Google and in Google I/O 2016 was showed very interesting news and new features (more info here ). My project provide a REST facade to consume FIREBASE RealTime Database API.
The Firebase Realtime Database is a cloud-hosted database. Data is stored as JSON and synchronized in realtime to every connected client. When you build cross-platform apps with our iOS, Android, and JavaScript SDKs, all of your clients share one Realtime Database instance and automatically receive updates with the newest data. - Firebase Realtime Database Documentation
In my project there is a sample application about a Chat messaging system. If you enjoy Firebase program (https://console.firebase.google.com/), you are able to create your first Firebase project! See the online documentation to undestand how Firebase works.
Once you create your application you can start to use the Chat Messaging sample, it's very easy if you follow these steps:
  1. Create a clone of Firebase4Delphi project (or download it)
  2. Open Firebase4DelphiChatDemo.dproj
  3. Deploy the app on your favorite Target Platoform (Windows, Mac, Android, iOS)
  4. Once application started, put in the settings tab (Fig 1) the URL provided by Firebase Realtime Database related to your project (Fig 2) , adding the demo name "chatdemo" as REST parameter
  5. Choose a username
  6. Click Start Chat button
Fig 1:

Fig 2:



















And that's all! You can start to use the simple chat messaging system!

Be careful to share your project and other info because it's just a demo and I not covered Firebase Realtime Database Security and Rules so all your security rules are defined as public and anyone can read or write to your database (default).

If you are interested about this project or you want to contribute do not hesitate to contact me by the github page!

PS.
In October I will take a session in ITDevCon conferenceBuild Realtime application with Delphi and Firebase

28 comments :

  1. HI ,

    Thanks for sharing , i am using XE7 and would like to ask whether is possible to use Indy to replace the System.Net.HttpClient so that can make this library to be compatible with XE7 ?

    ReplyDelete
    Replies
    1. Yes it is possible... but I chose this solution because the new HTTP client libraries work across Windows, OS X, iOS and Android, and include native support for SSL, GZIP encoding, etc...

      Delete
    2. Hi, Kalmen Chia! You are using Indy? It's work?

      Delete
  2. Hi,
    Congratulations on the article.
    I have a doubt:
    It is possible using the project Firebase send PUSH notification to the users?
    Just as we can use Kinvey?

    ReplyDelete
    Replies
    1. Hi,
      it is possible but not from a Delphi client, only from a client specified in the documentation. I have been in close contact with the support of Firebase, but unfortunately for now, is not possible a third party bridge for the new features ( those added since Google has acquired Firebase ) .

      Delete
  3. Hi,
    Congratulations on the article.
    I have a doubt:
    It is possible using the project Firebase send PUSH notification to the users?
    Just as we can use Kinvey?

    ReplyDelete
  4. Hi Daniele,

    Great job ! I leave you a message in GitHub but I have another question. Is it you framework compatible with Delphi XE6 ?

    Best Regards.

    Adalberto Brasaca
    Piracicaba - SP
    Brazil

    ReplyDelete
    Replies
    1. Hi,
      no it's not compatible because it use the new HTTP client libraries available from XE8

      Delete
  5. Hi Daniele. The sample program works. But one node above "Server URL" and "Username" always is added a string with many strange characters, for example "-KS9cRlaIl4m1YPdVNGB" or "-KS9chSGkluCugqxOHpG". Is that right ?

    Regards.

    ReplyDelete
    Replies
    1. Yes, it is correct. They are unique identifiers supplied automatically by system

      Delete
  6. hi, i cant run error:permisson denied. pls help
    thanks

    ReplyDelete
    Replies
    1. you must define this in rules tab under Database menu of Firebase
      {
      "rules": {
      ".read": "auth == null",
      ".write": "auth == null"
      }
      }
      please this is for demo purposes only as noted above. thanks

      Delete
  7. Hi, I couldn't get it to work. I got my firebase account, put in my firebaseurl in the server textbox, put in a username which I created under authentication but when I click start chat nothing happens, even after I type a message and click send. HELP

    ReplyDelete
    Replies
    1. Have you tried to debug some info? What about the server response?

      Delete
    2. Hi NigeriaLNG. My code works fine ! Try it. The rar file contains source code and executable. Good luck. Link to download: https://1drv.ms/u/s!AuSTIeosjoqokDAn77hRNoKxydT3

      Delete
    3. @Daniele sorry for my late response, but how or which debug info.
      @Adalberto I downloaded your app but did not work, just like my or app created by Daniele.
      Let me know, for URL is it https://.firebaseio.com or some other url

      Delete
    4. Hi NigeriaLNG... You have to create a "database" in Firebase's site and use the URL for the create "database" in application (first field - see Fig. 1 above). And also see above the reply from Daniele to Sam Mikael (access permisson rules). Regards.

      Delete
  8. Daniele,

    The framework can be used in Delphi mobile application ?

    Best regards.

    ReplyDelete
  9. Hai, can you teach me how to create remote push notification using firebase cloud messaging. please explain me how do it, or give me some example. please help me i need your help :'(

    ReplyDelete
    Replies
    1. Hi! remote push notification are not supported by Firebase4Delphi. You have to use the libraries specified in firebase documentation. The documentation is very simple and complete. Here the link https://firebase.google.com/features/notifications/

      Delete
    2. but, can you explain to me step by step. seriously i'm newbie, please help me

      Delete
    3. I think that the official documentation is better than me :) :)

      Delete
  10. Hi Daniele. I have one doubt. How can I change the values of the same fields (2), I mean, edit the fields contents. Best regards.

    ReplyDelete
    Replies
    1. Hi! PUT is the command for update. Here the documentation https://firebase.google.com/docs/database/rest/save-data

      Delete
  11. Hi Daniele, How can we retrieve just some data from database chat. I try with "EqualTo" in params but does not work: ... QueryParams.Add('equalTo', 'some_user_name');
    Regards

    ReplyDelete
  12. Hi, I am answering my self to help someone else. The solution was add ".indexOn":"name" in RULES.

    ReplyDelete
  13. Hello Daniele,
    I need a consultant on this project.
    I would like to include a list of users in a listview, and when clicking, open the chat, as well as having one photo per user.
    That is, in the user registry can add / change a photo.

    awaiting
    Follow my skype loester.rodrigo.da.silva

    ReplyDelete