How save messages received in a database using Yowsup?
I'm using yowsup-cli to send and receive messages, but I want to know how can I store all them in a database? I saw in wazapp documentation, but I'm new with python. I didn't realize how can I store messages received from yowsup-cli on bash. By a Model, something with bash's history? (Note: As I want to put it in a server, it's possible access history of a host's bash?)
Any help? Thanks everybody!
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
you might want to use WhatsAPI in perl if you're targeting for server
Really? It's impossible or just not recomended? There's no way to use yowsup in a server? Ok, thank you! And about save messages in a database (in my pc - yowsup - and on server - whatsAPI), you have some idea or maybe a link to know more about how can I do it?
Nobody will teach you using python or writing code for you. Search for easier solutions. If you still want to use Yowsup you should learn python. At last Yowsup is a Library, it's not complete solution, and yowsup-cli is just demonstration tool of Yowsup. If using Yowsup you need to make your own client with all features you need.
Sorry for it CODeRUS, wasn't my intention. I'm trying to learn more. Thanks for everything, and sorry again for any misunderstood.
Yowsup is using none special, just common Python functioins and libraries.
It's not that hard actually if u have basic logic for programing
U have to modify the cmdclient.py Add the mySql library And use the message received event to insert the incoming messages in the db
All right! guess I'm understanding, mrtass. Would seem nothing but helped me a lot. And thanks you both. I'll learn more.
@regisfcsantos You can add a new function to "onMessageReceived" to capture "messageContent" and process it, then you send the call processing "message_send" message
I have something like this
ListenerClient.py:
.....more code.... def onMessageReceived(self, messageId, jid, messageContent, timestamp, wantsReceipt, pushName, isBroadCast): formattedDate = datetime.datetime.fromtimestamp(timestamp).strftime('%d-%m-%Y %H:%M') jid = json.dumps(jid) messageContent = json.dumps(messageContent) os.system("python save.py " + jid + " " + messageContent + "") print "[from]" + jid + "[message]" + messageContent
And save.py:
import sys import MySQLdb import MySQLdb.cursors db = MySQLdb.connect(host="localhost", # your host, usually localhost user="aaaaaa", # your username passwd="*", # your password db="**", cursorclass=MySQLdb.cursors.DictCursor) # name of the data base
jid = str(sys.argv[1]) message = str(sys.argv[2])
cur = db.cursor() cur.execute(""" INSERT INTO WhatsappMessage (message, jid, stamp) VALUES (%s,%s, NOW())""", (message, jid, )) cur.execute("COMMIT")
@regisfcsantos brother did you get the data to the database? any way?
@regisfcsantos @juanmas07 any way of getting the recieved messages into a text file? pls help me im a noob :)
yowsup 2.0 makes it easy, stay tuned for the upcoming changes.
I have implemented this feature with the current version of yowsup. This is what I have done according to my need of a USSD like feature for whatsapp.
Once I get a message from whatsapp - I do an http request to my server which is running php scripts, do my messages logs with php+mysql, process what I need then issue back response as json. Once my python script gets this response - formatted in a standard way like this: { "message": "Response header instructions is here", "menu":[ {"code": "1", "tag": "Check order status"}, {"code": "2", "tag": "Check all orders status"} ] } I now then format this to a standard string , and send it back to the person who requested this service- whatsapp no : The response to user
Response header instructions is here
1: Check order status 2: Check all orders status
Once the user selects any of the above items, I repeat the same procedure of doing an http request then formatting the response till I get my client satisfied.
I will issue a pull request with this example.
Depending on how you are using Yowsup I would rather tend to use sqlite. It's faster and not using that much resources. (I do not want to start a discussion about it - just my personal opinion) You can either use a database like @juanmas07 showed in his post or creating a text-file for every session with a number. But use the ListenerClient.py script as first step it's easy and working ;)
I am really busy right now but I can try to give a brief example with storing messages in txt file (~weekend). So far look into this https://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files
Hi there...anybody could point me out how to get messages with yowsup library? I know how to send, but I couldn't figure out how to receive messages. Thanks any help