Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sending image fail in legacy yowsup-cli #581

Closed
morfeokmg opened this issue Jan 26, 2015 · 9 comments
Closed

sending image fail in legacy yowsup-cli #581

morfeokmg opened this issue Jan 26, 2015 · 9 comments
Labels

Comments

@morfeokmg
Copy link

Let me if understand your change, we need two steps for send the image to the smartphone.

  1. Upload the image to the wattsapp server.
  2. Send the message to the group or participant, as the image uploaded.

My question is: what kind of message we need for send the image in step 2. (text, url, image)
What I need implement for end the module??

I implement the legacy version for my server and I have reports on image format, my idea is send these one's to my wattsapp. Only I need the second step for complete this one.

I review the code but I don't the implementation for the command, I know how can with xml, only need the information for the command of send the image (that I understand the the command for upload is very different for the step 2nd)
morfeokmg

morfeokmg commented 17 days ago
This is my test.
I executed in debug mode.

....
YowsupConnectionManager: starting reader
YowsupConnectionManager: started
Sending picture /home/morfeokmg/watts/Caso1.jpg of size 42781 with name Caso1.jpg
Sending media_requestUpload
BinTreeNodeWriter: Outgoing
BinTreeNodeWriter:

......

BinTreeNodeReader: Incoming
BinTreeNodeReader:



Request Dublicate: hash: hsjVxrz8M1Z0J8nNmQAcBph3NIsuU6SDiNl6xiGp6OM= url: https://mmi631.whatsapp.net/d/AubJPvfWLCHP69u3qvJxNxoTVl1N0wNkjuC0mnt4B5t0.jpg
Sending message_image
BinTreeNodeWriter: Outgoing
BinTreeNodeWriter:


796573





BinTreeNodeReader: Incoming
BinTreeNodeReader:

Got request MediaReceipt
Please, I need know what I need modify or implement in the code in the Legacy version!!!!.

Best Regards.

@morfeokmg
Copy link
Author

I review the code on connectionmanager.py
I think that the incomplete code is:

@medianode
def sendImage(self, jid, url, name, size, preview):
return "image"
If this is correct, i Need implement some return as

return ProtocolTreeNode("media", {"type":"location","latitude":latitude,"longitude":longitude},None,preview)

but i don't know the variables, @tgalal, @chirikchik, @debianitram do you know what parameters i need???

Thanks in advance!

@morfeokmg
Copy link
Author

I analize the debug, and this is my unique conclusion

From UploaderClient.py the correct execution is:

        ReaderThread:   Read thread startedX
         YowsupConnectionManager:   started
        Sending picture /home/morfeokmg/watts/CasoMau.jpg of size 42781 with name CasoMau.jpg
        Sending media_requestUpload
        BinTreeNodeWriter:  Outgoing
        BinTreeNodeWriter:  
        <iq to="s.whatsapp.net" xmlns="w:m" type="set" id="upload_1">
            <media type="image" hash="hsjVxrz8M1Z0J8nNmQAcBph3NIsuU6SDiNl6xiGp6OM=" size="42781">
            </media>
        </iq>

This part doesn't work or is incomplete (I think that is the second option)
(from UploaderClient.py Interface : message_imageSend)

        def doSendImage(self, url):
                    print("Sending message_image")
                    statinfo = os.stat(self.path)
                    name=os.path.basename(self.path)

                    #im = Image.open("c:\\users\\poot\\desktop\\icon.png")                                                                                               
            #im.thumbnail(size, Image.ANTIALIAS)                                                                                                                 

                msgId = self.methodsInterface.call("message_imageSend", (self.jid, url, name,str(statinfo.st_size), "yes"))
            #msgId = self.methodsInterface.call("message_imageSend", (self.jid, url, name,str(statinfo.st_size), self.createThumb()))                            
            self.sentCache[msgId] = [int(time.time()), self.path]




        Request Dublicate: hash: hsjVxrz8M1Z0J8nNmQAcBph3NIsuU6SDiNl6xiGp6OM= url: https://mmi631.whatsapp.net/d/AubJPvfWLCHP69u3qvJxNxoTVl1N0wNkjuC0mnt4B5t0.jpg 
        Sending message_image
        BinTreeNodeWriter:  Outgoing
        BinTreeNodeWriter:  
        <message to="XXXXXXXXXXX-XXXXXXX@g.us" type="text" id="XXXXXXXXX-0">
            <media url="https://mmi631.whatsapp.net/d/AubJPvfWLCHP69u3qvJxNxoTVl1N0wNkjuC0mnt4B5t0.jpg" type="image" file="CasoMau.jpg" size="42781">
                796573
            </media>
            <x xmlns="jabber:x:event">
                <server>
                </server>
            </x>
        </message>

