limit users in group chat of whatsapp by an android app - java

i m trying to developing an app where i want to monitor whatsapp group chat and limit users e.g max 5 users can join if 6th coming, ignore or remove most inactive and add new user to chat
i have no idea how can i do that ? it requires root acess or not?
is there any api available to do this ?

You can use Yowsup which is a Python library. You will need to setup a separate WhatsApp account that logs into the WhatsApp servers using this library. This account will need to be the "owner" of the groups and will need to manage adding and removing users from the chat. The code will also need to monitor the chat traffic to figure out who is talking. The code you develop does not need to run all the time.
You will need to register listeners for a number of WhatsApp events. Some of your init code will look like this:
class WhatsappClient:
def __init__(self):
atexit.register(self.exitfunction)
connectionManager = YowsupConnectionManager()
connectionManager.setAutoPong(True)
self.signalsInterface = connectionManager.getSignalsInterface()
self.methodsInterface = connectionManager.getMethodsInterface()
self.signalsInterface.registerListener("auth_success", self.onAuthSuccess)
self.signalsInterface.registerListener("auth_fail", self.onAuthFailed)
self.signalsInterface.registerListener("message_received", self.onMessageReceived)
self.signalsInterface.registerListener("receipt_messageSent", self.onMessageSent)
self.signalsInterface.registerListener("disconnected", self.onDisconnected)
self.signalsInterface.registerListener("group_messageReceived", self.onGroup_messageReceived)
self.signalsInterface.registerListener("notification_groupParticipantAdded", self.onNotification_groupParticipantAdded)
self.signalsInterface.registerListener("notification_groupParticipantRemoved", self.onNotification_groupParticipantRemoved)
self.signalsInterface.registerListener("group_gotInfo", self.onGroup_gotInfo)
self.signalsInterface.registerListener("group_gotParticipants", self.onGroup_gotParticipants)
self.signalsInterface.registerListener("group_subjectReceived", self.onGroup_subjectReceived)
self.signalsInterface.registerListener("notification_groupPictureUpdated", self.onNotification_groupPictureUpdated)
self.signalsInterface.registerListener("group_setSubjectSuccess", self.onGroup_setSubjectSuccess)
self.signalsInterface.registerListener("group_createSuccess", self.onGroup_createSuccess)
self.signalsInterface.registerListener("group_createFail", self.onGroup_createFail)
self.signalsInterface.registerListener("group_endSuccess", self.onGroup_endSuccess)
self.signalsInterface.registerListener("group_addParticipantsSuccess", self.onGroup_addParticipantsSuccess)
self.signalsInterface.registerListener("group_removeParticipantsSuccess", self.onGroup_removeParticipantsSuccess)
some examples of method implementations above:
def onGroup_messageReceived(self, messageId, gjid, author, content, timestamp, receiptRequested, pushName):
formattedDate = datetime.datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
log("Group message %s - %s (%s):%s"%(gjid, pushName, author, content))
if receiptRequested:
self.methodsInterface.call("message_ack", (gjid, messageId))
# do something with the message....
def onGroup_addParticipantsSuccess(self, gjid, jid):
log ("Participant added success g=%s j=%s " % (gjid, jid))
def onGroup_removeParticipantsSuccess(self, gjid, jid):
log ("Participant removed success g=%s j=%s " % (gjid, jid))

Related

Online Multipler Games in Java

In Java, is there a way to make a client/server system for a game without having to enter ips (like in Minecraft).
But instead, have it automatically connect the user to a game when he requests to join one (like in Fortnite, or surviv.io).
The only method I current know for client/server is having to give each user a server ip to connect to (like in Minecraft), so I was wondering if I could do it this way.
Thanks in advance.
IMHO, I think in all ".io" games, they are only hiding the registration processing. In my case, the previous game I made had a feature calls "Quick Play".
When a player uses that playing method and first time joins the game, I get his device's ID (for example in Android) then use it as a unique ID for that player in-game (I'm not sure about iOS but you can get that unique value in Android).
You can see the example below:
_on(TEvent.CONNECTION_SUCCESS, args -> {
var connection = Connection.convert(args[0]);
var message = TObject.convert(args[1]);
info("CONNECTION", connection.getAddress());
// Allow the connection login into server (become a player)
String username = message.getString("u");
// Should confirm that credentials by data from database or other services, here
// is only for testing
_playerApi.login(new PlayerLogin(username), connection);
return null;
});
Now when a new user login, he will send his device's ID and I can treat him a new player and make that ID as his name (or making a randomized name for him)
You can see more detail in the link below:
Login Example

Android Firebase session calculation for app which is in background

I'm trying to figure out how can I apply this guide to my code and this SO answer, precisely:
A session begins to time out when an app is moved to the background,
but you have the option to extend that session by logging the
extend_session parameter (with a value of 1) on events logged while
the app is in the background.
This is my code (which I want to use on events, when my service is running and activities are on pause / stop):
Bundle params = new Bundle();
params.putInt("extend_session", 1);
firebaseAnalytics.logEvent("app_in_background", params);
The event is custom, because default one doesn't suite my need.
Long story short, I want to see how much time (average) the service is running and possibly having this data listed in Where are your users engaged? table (Firebase console).
What I want to achieve is: how much my users are engaged while using my app service ?
Am I using the correct approach ?

Gmail watch user inbox, history.getMessagesAdded is not returning the new message

Requirement is to sync mails from Gmail for an user into our CRM. The system in place is based on Google Pub/Sub which watches inbox of the user for any change and fires the notification to our HTTPs endpoint. More on this at Gmail cloud pub/sub.
Based on the above procedure we git history of changes. And then i am interested in only new messages, so history.getMessagesAdded is preferred as per this guide. Issue we are facing now is the first mail of a thread is not captured under messagesAdded all the subsequent messages are passing through our system.
Note: For the first mail, we do get push from Google. But when we try to get Messages added it turns out empty. Is there anything special needs to be done for the first mail of the thread or am i missing out something.
I was experiencing a very similar problem, and my mistake was that I was using the historyId from the push notification, the solution was to store the last known historyId on my database, so, every time I get a notification, I get the history from the id I have stored, not the one from the notification.
In my case, the historyId from the notification doesn't even make part of the history, maybe because of my watch restrictions: labelIds=['INBOX']
This is the google pub/sub notification:
{
message:
{
data: {"emailAddress": "user#example.com", "historyId": "9876543210"},
message_id: "1234567890",
}
subscription: "projects/myproject/subscriptions/mysubscription"
}
I was using the message.data.historyId, wich was causing the confusion!
The message.data, comes as a base64 encoded string, in this example I just decoded it!
Step by step for watching new e-mails on the inbox:
Do all the configuration in the google pub/sub.
Start watching the user with the filters you want (docs.: https://developers.google.com/gmail/api/v1/reference/users/watch)
Store the historyId obtained in the step 2
When receive the notification, get all the events (history) using the stored id as the startHistoryId parameter (docs: https://developers.google.com/gmail/api/v1/reference/users/history/list)
In the history list obtained on the step 4, look for the new messages: history.getMessagesAdded().
Update the last known history id in your database, so you don't need to deal with the whole history every time!
I hope it helps.

Twilio TaskRouter Worker Conference

I have a Twilio phone number which I am using for softphone and that phone I have configured for TaskRouter. So whenever Somebody call to twilio number that call route to available Worker, this is working fine but my question is how Worker can call other non twilio number in live call.
I am reading a docs on https://www.twilio.com/docs/api/taskrouter/handling-assignment-callbacks#redirecting-call where it mentions that
1. Dial the worker in a Conference name by the ReservationSid. This can be done on assignment call back.
2. Utilize Redirect Assignment Instruction to transfer the customer from a Queue to a Conference named by the ReservationSid.
So how can I dial a Worker in conference and how customer redirect to that conference so Agent can dial a non twilio number in live call and redirect that call in conference
means it is like three way communication,
Customer-->Twilio Number--->Worker--->Non Twilio number??
in PHP I have manage like this
first set one URL assignment in taskrouter
HERE : TaskRouter->Settings->Event Callbacks
like www.site.com/test/event_status_callback.php
You can use twilio conferece task router :-
https://www.twilio.com/docs/api/taskrouter/reservations
Conference Instruction like this
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;
// Your Account Sid and Auth Token from twilio.com/user/account
$accountSid = "AC1afdf65d5c4e434dc58792456bda940f";
$authToken = "your_auth_token";
$workspaceSid = "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$taskSid = "WTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$reservationSid = "WRXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$client = new Client($accountSid, $authToken);
// Update a Reservation with a Conference instruction
$reservation = $client->taskrouter
->workspaces($workspaceSid)
->tasks($taskSid)
->reservations($reservationSid)
->fetch();
$reservation->update(
array(
'instruction' => 'conference',
'dequeueFrom' => '+18001231234'
)
);
1) call come on twilio number and goes to taskrouter
<Response>
<Enqueue workflowSid="WWXXXXXXXXXXXXXXXXXXXXXXXX">
<Task>{"selected_language": "<?= $language ?>"}</Task>
</Enqueue>
</Response>
2)now call goes to perticuler language wise and dail to avelable workers and here you can redirect your call to other Non Twilio number get call sid
also you can Use Db for manage worker side and call sid
In this event_status_callback.php page you get call_sid
$call = $client
->calls($call_sidss)
->update(
array(
"url" => $url . "test/callredirectonsupport.php",
"method" => "POST"
)
);
echo $call->to;
3) callredirectonsupport.php
now you call redirect to callredirectonsupport.php
here you can write youe dial code

Determining which Gmail Tab an email is placed under, using the Javamail API

I am working on application that can determine which Gmail Tab an email is placed under (ie Social, Promotions, etc). Is there any way of determining which Gmail Tab an email is placed into with the Javamail API? Or are there some other applications that can determine this?
Thanks in advance.
It is not possible to determine the category/tab with the Javamail API because Google do not integrate the information with the IMAP protocol. The category/tab is only available via Google's proprietary GMail APIs.
In the GMail settings under labels, I was able to get categories to show up as folders in the GMail web client by clicking on 'show' next to categories, however they did not come down in the IMAP request. It must be by design because there is no "Show in IMAP" option provided for the categories.
In the existing answer it is mentioned that the GMail IMAP extensions can be used to access X-GM-THRID and X-GM-LABELS
These extensions are explained in Google's GMail IMAP docs:
https://developers.google.com/gmail/imap/imap-extensions
X-GM-LABELS -> "Gmail treats labels as folders for the purposes of IMAP."
a010 FETCH 1:4 (X-GM-LABELS)
1 FETCH (X-GM-LABELS (\Inbox \Sent Important "Muy Importante"))
2 FETCH (X-GM-LABELS (foo))
3 FETCH (X-GM-LABELS ())
4 FETCH (X-GM-LABELS (\Drafts))
a010 OK FETCH (Success)
X-GM-THRID -> "Gmail provides a thread ID to associate groups of messages in the same manner as in the Gmail web interface."
a008 FETCH 1:4 (X-GM-THRID)
1 FETCH (X-GM-THRID 1278455344230334865)
2 FETCH (X-GM-THRID 1266894439832287888)
3 FETCH (X-GM-THRID 1266894439832287888)
4 FETCH (X-GM-THRID 1266894439832287888)
a008 OK FETCH (Success)
But neither of these extensions specifies the category to which an email belongs.
There are however two alternative solutions that will allow Javamail to work with categories indirectly:
Use a filter that associates labels with each category -> Causes an IMAP folder to be created for each category
Create a filter and associate it with "Skip inbox" to exclude certain emails from coming down in the IMAP request if that is your goal
Procedure for changing categories into labels/IMAP-folders:
Go to GMail Settings
Click on "See All Settings"
Click on "Filters and Blocked Addresses"
Click on "Create new Filter"
On the line "Includes the words" enter "category:primary"
Click "Create the Filter"
Tick "Apply the Label"
Choose "New label..."
Enter the label name
[This will be the IMAP folder name]
Screenshots for the procedure:
The procedure for skipping the inbox
Same procedure as above
In step 7, choose "Skip in the inbox" instead of "Apply the Label"
The list of possible categories to filter on:
category:primary
category:social
category:promotions
category:forums
category:updates
The standard IMAP/SMTP capabilities of JavaMail API & Gmail API together were quite enough, even to deal with the labels. But to fetch custom Gmail attributes X-GM-THRID and X-GM-LABELS also, have a look at Gmail Imap Extensions.
In order to fetch a list of messages from Gmail you must be implementing standard javamail profile fetch:
folder.fetch(msgs, stdFetchProfile);
Now to fetch the list of tags/tabs/labels from Gmail, make a call to custom method using IMAPFolder’s doCommand()
final MessageSet[] mSets = MessageSet.createMessageSets(mns);
((IMAPFolder) folder).doCommand(new IMAPFolder.ProtocolCommand() {
#Override
public Object doCommand(IMAPProtocol p) throws ProtocolException {
try {
Response[] r = p.fetch(mSets, "X-GM-LABELS X-GM-THRID");
for (int i = 0; i < r.length; i++) {
if (!FetchResponse.class.isInstance(r[i]))
continue;
// Got a FetchResponse.
GmailFetchResponse gfr = new GmailFetchResponse(
((FetchResponse) r[i]).toString());
// Use gfr.getNumber() to get the msg number
for (int j = 0; j < gfr.getItemCount(); j++) {
Item item = gfr.getItem(j);
if (X_GM_LABELS.class.isInstance(item))
// get the labels
((X_GM_LABELS) item).x_gm_labels);
}
}
} catch (ProtocolException e) {
logError(e.getMessage(), e);
}
return null;
}
});
Then you need to do the re-parse using java-gmail-imap' parse() method.
Above implementation is excellently explained on following link.
Getting Gmail labels using javamail
Shishir

Categories

Resources