tulir / whatsmeow

Go library for the WhatsApp web multidevice API
https://go.mau.fi/whatsmeow
Mozilla Public License 2.0
2.29k stars 427 forks source link

Please update Upload documentation #619

Closed FabioSebs closed 4 months ago

FabioSebs commented 4 months ago

If waProto is deprecated I can't seem to find the correct way to Upload a pdf or a png. Can you please provide a working example in the documentation thank you guys

FabioSebs commented 4 months ago

This is how I am currently trying it but I get no message unfortunately. Is there something I am missing?

func SendInvoiceExample(filename string) (err error) {
    var (
                msg string = "hello world!"
        ctx = context.Background()
    )

    fileData, err := os.ReadFile(filename)
    if err != nil {
        return
    }

    resp, err := w.client.Upload(ctx, fileData, whatsmeow.MediaImage)
    if err != nil {
        return
    }

    toJID := types.JID{
        User:   "12345678901",
        Server: types.DefaultUserServer,
    }

    message := &waE2E.ImageMessage{
        Caption:       proto.String("Hello, world!"),
        URL:           &resp.URL,
        Mimetype:      proto.String("image/png"),
        FileLength:    &resp.FileLength,
        MediaKey:      resp.MediaKey,
        FileEncSHA256: resp.FileEncSHA256,
        FileSHA256:    resp.FileSHA256,
    }

    _, err = w.client.SendMessage(ctx, toJID, &waE2E.Message{
        Conversation: &msg,
        ImageMessage: message,
    })

    return
}
tulir commented 4 months ago

Only one top-level type in waE2E.Message must be set. Conversation and ImageMessage are mutually exclusive.

FabioSebs commented 4 months ago

thanks a lot man , respect your hard work 👍🏼