But message_imageSend
Is

self.methodInterface.registerCallback("message_imageSend",self.sendImage)

and sendImage is not implemented

        @sendMessage
            @mediaNode
        def sendImage(self, jid, url, name, size, preview):
            return "image"              

what I Need for implement the missing code?

Thanks!

@morfeokmg
Copy link
Author

At today, I tried change the sendImage method for the final step, but; without documentation is very hard. Do you have some document or can you help me to know the correct attributes?

This is the result of my last test:

The Code:

    491          @sendMessage
    492          @mediaNode
    493          def sendImage(self, jid, url, name, size, preview):
    494                  #return "image"
    495                  self._d("sending image (" + name + ":" + str(size) + ")")
    496
    497                  return ProtocolTreeNode("media", {"type":"image","name":name,"size":size,"url":url},None,preview)
    498

The result

  Request Succ: hash: hsjVxrz8M1Z0J8nNmQAcBph3NIsuU6SDiNl6xiGp6OM= url:       https://mmi648.whatsapp.net/u/8rqGLBDC4J0vHAlMvhyObj14pGEABQ2IHWHo0g/AubJPvfWLCHP6      9u3qvJxNxoTVl1N0wNkjuC0mnt4B5t0 resume: 0
  MediaUploader:  POST       https://mmi648.whatsapp.net/u/8rqGLBDC4J0vHAlMvhyObj14pGEABQ2IHWHo0g/AubJPvfWLCHP6      9u3qvJxNxoTVl1N0wNkjuC0mnt4B5t0
  Content-Type: multipart/form-data; boundary=zzXXzzYYzzXXzzQQ
  Host: mmi648.whatsapp.net      
  User-Agent: WhatsApp/2.12.49 S40Version/14.26 Device/Nokia302
  Content-Length: 43125

  MediaUploader:  sending REQUEST
  MediaUploader:  --zzXXzzYYzzXXzzQQ
  Content-Disposition: form-data; name="to"

  XXXXXXXXXXXX-XXXXXXXXXX@g.us
  --zzXXzzYYzzXXzzQQ
  Content-Disposition: form-data; name="from"

  XXXXXXXXXXXX
  --zzXXzzYYzzXXzzQQ
  Content-Disposition: form-data; name="file";       filename="314aac882ecc00a9b288d83f61c9ed83.jpg"
  Content-Type: image/jpeg


   Progress: 98MediaUploader:     Reading response...
  MediaUploader:  HTTP/1.1 200 OK
  Connection: close
  Content-Length: 275
  Content-Type: application/json
  X-WA-Metadata: filetype=jpg; filehash=hsjVxrz8M1Z0J8nNmQAcBph3NIsuU6SDiNl6xiGp6OM=;       type=image; width=700; height=434

  {"name":"314aac882ecc00a9b288d83f61c9ed83.jpg","url":"https://mmi648.whatsapp.net/d/AubJPvfWLCHP69u3qvJxNxoTVl1N0wNkjuC0mnt4B5t0.jpg","size":"42781","mimetype":"image/jpeg","filehash":"hsjVxrz8M1Z0J8nNmQAcBph3NIsuU6SDiNl6xiGp6OM=","type":"image","width":"700","height":"434"}
   Progress: 100MediaUploader:    {'mimetype': u'image/jpeg', 'name':       u'314aac882ecc00a9b288d83f61c9ed83.jpg', 'filehash':       u'hsjVxrz8M1Z0J8nNmQAcBph3NIsuU6SDiNl6xiGp6OM=', 'url':       u'https://mmi648.whatsapp.net/d/AubJPvfWLCHP69u3qvJxNxoTVl1N0wNkjuC0mnt4B5t0.jpg',       'height': u'434', 'width': u'700', 'error': None, 'type': u'image', 'size': u'42781'}

  Upload Succ: url:             https://mmi648.whatsapp.net/d/AubJPvfWLCHP69u3qvJxNxoTVl1N0wNkjuC0mnt4B5t0.jpg
  Sending message_image
  YowsupConnectionManager:        sending image (CasoMau.jpg:42781)
  BinTreeNodeWriter:      Outgoing
 ignored toString call, probably encountered byte
 ignored toString call, probably encountered byte
 BinTreeNodeWriter:
 None
 Error occured at transfer ProtocolTreeNode instance has no attribute 'index'

