How to create immediate Notification System in website - java

I am implementing a small social networking website, and I am trying to implement notifications.
Notifications have the following requirements
All users will receive notifications whenever users they follow do
certain events (like a post, create a post,leave a comment, etc...
When a set of notifications for a user is unread, just like on facebook, the user will
continue to see a read notification icon on their navbar.
Problem : I am taking an example to describe my problem for better understanding for everyone.
Suppose there are two users A and B. A & B are friends and A post something, suddenly B like the post of A then A should have to receive the notification immediately.
So how can i achieve this immediately receiving of notification process?
Should i send a call to server on each millisecond to check whether there is any unread notification is available for A user ? In this case thousand millions of call creating for multiple user. It is feasible solution ?
(I think it create unnecessary load on my website. As i think facebook and stackoverflow do not use this way).
Provide me a suitable solution just like fb and other webiste using.
Technology Using in my project: Java and MYSQL

You should use JavaScript (client side) along with Java - MySql (Server side), and more specifically Ajax. You will need some time to understand the concept and the usage but it does exactly what you want.
To give more details, what you need is to create a partial view where the notifications will appear, and update this partial view async (with AJAX).

Dont reinvent the wheel.
Use ajax call to server at each interval and check your server and update nav acc.

1.So how can i achieve this immediately receiving of notification process?
2) Should i send a call to server on each millisecond to check whether there is any unread notification is available for A user ?
Your above both questions answers solve through GWTEventService implementation.
Through it you can write code that will avoid client to server round trip.
GWTEventService is an event-based client-server communication framework. It uses GWT-RPC and the Comet / server-push technique. The client side offers a high-level API with opportunities to register listeners to the server like to a GUI component. Events can be added to a context/domain on the server side and the listeners on the client side get informed about the incoming events. The server side is completely independent of the client implementation and is highly configurable. Domains can be defined to decide which events are important for the different contexts.
Refer link: https://code.google.com/p/gwteventservice/

Related

Dynamically created content on Android - retrieve friends newest posts

I'm trying to create this:
It goes through your friends, finds the ones with new posts and retrieves them. What's the logic that would go behind something like this? What should I be trying to do?
I know two popular way to deliver news to receivers.
First way
Receiver asking for news from friends with a certain frequency. In this case server works as mediator for senders and receivers. Client application asking for news from paticular friend application. For this architecture typically used Mediator pattern:
Second way
Source of news sends this to server. Server works as observer and sends news directly to receivers with online state. Otherwise, server collects news for particular user (client application) in queue. For this behaviour typically used Observer pattern:
For more information about architecture templates see source PDF

Facebook Messenger - ChatBot - wit.ai integration

