whatsapp-framework icon indicating copy to clipboard operation
whatsapp-framework copied to clipboard

How to get all opened chats?

Open takasurazeem opened this issue 6 years ago • 4 comments

How to get list of all chats, (users who have messaged me)

takasurazeem avatar Aug 30 '18 01:08 takasurazeem

My method is to create some global variable inside your module and manually fill it. Smth like:

from app.mac import mac, signals

CONVERSATIONS = {}

@signals.message_received.connect
def handle(message):
        if message.conversation not in CONVERSATIONS:
            CONVERSATIONS[message.conversation] = {'count': 0, 'messages': []}

Same logic can be done with files or db.

PATAPOsha avatar Sep 06 '18 15:09 PATAPOsha

This is simple you just want to know who messaged your bot and it's name and message right?


from app.mac import mac, signals
import datetime as dt

@signals.message_received.connect
def handle(message):
    date_str = dt.datetime.now().strftime('%Y-%m-%d-%H:%M:%S')
    name = message.who_name
    no = message.who
    con = message.conversation
    msg = message.text
    f= open("./cache/Logs/logs.log","a+")
    f.write("Mesage Received: "+msg+"\nSender Name: "+name+"\nSender Contact Number: "+no+"\nConversation: "+con+"\nDate & Time: "+date_str+"\n---------------------------------\n")
    f.close()

Now it will work as a log file it will save all records to logs.log file including group messages also wherever your bot is added! ;)

x-frst avatar Sep 14 '18 12:09 x-frst

This is simple you just want to know who messaged your bot and it's name and message right?


from app.mac import mac, signals
import datetime as dt

@signals.message_received.connect
def handle(message):
    date_str = dt.datetime.now().strftime('%Y-%m-%d-%H:%M:%S')
    name = message.who_name
    no = message.who
    con = message.conversation
    msg = message.text
    f= open("./cache/Logs/logs.log","a+")
    f.write("Mesage Received: "+msg+"\nSender Name: "+name+"\nSender Contact Number: "+no+"\nConversation: "+con+"\nDate & Time: "+date_str+"\n---------------------------------\n")
    f.close()

Now it will work as a log file it will save all records to logs.log file including group messages also wherever your bot is added! ;) so what about if someone sends an image to your bot, do you know how to catch it and save?

gabrieru avatar Oct 10 '18 00:10 gabrieru

@gabrieru when someone sends your bot a media file it automatically saves it in ./whatsapp-framework/app/assets/received however it automatically creates an Asset folder if someone sends some media...

x-frst avatar Oct 10 '18 01:10 x-frst