mnkgrover08-zz / whatsapp_automation

Whatsapp Automation is a collection of APIs that interact with WhatsApp messenger running in an Android emulator, allowing developers to build projects that automate sending and receiving messages, adding new contacts and broadcasting messages multiple contacts.
GNU General Public License v3.0
202 stars 61 forks source link

Listen for new messages not working #15

Closed lddd closed 5 years ago

lddd commented 5 years ago

Hey,

Adding contacts, sending single message and broadcast works like in your example.

But how to work with incoming messages? I tested sending some messages to that number/device and they arrive but won´t get recognized.

All i get is:

[roman@CentOS-75-64-minimal whatsapp_automation]# python new_message_listener_producer.py dev Waiting For Messages

lddd commented 5 years ago

Hello?

mnkgrover08-zz commented 5 years ago

Hi Roman

Incoming messages work as mentioned in description. You need Database connection for that. sql file is already present in root of project with name whatsapp_rnd_db.sql. Import it in DB and set the credentials in dev.cfg file. According to current functionality when you send msgs on emulator following steps occur

  1. Code reads your last message only sent on emulator
  2. message can be either subscribe or unsubscribe So make sure you are only sending one of them.
  3. if it is subscribe then it will search your mobile number in DB and add if it is not there and mark subscribe status as true and print message otherwise just print msg.
  4. if it is unsubscribe then Looks for contact in DB if exists then update subscribe status to false and print message otherwise add the contact entry in DB and update subscribe status to false and print msg.

Basically the idea behind new message listener was to look for contacts which sent subscribe and add them to DB and send them updates or else unsubscribe them and stop sending further updates.

Note: you can modify this functionality according to your requirement.

So the process goes like.

  1. Send message to your emulator with either subscribe or unsubscribe
  2. Navigate to worker tab which is listening like:

[roman@CentOS-75-64-minimal whatsapp_automation]# python new_message_listener_producer.py dev Waiting For Messages

  1. In the postman hit the API for listen new message and navigate back to worker tab.

you will see the above mentioned functionality working and message printed accordingly.

@lddd Let me know how it goes.

Thanks. Mayank

lddd commented 5 years ago

Hi,

Thank you. I will check my database settings, there might be something wrong.

So this is basically for listening and reacting to specific commands only right?

What about listening for all incoming messages?

I would like to save all incoming messages for each phone number to the database?

mnkgrover08-zz commented 5 years ago

Hi Roman

You are Welcome!

Yeah you can say it has been customised to listen and react for specific commands.

I have put a simple condition to read the last new incoming message and compare if it matches subscribe or unsubscribe and then perform action accordingly.

Complete logic for new messages parsing is written in file https://github.com/mnkgrover08/whatsapp_automation/blob/master/workers/whatsapp_new_message_listener_worker.py

You can tweak the logic according to your requirements. loop is running for new messages where I am only taking out last index message, so you can run another loop and write all messages in DB or anything you want.

yes for sure you can store all incoming messages for each phone in DB. Just go through file whatsapp_new_message_listener_worker.py for a better understanding.

Thanks Mayank

On Tue, Nov 27, 2018 at 4:03 PM Roman M. notifications@github.com wrote:

Hi,

Thank you. I will check my database settings, there might be something wrong.

So this is basically for listening and reacting to specific commands only right?

What about listening for all incoming messages?

I would like to save all incoming messages for each phone number to the database?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/mnkgrover08/whatsapp_automation/issues/15#issuecomment-442009385, or mute the thread https://github.com/notifications/unsubscribe-auth/AGH0KpTEsfHLlgVZTh3SAflDdGDbm-Gzks5uzRT4gaJpZM4YxV2s .

lddd commented 5 years ago

I checked all settings again and updated whatsapp_new_message_listener_worker.py

However its still not working. Tested "subscribe" "unsubscribe"

See: https://i.postimg.cc/fydHMQYF/screen.jpg

mnkgrover08-zz commented 5 years ago

working fine at my end. This needs debugging Roman, will not be able to help remotely via email.

However take pull of repo for latest code and check once if your rabbit mq exchange and queue is working properly for new message listner because in screenshot it seems that request is not even coming to your worker. otherwise it would have printed some msgs.

Thanks Mayank

On Tue 27 Nov, 2018, 8:22 PM Roman M. <notifications@github.com wrote:

I checked all settings again and updated whatsapp_new_message_listener_worker.py

However its still not working. Tested "subscribe" "unsubscribe"

See: https://i.postimg.cc/fydHMQYF/screen.jpg

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/mnkgrover08/whatsapp_automation/issues/15#issuecomment-442086041, or mute the thread https://github.com/notifications/unsubscribe-auth/AGH0Ko-UTjeEU9SWplvAgWoYYfXVAPSBks5uzVGggaJpZM4YxV2s .

lddd commented 5 years ago

I don´t know why the request is not coming in to this worker.

Single Message and Broadcast Worker is working as expected. Just incoming messages, nothing happens.

I will send you details to the docker test environment on Skype, so you can have a look if you would like.

thanks in advance, Roman

MalteToenjes commented 5 years ago

@lddd did you find a solution? I got the same issue.

@mnkgrover08 I also had to write the db connection params into the .py file, because the config file couldn't be found cause its not imported. I'm wondering about this...should'nt it be imported?