I have a Java project and I would like to get notified of certain runtime events by receiving a message in my personal Whatsapp account. I was wondering if this is even possible and if so, how can I accomplish this? Is there an API or Java library that I should be aware of?
Thank you for your help.
WhatsApp Inc. doesn't allow sending messages programmatically for personal accounts. But WhatsApp has started taking requests for business accounts in which they might allow certain programming features like integrating with your own code for sending messages etc.
I had once written a program using selenium to send message via WhatsApp Web. It worked perfectly fine. This was for experimental purpose only.
There are few 3rd-party libraries available but you run the risk of getting your number blocked. WhatsApp tries to detect if you are running such libraries. And if they catch then they will immediately block the mobile number.
Selenium method doesn't have such risk. Because you will be using WhatsApp Web only (via selenium).
For your application, the method suggested by #C-Sway is good enough.
You might want to look at Telegram as an application for this.
https://telegram.org/
AFAIK whatsapp will be tied to a mobile/cell number, which will hinder you from the outset, whilst creating your own private telegram channel to monitor automation on your site is very simple, they encourage bot use for this kind of thing and you'll find guides on how to create them below:
https://core.telegram.org/bots/samples
Additionally Telegram can be installed on any phone and the notifications are very reliable and customisable. Enjoy.
Related
I want to make a TeamSpeak 3 Musicbot in Java. But I don't find any Protocol from Teamspeak for the Voice transmission. And after searching for a Client API, for Java, I didn't find anything. Only for a ServerQuery but that doesn't help me I think.
I only want the Client to connect to the Server and then plays a Song, though that wouldn't be that hard!
Maybe you Guys can help me?
Teamspeak does not have an official client-api. You can only use the Query-API and create plugins. As the Query-API does not support any voice-communication, that's not the way you should go. The (most) official way of creating a Teamspeak3 MusicBot would be to run a client on your server which has a plugin installed which allows you to play music (more or less a soundboard). Sinusbot is exactly built this way.
Another "unofficial" option would be to make use of unofficial reverses of the teamspeak-protocol and built you own client from these. If you want more information about this, this repository might help you (and look for other projects the creator pushed, they might help you too).
I'm not quite sure if this helps, but have been developing a TeamSpeak 3 music bot using Kotlin, which is compatible with Java as it runs on the JVM (Java Virtual Machine)
The way it works is that it first launches the TeamSpeak client and connects to the desired server and channel, then it starts monitoring the chat log -> the bot can be controlled by entering commands into the chat.
The bot uses the TeamSpeak ClientQuery via Netcat to send messages to the chat.
It is completely client-side so you don't need to be server admin to get it working.
The bot currently supports Spotify, YouTube, and SoundCloud.
You can check it out at https://gitlab.com/Bettehem/ts3-musicbot
I am doing a lot of long lasting computation stuff in java and want to stay informed.
Is there any standard method ( library etc. ) to send push notifications from a desktop java program to my Android device?
When there is no , could someone provide me with some starting ideas how to write this on my own?
The "3rd-party application server" mentioned in https://developer.android.com/google/gcm/server.html can also be a desktop pc running a simple java program.
You will need to setup some IDs, an app that receives push messages, a way to display the phone registration ID so you can enter it in the desktop app.
But the rest is basically as simple as adding the gcm server jar to a desktop app (I'd use this version here: https://github.com/kurthuwig/gcm/commit/d37f4d1c37ed8deaf1a161ca7b881c1d843f80df ) and then calling 3 methods or so.
Like what zapl suggested I would say GCM is a good choice. Also, all benefits aside, if you're into messaging you can have a go at AMQP, specially the RabbitMQ implementation. You can run the RabbitMQ server on your desktop and push your messages out to all listening devices.
I currently have an small application that I have been using to learn java/android programming. Right now I have a setup were the app on one phone sends a request (via sms) to another phone running the same app. The remote phone receives the request and sends back some info. Next I would like to try this from the web. Is there an established "best" way to to this?
I was thinking I would have a web server send requests to the device via google cloud messaging and then have the device return the data directly to the web server. (Not that I really know how to do any of that just yet).
I see that there is a google cloud messaging return path (send messages from the device to the google cloud server, but it seems very new, do I need something like that? The main thing I want is to be able to ask the phone to do something when I want, not have it poll to see if there is a request, or just periodically update some status.
UPDATE:
Thanks to the answers below for confirming to me that I was on the right track.
I now have some basic functionality.
I started out using this gcm android demo code
https://code.google.com/p/gcm/source/browse/#git%2Fgcm-client%2Fsrc%2Fcom%2Fgoogle%2Fandroid%2Fgcm%2Fdemo%2Fapp%253Fstate%253Dclosed
and this ruby gem
https://github.com/spacialdb/gcm/blob/master/README.md
between the above two I was able to send a message to my phone pretty easily.
To get the round trip working, I setup a very simple rails app on heroku.
I included a modified version of the sample code in the gcm gem in a controller and then used
HttpPatch (needed for rails 4) to send a post/patch from my phone to my web app, the controller then echoes the message back to my phone.
I guess it would be nice to get the two way gcm stuff to work, but I am not sure there are any gems that handle that, and I am not qualified to handle a task like that :)
I would say it's the right call: Google Cloud Messaging for Android
From the site Android Developer:
This could be a lightweight message telling your app there is new data
to be fetched from the server (for instance, a movie uploaded by a
friend), or it could be a message containing up to 4kb of payload data
(so apps like instant messaging can consume the message directly).
In this case you don't want to fetch data from the server but you want to send them.
You can send them in different ways. I would suggest, since you are learning, to try a RESTful solution using one of the implementation of JAX-RS.
As a short and direct answer for beginner : GCM (Google Cloud Messaging) would solve your issue. However, if your app turned out to be something bigger, other more technical and complicated solutions are present too.
see this link.
If I am developing an Android application, what is the most feasible way to get near real-time notifications about an incoming email? Is there a push-like mechanism, or can I hold my IMAP connection for a long time, or do I use IDLE command?
Consider that user is authorized to use GMail services via OAuth and I don't want to poll IMAP server madly.
Update:
I'm not using the phone's configured-in Google account. There is another account set up using OAuth.
I'm using Apache Commons Net to connect to IMAP/SMTP in my app. It's a bare-bone library for IMAP, but I can perhaps modify it to add IMAP commands/extensions.
You can register a ContentObserver with GMail, anytime something changes in GMail, the observer will be called.
contentResolver.registerContentObserver(Uri.parse("content://gmail-ls"), true, myContentObserver );
Override onChange in your ContentObserver to do stuff when something in GMail changes.
Since IMAP does natively provide any sort of push notifications and the Google extensions don't either, you have to implement it yourself.
One way is to use IDLE requests, which is still a cheap way to do polling. Of course, you can't expect your app to be running all the time, so you need to use a background service. An 'always-on' service is however an anti-pattern on Android and will drain the battery quickly and likely get you many 1-stars. Additionally the system may decide to kill it at any time. The other alternative is to use AlarmManager to start the service periodically, but starting it every couple of seconds or so is just as bad. So you are basically back to square one: polling.
The other way is to get push notifications using GCM or a similar service. This does require you to have a server, and the server needs to have the authentication info for the user (which might be a problem), but there are no real constraints concerning keeping open connections and sending IDLEs each second, etc. On the Android side, if you want to implement push yourself, you need to keep an open socket to get notifications. This is not very easy to do if you are not a system app (see above), so that leaves GCM. The connection it uses is manged by the system (Google Services framework), it can do things a regular app cannot, and you basically get it for free, since it's already there. It receives small pieces of data when there is something to do, called 'tickles'. Those in turn trigger broadcasts, Google Play updates, etc.
So, take your pick. Or just give up, register the account and use GMail and its labels Android API.
I'd check out Google Cloud Messaging (GCM):
http://developer.android.com/training/cloudsync/gcm.html
My understanding is that this works without requiring the user's Google account, and lets you handle authentication.
See a tutorial here:
http://www.techrepublic.com/blog/app-builder/implementing-googles-cloud-to-device-messaging/428
You would need additional server-side code running to do this though.
A friend and I are currently working on a turn-based game with chat with both desktop browser and Android clients, with Google App Engine as the server.
We're using the Java API for GAE and using HTTP for communication with the server. We've implemented simple chat functionality, and we're getting undesirable latencies 1-3 seconds from both the browser and Android clients while just posting simple one-word chat messages.
My friend thought it would be best to use XMPP instead of HTTP, but we want to use a Google Accounts cookie for authentication from the Android client, and according to the GAE documentation, XMPP clients cannot use a Google Accounts cookie and must use the user's password.
Does anyone have any suggestions as to where the latency might be coming from, how to troubleshoot it, and/or what to do about it?
Also, is anyone aware of any opensource implementations of chat (or something similar) on GAE done in Java? Can't seem to find any.
One way to analyze the situation would be to use Wireshark to look at the network traffic during the delays.
You don't say how your chat messages are getting from one JVM to the other. If you're using the datastore, maybe try memcache?
Also, startup time is often an issue; app engine starts and stops JVMs all the time, particularly for a low-traffic app. A way to diagnose this is to reload the page a bunch of times (send more messages) and see if it gets faster after a while. It should be pretty easy to tell the difference in the admin console logs.