Go-whatsapp: Download again

Created on 10 Aug 2020  Â·  7Comments  Â·  Source: Rhymen/go-whatsapp

Good Morning!

Does anyone know a way to retrieve a message and download again the image or files?

Most helpful comment

it is, includes it lets merge it :)

On Sat, Aug 22, 2020 at 1:39 AM Valdenir Luíz Mezadri Junior <
[email protected]> wrote:

It works

func (h *waHandler) HandleImageMessage(message whatsapp.ImageMessage) {
if strings.HasPrefix(message.Info.Id, "3EB04E67107BE197D91A") {
id := message.Info.Id
jid := message.Info.RemoteJid
fmt.Println(id)
msg, err := h.wac.GetMessage(jid, id)
if err != nil {
fmt.Println(err)
}
switch msg.(type) {
case whatsapp.ImageMessage:
image := msg.(whatsapp.ImageMessage)
f, err := image.Download()
if err != nil {
fmt.Printf("%+vn", err)
}
saveFile(f)
}
}
}

func saveFile(data []byte) {
filename := "teste.jpeg"
file, err := os.Create(filename)
defer file.Close()
if err != nil {
return
}
_, err = file.Write(data)
if err != nil {
return
}
log.Printf("image received, saved at:%vn", filename)
}

I don't know if it's worth including this function

https://github.com/Valdenirmezadri/go-whatsapp/commit/b3e0a57bdc7178736380fa8da83e6c30052f1d5c

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/Rhymen/go-whatsapp/issues/426#issuecomment-678544417,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ABDLT2Z5M6JFS7GUBNUCMXTSB3ZSJANCNFSM4PZ66JDA
.

All 7 comments

Hi @Valdenirmezadri , i'm sure this same question was answered in previous closed issues.
I looked for but couldn't find.

Summarily, you must load an historical chat of the contact looking for the specific message. It is possible loading previous or next messages based on a known WhatsAppMessageId using these functions below:

```
func (wac Conn) LoadMessagesBefore(jid, messageId string, fromMe bool, count int) (binary.Node, error) {
return wac.query("message", jid, messageId, "before", strconv.FormatBool(fromMe), "", count, 0)
}

func (wac Conn) LoadMessagesAfter(jid, messageId string, fromMe bool, count int) (binary.Node, error) {
return wac.query("message", jid, messageId, "after", strconv.FormatBool(fromMe), "", count, 0)
}

how can i work with binary.Node ?

I guess in this case you'll have a []proto.WebMessageInfo. However, I suggest you do some debugs and try match with any known structure.

It works

func (h *waHandler) HandleImageMessage(message whatsapp.ImageMessage) {
if strings.HasPrefix(message.Info.Id, "3EB04E67107BE197D91A") {
id := message.Info.Id
jid := message.Info.RemoteJid
fmt.Println(id)
msg, err := h.wac.GetMessage(jid, id)
if err != nil {
fmt.Println(err)
}
switch msg.(type) {
case whatsapp.ImageMessage:
image := msg.(whatsapp.ImageMessage)
f, err := image.Download()
if err != nil {
fmt.Printf("%+vn", err)
}
saveFile(f)
}
}
}

func saveFile(data []byte) {
filename := "teste.jpeg"
file, err := os.Create(filename)
defer file.Close()
if err != nil {
return
}
_, err = file.Write(data)
if err != nil {
return
}
log.Printf("image received, saved at:%vn", filename)
}

I don't know if it's worth including this function
https://github.com/Valdenirmezadri/go-whatsapp/commit/b3e0a57bdc7178736380fa8da83e6c30052f1d5c

it is, includes it lets merge it :)

On Sat, Aug 22, 2020 at 1:39 AM Valdenir Luíz Mezadri Junior <
[email protected]> wrote:

It works

func (h *waHandler) HandleImageMessage(message whatsapp.ImageMessage) {
if strings.HasPrefix(message.Info.Id, "3EB04E67107BE197D91A") {
id := message.Info.Id
jid := message.Info.RemoteJid
fmt.Println(id)
msg, err := h.wac.GetMessage(jid, id)
if err != nil {
fmt.Println(err)
}
switch msg.(type) {
case whatsapp.ImageMessage:
image := msg.(whatsapp.ImageMessage)
f, err := image.Download()
if err != nil {
fmt.Printf("%+vn", err)
}
saveFile(f)
}
}
}

func saveFile(data []byte) {
filename := "teste.jpeg"
file, err := os.Create(filename)
defer file.Close()
if err != nil {
return
}
_, err = file.Write(data)
if err != nil {
return
}
log.Printf("image received, saved at:%vn", filename)
}

I don't know if it's worth including this function

https://github.com/Valdenirmezadri/go-whatsapp/commit/b3e0a57bdc7178736380fa8da83e6c30052f1d5c

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/Rhymen/go-whatsapp/issues/426#issuecomment-678544417,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ABDLT2Z5M6JFS7GUBNUCMXTSB3ZSJANCNFSM4PZ66JDA
.

Nice!

Buy polish it and make it usable as method or function.. Etc

On Wed, 26 Aug 2020, 8:30 pm Rafael Henrique, notifications@github.com
wrote:

Nice!

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/Rhymen/go-whatsapp/issues/426#issuecomment-681020023,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ABDLT2ZSEU3Z4B7TANN33CDSCVBEDANCNFSM4PZ66JDA
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yazeed44 picture yazeed44  Â·  4Comments

orangehaired picture orangehaired  Â·  10Comments

lutpiero picture lutpiero  Â·  8Comments

Valdenirmezadri picture Valdenirmezadri  Â·  5Comments

Manjit2003 picture Manjit2003  Â·  9Comments