I have my application running on AWS on tomcat instance with Java code with mongodb database.
I now need to integrate this with Facebook messenger ChatBot and wit.ai.
I am really struggling to get started, some sample code i have found but in different languages.
Can i run this and integrate with my portal running on Tomcat. it should call both Facebook messenger and wit api.
I need to get high level idea as to how to proceed.
To connect wit.ai to your facebook page, you just need to create an accound with wit.ai, and then create a new application (or use the default starting one).
Then you can go to the settings of the app, and you will se the Server Access Token code.
You need to paste that server access code in the field "Integrated NLP", that you will find in your Facebook for Developers account, then access the application that you want to use NLP, in the setting for Messenger. For that you must have the messenger app already created and configured with it's webhook wich I guess you have.
Once that's done, the Natural Language Processing (NLP) will be sent to your server automatically as another field in the message. And it's preety simple to understand and train from wit.ai
The messages of the user will be analyzed by wit.ai, and if it finds any entity of the default ones or one defined by you training the bot from wit.ai, will send it to messenger, and this one will insert the NLP in the message.
So you will recive a normal JSON message from messenger, with an extra field called NLP that will contain something like the following example:
"text":"reservar una pista","nlp":{"entities":{"tipo_cita":[{"confidence":0.98398202482107,"value":"pista","_entity":"tipo_cita"}]},"detected_locales":[{"locale":"es_XX","confidence":0.9935}]}}}]
My chatbot is in spanish, but there's an example of how you can see the NLP in the JSON message.
I introduced the text: "reservar una pista"
And it recognized the value: "pista" with a confidence of 0.9839. Wit also detected the language "es_XX" that's spanish with a confidence of 0.9935.
First of all think about what your bot should do. What functionality will it provide, which questions will be asked by users and how you would like to respond to that.
If you have a general idea about your problem space you can start thinking about the technical challenges.
Be aware that both the Messenger Platform and wit.ai are completely independent products and they provide an HTTP interface to their service. That means you can use any language you like to interact with these platforms. Your application acts as the middleman to these services.
Start off establishing an integration with the Messenger Platform so you that you are able to both receive and send messages.
For that you have to create a Facebook page which acts as the identity of your product. Users will find you in Messenger by your pages' name. You also need to create a Facebook app where you subscribe to your page and specify the webhook settings so that messages are relayed to your own backend service.
The documentation for this is really good and I advise you read it carefully. You can find it here.
After going through the docs you will have a good understanding of what you can do with the Messenger Platform and which types of messages you can send and receive.
Once your able to send and receive messages you can start to extract some sense out of them. For this you can use wit.ai, but there are also other services you might consider. E.g Google just released their own NLP platform which provides similar features. See here
Also there is api.ai
In general you have to send received messages to the service of your liking and get back structured information about what the intent of the user is and what values where extracted. With that information you can act accordingly.
If you want to stick with wit.ai go through their Getting Started guide and recipes section. That enabled me to use their platform.
I hope this gives you a general idea about how an integration could work. This is fairly high-level and much of the details (especially on the NLP side) depend on your specific use cases.
You can use a sample nodejs implementation of witai and facebook messenger from their official repo. First of all, you have to train the model of witai to understand expressions and extract entities. Then set up the messenger bot on fb and attach it to some fb page. Once you are able to get the messages from the webhook callback send them to the witai API. You will also have to define actions in your code for the witai to execute actions defined in the model.

how to send post data continuosly to web and mobile

I am going to develop uber-like application.Here I have to send latitude and longitude to web and mobile devices continuously with my service,What I have do to get this.
Can anyone please give some idea.
You should start by designing how the application is to be used, seen from all the different users perspectives.
For instance is this a web app, or a native app, or both?
Then from that knowledge, you need to define a communication protocol.
You should be able to determine if the client will be polling for data, or if you need to push it from the server onto the clients.
This also goes for the data that travels the other way.
From here you choose a language for programming, and then start doing some proof of concept tests.
The choice will depend on the chosen underlying technologies
(web / native / os / available libraries)
After some test work you may have something that works, then you need to review or add security to the communication, cause we do not want everyone collecting location data from everyone that has the app installed.
Then run beta trials and eliminate the worst bugs, and then release the app.
You'll want some sort of asynchronous task which can get new data from your server and refresh the mobile and web content to reflect the content of the server. You'll also want to notify the server whenever you make local changes to content and want to reflect those changes. Android provides the SyncAdapter pattern as a way to easily solve this pattern. You'll need to register user accounts, and then Android will perform lots of magic for you, and allow you to automatically sync. Here's a good tutorial: http://www.c99.org/2010/01/23/writing-an-android-sync-provider-part-1/

Send and forget library for Android

When I program apps, usually I need to do something that can fail (the most typical is send something to a server), many times the "send and forget" would be the best option (or a send and forget with a expiration date).
I know it is a very generic problem but is there some library that facilitates the save and retry process?
As #CodeChimp says, you'll probably need to roll your own.
That said, the usual pattern for Android is to write a Service that handles saving/retry.
Your app would pass the data to the service (send and forget), and the service would then take care of trying to send in the background.
The big question for this sort of thing is always how to handle failure. What happens after the save fails some number of times? You're on your own here too. Depending on your situation, you could notify the user (via a Notification), save the error in the app's database, and notify the user in the app's UI, etc...

Connect two calls via web application

I need to add a functionality to my java-based web application that will allow users to click on a link and the application will automatically call the user and another party and connect them in a phone call.
Does anybody know what would this entail?
Thanks
It can be done with Twilio, and their new, easy Conferencing API. Trust me, it's really really simple. Another option might be CloudVox, but I haven't (formally) tried their service yet.
The World-Wide Web Consortium has an integrated set of speech interaction standards that you'll find interesting. There's a markup language called VoiceXML that is analogous to HTML in that web applications generate it. It differs from HTML in that it's specialized for temporally-based speech interactions instead of visual interactions. So instead of looking at a screen you listen to audio prompts and computer-generated speech. Instead of typing and mousing, you speak back and what you say is processed by a speech recognizer or recorded.
There are many companies using VoiceXML to automate voice response systems, and they handle billions of calls per year. You've probably talked to them many times without realizing it. One of the best companies in this space is Voxeo, and they have a developer site at http://evolution.voxeo.com/ that you can play with. Evolution lets you call your web application over an ordinary phone (or Skype). You actually talk to a VoiceXML-based web browser which will fetch a VoiceXML page from your Java application server, "play" it to you, listen to what you say, and then report that back to your app via a form submission, get the next page to render to you, etc.
Another related standard is CCXML, or Call Control XML. You use this to create teleconferences that may or may not include a voice response application.
So it sounds like in your case you want your standard web application to talk to a CCXML server and ask it establish call legs to the web user and to a customer service line. I know that Voxeo Evolution offers CCXML as well.
There are other good companies in this space too. One that comes to mind is TellMe, which was bought by Microsoft a year or two ago. These two companies (and others) offer professional services too.
So I wanted to write this up as an answer to the comment above. The Skype API provides a number of options for telephony in COM, Java and Python:
Skype4Java - https://developer.skype.com/wiki/Java_API
Skype4Py - https://developer.skype.com/wiki/Skype4Py
Skype4COM - https://developer.skype.com/Docs/Skype4COM
They provide a communication and command protocol layer for working with Skype, more info on the API here:
https://developer.skype.com/Docs/ApiDoc/Overview_of_the_Skype_API
It's kind of different for every platform, the Linux version is based on DBus or X11.
Try FreeSWITCH. I have done this before. Its pretty straight forward. Can be a bit hairy when you need to log call accounting and all those stuff. I hopefully would be able to provide you some guidelines and code samples, let me get home first. Cheers.
The good thing in using FreeSWITCH, you will be able to handle multiple calls, and quite a number of. You might need that in future.
Note: You have to use some kind of VoIP provider in order to do that. I was using Gizmo5 that time and it was pretty good.
Sorry buddy, lost the servlet code somewhere. But no worries it was a simple servlet. Fortunately, I had added my example Java code for XML-RPC, into the FreeSWITCH wiki, and actually that was the code my servlet was invoking down the road. Below is the snippet.
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
XmlRpcClient client = new XmlRpcClient();
try {
config.setServerURL(new URL("http://localhost:8080/RPC2"));
config.setBasicUserName("freeswitch");
config.setBasicPassword("works");
client.setConfig(config);
// For external phone calls using VoIP. We will use something like below.
// new Object[]{"originate", "sofia/gateway/gizmo1/6098989898 &bridge(sofia/gateway/gizmo9/0116054545454)"}
// gizmo1, and gizmo9 are the accounts configured under freeswitch gateway configuration.
client.execute("freeswitch.api", new Object[]{"originate", "sofia/internal/1001 &park()"});
} catch (Exception ex) {
ex.printStackTrace();
}
Moreover, you need to configure few things prior doing this. You need to set up the gateway using your VoIP provider settings.
For FreeSWITCH related help, take a look at this SO Thread.
I know of 2 API providers that does what you need:
1) twilio - can connect to 2 or more parties using TwiML (their markup). example
2) Hoiio - very easy to use with 1 line of RESTful api call. example

Categories

Resources