whatsapp-framework
whatsapp-framework copied to clipboard
How to get all opened chats?
How to get list of all chats, (users who have messaged me)
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.
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! ;)
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 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...