tulir / whatsmeow

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

Receiving messages on the whatsapp desktop app but not on phones and the browser #369

Closed Dakauann closed 1 year ago

Dakauann commented 1 year ago

Hello, im creating an automation using whatsmeow on whatsapp, but recently i through of implementing button responses, as i was testing it, i had to go to the browser version of whatsapp, when i sent a message its like it didnt receive nothing. (my account is a whatsapp business account)

Sending the command on the desktop app: image Sending the command on the browser/mobile whatsapp: image

func MakeWaConnection(Client *types.Client) *whatsmeow.Client {
    container, err := sqlstore.New("sqlite3", "file:./db/database.db?_foreign_keys=on", nil)
    if err != nil {
        panic(err)
    }

    deviceStore, err := container.GetFirstDevice()
    if err != nil {
        panic(err)
    }

    client := &types.Client{
        WAClient: whatsmeow.NewClient(deviceStore, nil),
    }
    client.Register()

    if client.WAClient.Store.ID == nil {
        qrChan, err := client.WAClient.GetQRChannel(context.Background())
        if err != nil {
            panic(err)
        }

        err = client.WAClient.Connect()
        if err != nil {
            panic(err)
        }

        for evt := range qrChan {
            if evt.Event == "code" {
                png, err := qrCode.Encode(evt.Code, qrCode.Medium, 256)
                if err != nil {
                    fmt.Println(err)
                }
                err = ioutil.WriteFile("qr.png", png, 0644)
            } else {
                fmt.Println("Login event:", evt.Event)
            }
        }
    } else {
        err = client.WAClient.Connect()
        if err != nil {
            panic(err)
        }
        fmt.Println("Connected to WhatsApp!")
    }

    c := make(chan os.Signal)
    signal.Notify(c, os.Interrupt, syscall.SIGTERM)
    <-c

    client.WAClient.Disconnect()

    return client.WAClient
}

The Messages event handler:

func HandleMessages(evt interface{}, client *whatsmeow.Client) {
    switch v := evt.(type) {
    case *events.Message:
        args := strings.Fields(*v.Message.ExtendedTextMessage.Text)
        startsWithPrefix := strings.HasPrefix(args[0], PREFIX)
        fmt.Println(startsWithPrefix, strings.Replace(args[0], PREFIX, "", 1))

        if startsWithPrefix && len(args) > 0 && !v.Info.IsFromMe {
            if _, ok := commands.Commands[strings.Replace(args[0], PREFIX, "", 1)]; ok {
                fmt.Println("Command found: ", args[0])
                commands.Commands[strings.Replace(args[0], PREFIX, "", 1)](client, v.Info.Chat)
            }
        }
    }
}

the function im using to send messages:

func SendTextMessage(client *whatsmeow.Client, JID types.JID, Message string) {
    client.SendMessage(context.Background(), JID, &waProto.Message{
        Conversation: proto.String(Message),
    })
}
Dakauann commented 1 year ago

@tulir do you know the reason?

ibroid commented 10 months ago

i had same issue here. but i only recive message from the phones. i think this is from the difference version of platform