Upload Fail:
Got request MediaReceipt

@morfeokmg
Copy link
Author

Analysing the steps, I see these parameters, but i don't know what are the corrects for send

 X-WA-Metadata: filetype=jpg; filehash=hsjVxrz8M1Z0J8nNmQAcBph3NIsuU6SDiNl6xiGp6OM=;      type=image; width=700; height=434

 {"name":"314aac882ecc00a9b288d83f61c9ed83.jpg","url":"https://mmi648.whatsapp.net/d/AubJPvfWLCHP69u3qvJxNxoTVl1N0wNkjuC0mnt4B5t0.jpg","size":"42781","mimetype":"image/jpeg","filehash":"hsjVxrz8M1Z0J8nNmQAcBph3NIsuU6SDiNl6xiGp6OM=","type":"image","width":"700","height":"434"}
  Progress: 100MediaUploader:    {'mimetype': u'image/jpeg', 'name':      u'314aac882ecc00a9b288d83f61c9ed83.jpg', 'filehash':      u'hsjVxrz8M1Z0J8nNmQAcBph3NIsuU6SDiNl6xiGp6OM=', 'url':      u'https://mmi648.whatsapp.net/d/AubJPvfWLCHP69u3qvJxNxoTVl1N0wNkjuC0mnt4B5t0.jpg',      'height': u'434', 'width': u'700', 'error': None, 'type': u'image', 'size': u'42781'}

I tried with variations of these ones:

mmNode = ProtocolTreeNode("media", {"type":mediaType,"file":name,"size":size,"url":url},None, args[4:][0] if args[4:] else None);

ProtocolTreeNode("media", {"type":"location","latitude":latitude,"longitude":longitude},None,preview)

@h1rule
Copy link

h1rule commented Jan 27, 2015

Hey man,

i need to send images through a single command. like ./yowsup-cli -c config -sendimage /path/image.jpg 49999999-99999999

Are you able to modify the code of yowsup? I dont want to login first, then /L then /image send.

:s

@morfeokmg
Copy link
Author

No, this issue is for the legacy version, this version can be use in the command line the login information is taken of the configuration file.

I like the last program style, i don't review the new version 2.0 with the layers style yet.

@morfeokmg
Copy link
Author

@tgalal, do you have the parameters that i need for this implement, please ???

thanks!

@tgalal tgalal added the legacy label Feb 1, 2015
@tgalal
Copy link
Owner

tgalal commented Feb 1, 2015

@morfeokmg

For sending the uploaded image it's should be something like this:

    <message t="{{TIME_STAMP}}" from="{{CONTACT_JID}}" 
        offline="{{OFFLINE}}" type="media" id="{{MESSAGE_ID}}" notify="{{NOTIFY_NAME}}">
        <media type="image"
            mimetype="{{MIME_TYPE}}" 
            filehash="{{FILE_HASH}}"
            url="{{DOWNLOAD_URL}}" 
            ip="{{IP}}"
            size="{{MEDIA SIZE}}"
            file="{{FILENAME}}" 


            encoding="{{ENCODING}}" 
            height="{{IMAGE_HEIGHT}}" 
            width="{{IMAGE_WIDTH}}"

            > {{THUMBNAIL_RAWDATA}}
        </media>
    </message>

And so to manually construct something that resolves to this, you should do something like:

messageNode = ProtocolTreeNode("message", {"to": jid, "type": "media", ...})
mediaNode = ProtocolTreeNode("media", {"type": "image", "url": url, "mimetype": mimetype, ...}, data = preview) #if you want to send thumbnail/preview
messageNode.addChild(mediaNode)

And then send this messageNode. In yowsup's old code, the decorators @sendMessage, @medianode automatically transformed what sendImage function returned into this.

@morfeokmg
Copy link
Author

thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants