WhatsApp Web API

Overview

go-whatsapp

Package rhymen/go-whatsapp implements the WhatsApp Web API to provide a clean interface for developers. Big thanks to all contributors of the sigalor/whatsapp-web-reveng project. The official WhatsApp Business API was released in August 2018. You can check it out here.

Installation

go get github.com/Rhymen/go-whatsapp

Usage

Creating a connection

import (
    whatsapp "github.com/Rhymen/go-whatsapp"
)

wac, err := whatsapp.NewConn(20 * time.Second)

The duration passed to the NewConn function is used to timeout login requests. If you have a bad internet connection use a higher timeout value. This function only creates a websocket connection, it does not handle authentication.

Login

qrChan := make(chan string)
go func() {
    fmt.Printf("qr code: %v\n", <-qrChan)
    //show qr code or save it somewhere to scan
}()
sess, err := wac.Login(qrChan)

The authentication process requires you to scan the qr code, that is send through the channel, with the device you are using whatsapp on. The session struct that is returned can be saved and used to restore the login without scanning the qr code again. The qr code has a ttl of 20 seconds and the login function throws a timeout err if the time has passed or any other request fails.

Restore

newSess, err := wac.RestoreWithSession(sess)

The restore function needs a valid session and returns the new session that was created.

Add message handlers

type myHandler struct{}

func (myHandler) HandleError(err error) {
	fmt.Fprintf(os.Stderr, "%v", err)
}

func (myHandler) HandleTextMessage(message whatsapp.TextMessage) {
	fmt.Println(message)
}

func (myHandler) HandleImageMessage(message whatsapp.ImageMessage) {
	fmt.Println(message)
}

func (myHandler) HandleDocumentMessage(message whatsapp.DocumentMessage) {
	fmt.Println(message)
}

func (myHandler) HandleVideoMessage(message whatsapp.VideoMessage) {
	fmt.Println(message)
}

func (myHandler) HandleAudioMessage(message whatsapp.AudioMessage){	
	fmt.Println(message)
}

func (myHandler) HandleJsonMessage(message string) {
	fmt.Println(message)
}

func (myHandler) HandleContactMessage(message whatsapp.ContactMessage) {
	fmt.Println(message)
}

func (myHandler) HandleBatteryMessage(message whatsapp.BatteryMessage) {
	fmt.Println(message)
}

func (myHandler) HandleNewContact(contact whatsapp.Contact) {
	fmt.Println(contact)
}

wac.AddHandler(myHandler{})

The message handlers are all optional, you don't need to implement anything but the error handler to implement the interface. The ImageMessage, VideoMessage, AudioMessage and DocumentMessage provide a Download function to get the media data.

Sending text messages

text := whatsapp.TextMessage{
    Info: whatsapp.MessageInfo{
        RemoteJid: "[email protected]",
    },
    Text: "Hello Whatsapp",
}

err := wac.Send(text)

Sending Contact Messages

contactMessage := whatsapp.ContactMessage{
			Info: whatsapp.MessageInfo{ 
                RemoteJid: "[email protected]", 
                },
			DisplayName: "Luke Skylwallker",
			Vcard: "BEGIN:VCARD\nVERSION:3.0\nN:Skyllwalker;Luke;;\nFN:Luke Skywallker\nitem1.TEL;waid=0123456789:+1 23 456789789\nitem1.X-ABLabel:Mobile\nEND:VCARD",
		}

id, error := client.WaConn.Send(contactMessage)

The message will be send over the websocket. The attributes seen above are the required ones. All other relevant attributes (id, timestamp, fromMe, status) are set if they are missing in the struct. For the time being we only support text messages, but other types are planned for the near future.

Legal

This code is in no way affiliated with, authorized, maintained, sponsored or endorsed by WhatsApp or any of its affiliates or subsidiaries. This is an independent and unofficial software. Use at your own risk.

License

The MIT License (MIT)

Copyright (c) 2018

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Comments
  • Getting banned

    Getting banned

    For past 1 week, all of the numbers I'm using are getting banned after few hours i log in using this library, I'm not using proxy & running 4 bots on same vps, can anyone tell me what's wrong here? Should I use proxies or something else?

    opened by Ased2235 40
  • sending message timed out

    sending message timed out

    I can repro this most of the time: sending to someone else is ok, sending to the account who's QR code I scanned fails with timeout when sending. I'm on master due to #409.

    opened by andig 38
  • could not decode binary: invalid string with tag 174

    could not decode binary: invalid string with tag 174

    Hello, I got this error

    error caught in handler: error processing data: error decoding binary: could not decode binary: invalid string with tag 174
    

    Directly after scanning the QR

    Here is some information

    Mobile OS: Android 6.0
    Whatsapp Version: 2.19.190
    go-whatsapp Version: latest, the master branch at 4c0e263c801b8b5bd7fad1577786ab6c32c2c042
    

    A small note here for the owner, i'm also working on another project uses the same implementation as this project, but written in rust, and of course since most of my code is ported from this project i'm now facing the same problem.

    Here is a debug log from my implementation that maybe help

    OPEN THE LOG

    [2019-07-08T02:46:39Z DEBUG wapi::client] Received message Text("s1,[\"Conn\",{\"ref\":\" MASKEDI\",\"wid\":\"[email protected]\",\"connected\":true,\"isResponse\":\"false\",\"serverToken\":\"MASKED",\"browserToken\":\"  MQWKED",\"clientToken\":\"MASKED",\"lc\":\"US\",\"lg\":\"en\",\"locales\":\"en-US\",\"secret\":\"MASKED",\"protoVersion\":[0,17],\"binVersion\":11,\"battery\":48,\"plugged\":false,\"platform\":\"android\",\"features\":{\"URL\":true,\"FLAGS\":\"EAEYASgBOAFAAUgBWAFgAWgBmAEBoAEBsAECyAEB2AEC6AEC\"},\"phone\":{\"wa_version\":\"2.19.190\",\"mcc\":\"602\",\"mnc\":\"002\",\"os_version\":\"6.0\",\"device_manufacturer\":\"LENOVO\",\"device_model\":\"A7000plus\",\"os_build_number\":\"A7000-a_PLUS_S308_160618_ROW\"},\"pushname\":\"Shady Khalifa\",\"tos\":0}]")
    [2019-07-08T02:46:39Z INFO  echo] new state: Connected
    [2019-07-08T02:46:39Z DEBUG echo] PersistentSession { client_token: "MASKED", server_token: "MASKED", client_id:[...], mac: [...] }
    [2019-07-08T02:46:39Z INFO  echo] user data changed: UserJid(Jid { id: "MASKED", is_group: false, is_broadcast: false, is_remote: false })
    [2019-07-08T02:46:39Z DEBUG wapi::client] Received message Text("s2,[\"Blocklist\",{\"id\":1,\"blocklist\":[\"[email protected]\",\"[email protected]\"]}]")
    [2019-07-08T02:46:39Z DEBUG wapi::client] received json: Array([Short("Blocklist"), Object(Object { store: [("id", Number(Number { category: 1, exponent: 0, mantissa: 1 }), 0, 1), ("blocklist", Array([Short("[email protected]"), Short("[email protected]")]), 0, 0)] })])
    [2019-07-08T02:46:39Z DEBUG wapi::client] Received message Binary([52, 55, 97, 102, 55, 54, 97, 51, 54, 99, 101, 102, 55, 51, 100, 97, 46, 45, 45, 51, 55, 44, 143, 101, 218, 52, 137, 207, 52, 177, 250, 42, 128, 60, 171, 213, 126, 119, 224, 168, 116, 2, 152, 239, 223, 149, 241, 245, 59, 2, 99, 220, 68, 91, 10, 201, 229, 160, 28, 210, 240, 238, 154, 30, 168, 29, 1, 7, 195, 210, 241, 179, 242, 237, 49, 101, 16, 36, 117, 126, 29, 110, 166, 125, 136, 149, 73, 4, 218, 75, 16, 151, 219, 229, 251, 80, 128, 130, 43, 68, 199, 1, 146, 9, 77, 41, 80, 171, 118, 172, 201, 64, 84, 118, 50, 97, 120, 233, 76, 147, 221, 137, 217, 250, 168, 163, 204, 197, 196, 112, 183, 253, 52, 144, 235, 28, 245, 55, 47, 15, 150, 123, 218, 200, 5, 56, 191, 208, 124, 214, 6, 28, 13, 74, 96, 114, 107, 111, 130, 22, 159, 181, 146, 222, 20, 164, 4, 4, 149, 81, 218, 174, 11, 196, 139, 14, 225, 129, 23, 136, 234, 165, 245, 155, 191, 250, 39, 68, 2, 230, 51, 90, 175, 190, 157, 211, 70, 32, 236, 95, 146, 113, 98, 183, 187, 132, 176, 170, 180, 239, 251, 165, 153, 124, 78, 150, 214, 142, 24, 89, 145, 167, 96, 253, 66, 155, 206, 160, 15, 129, 201, 58, 45, 132, 91, 160, 107, 187, 135, 96, 43, 183, 147, 182, 102, 175, 96, 212, 193, 38, 13, 87, 60, 19, 245, 217, 42, 181, 165, 8, 102, 141])
    [2019-07-08T02:46:39Z TRACE wapi::protocol] Found the sep at: 21, and the tag is: [52, 55, 97, 102, 55, 54, 97, 51, 54, 99, 101, 102, 55, 51, 100, 97, 46, 45, 45, 51, 55]
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 9
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 248
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 23
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 91
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 139
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 248
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 52
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 45
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 250
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 255
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 80
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 52
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 45
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 250
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 255
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 80
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 52
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 45
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 250
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 255
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 80
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 52
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 45
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 250
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 255
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 80
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 40
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 45
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 250
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 255
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 80
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 40
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 45
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 250
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 255
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 80
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 40
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 45
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 250
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 255
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 80
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 40
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 45
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 250
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 255
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 35
    [2019-07-08T02:46:39Z DEBUG wapi::node] trying to find the tag: 174
    thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Unknown("Invalid Tag, tag 174")'
    

    i'm open to provide more information as needed to reproduce this issue

    Thanks :)

    opened by shekohex 31
  • Login connection timed out

    Login connection timed out

    Last few hours I got "login connection timed out" error message when trying to login via session. Tried to change waVersion but still get timed out. Does anyone get this error message too?

    opened by cht368 27
  • document upload failed

    document upload failed

    Hi All. I got an error message when uploading the document. error sending message: document upload failed: Post "https:///mms/document/OVk5iQKFT6By4U...."

    Is there any update on WhatsApp?

    opened by luwice 21
  • Memory usage with session restoration

    Memory usage with session restoration

    Hello guys,

    I am having a weird problem after making some experiments with the library(the current master branch)..

    I have a session stored and a function that keeps restoring(every X minutes) this session with:

    newSession, err = wac.RestoreWithSession(storedSession)

    but if err != nil(cellphone offline or app was unauthorized in wpp app) , the cpu usage goes up(and doesn't go down afterwards, only if app os.Exit()) and as i mentioned, this restore process runs forever and this is causing CPU usage to go up to almost 100% sometimes and the process gets killed by the kernel.

    And just to mention, if err == nil things run just fine and cpu keeps normal.

    Does anyone ever had some similar problem or an idea of why this is happening?

    opened by x00b 21
  • Disconnected after 24 hour with 1000 error status

    Disconnected after 24 hour with 1000 error status

    Hi all, I wonder what is the meaning of the error 1000

    ErrConnectionClosed server closed connection,code: 1000,text What is that's mean.? And should l rescan the QRcode?

    UPDATE I rescanned he QR code at 2020-11-11 14:16:56 and at 2020-11-12 17:29:20 I got disconnection! Regard

    opened by beshoo 19
  • Cant login

    Cant login

    error during login: error decoding login resp: json: cannot unmarshal array into Go value of type map[string]interface {}

    login successful, session: {uocSvrqQWvColFnkQ0aW2w== [] [] }

    go func() {
    		terminal := qrcodeTerminal.New()
    		terminal.Get(<-qr).Print()     //err here
    	}()
    
    
    
    

    I have no session in /tmp, the problem generates when trying to generate QR code. Ive already updated to last version of the repo. Thanks in advance

    opened by b4-io 19
  •  Error decoding login resp

    Error decoding login resp

    2020/03/26 17:21:57 error logging in: error during login: error decoding login resp: json: cannot unmarshal array into Go value of type map[string]interface {} I'm getting this error since this morning i already updated this library but i'm still getting this error, Can anyone please help me?

    Edit: See this comment

    opened by Ased2235 18
  • QR Code benchmark generate memory problem!

    QR Code benchmark generate memory problem!

    Hello, I have this function served via swagger

    func ScanQr(params profile.ScanQrParams) middleware.Responder {
            qr := make(chan string)
            errCh := make(chan error)
    
            go func() {
                    sessionID := params.SessionID.String()
                    handler, err := wa.Login(qr, params.ProxyURL, sessionID)
                    if err != nil {
                            errCh <- err
                    }
                    wa.Connections[sessionID] = handler
            }()
    
            select {
            case err := <-errCh:
                    errText := err.Error()
                    return profile.NewScanQrDefault(500).WithPayload(&models.Error{
                            Code:    500,
                            Message: &errText,
                    })
            case qrText := <-qr:
                    return profile.NewScanQrOK().WithPayload(&models.QRCode{
                            Base64: qrText,
                    })
    
            }
    
    }
    
    

    I tried to flood the function with 50 requests to understand what will be going on if we have 50 users online asking for the QR... Well, i got a server panic a VERY LONG error but I will add the deader of the error.

    runtime: out of memory: cannot allocate 26214400-byte block (3927212032 in use)
    fatal error: out of memory
    
    runtime stack:
    runtime.throw(0x87ae49f, 0xd)
            /usr/local/go/src/runtime/panic.go:774 +0x6a
    runtime.largeAlloc(0x1900000, 0x8090101, 0xe740ed20)
            /usr/local/go/src/runtime/malloc.go:1140 +0x108
    runtime.mallocgc.func1()
            /usr/local/go/src/runtime/malloc.go:1033 +0x39
    runtime.systemstack(0x9588700)
            /usr/local/go/src/runtime/asm_386.s:399 +0x53
    runtime.mstart()
            /usr/local/go/src/runtime/proc.go:1146
    
    goroutine 2083 [running]:
    runtime.systemstack_switch()
            /usr/local/go/src/runtime/asm_386.s:360 fp=0x9c1397c sp=0x9c13978 pc=0x8098d00
    runtime.mallocgc(0x1900000, 0x86dc340, 0x87ef801, 0x84cc9a40)
            /usr/local/go/src/runtime/malloc.go:1032 +0x6a8 fp=0x9c139d0 sp=0x9c1397c pc=0x8052508
    runtime.makeslice(0x86dc340, 0x1900000, 0x1900000, 0xe74b9cb8)
            /usr/local/go/src/runtime/slice.go:49 +0x4f fp=0x9c139e4 sp=0x9c139d0 pc=0x8085acf
    bufio.NewReaderSize(...)
            /usr/local/go/src/bufio/bufio.go:56
    github.com/gorilla/websocket.newConn(0x88e4140, 0x1232000, 0x0, 0x1900000, 0xa00000, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
            /root/go/pkg/mod/github.com/gorilla/[email protected]/conn.go:293 +0x2e1 fp=0x9c13a4c sp=0x9c139e4 pc=0x85a56d1
    github.com/gorilla/websocket.(*Dialer).DialContext(0x950c340, 0x88df800, 0x950cfc0, 0x87b9975, 0x19, 0x8d96fc68, 0x0, 0x0, 0x0, 0x0)
            /root/go/pkg/mod/github.com/gorilla/[email protected]/client.go:327 +0xc6f fp=0x9c13be4 sp=0x9c13a4c pc=0x85a2def
    github.com/gorilla/websocket.(*Dialer).Dial(0x950c340, 0x87b9975, 0x19, 0x8d96fc68, 0x8d96fccc, 0x84dc65e, 0x0, 0x0)
            /root/go/pkg/mod/github.com/gorilla/[email protected]/client.go:106 +0x4d fp=0x9c13c10 sp=0x9c13be4 pc=0x85a1fad
    github.com/Rhymen/go-whatsapp.(*Conn).connect(0x9a253b0, 0x0, 0x0)
            /root/go/pkg/mod/github.com/!rhymen/[email protected]/conn.go:163 +0x1a1 fp=0x9c13d34 sp=0x9c13c10 pc=0x85b8601
    github.com/Rhymen/go-whatsapp.NewConn(0xf8475800, 0xd, 0x87bc8dd, 0x1d, 0x121cdb8)
            /root/go/pkg/mod/github.com/!rhymen/[email protected]/conn.go:125 +0x119 fp=0x9c13d5c sp=0x9c13d34 pc=0x85b8229
    bitbucket.org/rockyOO7/wa-api/whatsapp.NewConn(0x0, 0x98ff6f8, 0x0, 0x0)
            /home/beshoo/go-wapi/wa/whatsapp/main.go:164 +0x1b8 fp=0x9c13dcc sp=0x9c13d5c pc=0x8606438
    bitbucket.org/rockyOO7/wa-api/whatsapp.Login(0x19223580, 0x0, 0x97f0f90, 0x24, 0x807903e, 0x87ef7e8, 0x1)
            /home/beshoo/go-wapi/wa/whatsapp/main.go:182 +0x7d fp=0x9c13fac sp=0x9c13dcc pc=0x86064cd
    bitbucket.org/rockyOO7/wa-api/api.ScanQr.func1(0xd177aa00, 0x0, 0x97f0f90, 0x24, 0x19223580, 0x192235c0)
            /home/beshoo/go-wapi/wa/api/profile.go:24 +0x4d fp=0x9c13fd8 sp=0x9c13fac pc=0x861cdad
    
    

    Now let us see what is going on, on the main.go:164*

    func NewConn(proxyURLString *string) (*wa.Conn, error) {
            var err error
            var wac *wa.Conn
            var timeout = time.Duration(*timeoutInt) * time.Second
            log.Infof("TimeOutFlag: %v , TimeOut: %v", *timeoutInt,timeout)
    
            if proxyURLString != nil {
                    proxyURL, err := url.Parse(*proxyURLString)
                    if err != nil {
                            return nil, err
                    }
                    proxy := http.ProxyURL(proxyURL)
                    wac, err = wa.NewConnWithProxy(timeout, proxy)
            } else {
                    wac, err = wa.NewConn(timeout) //<========== main.go:164 
            }
            if err != nil {
                    wac.Disconnect()
                    return nil, err
            }
            return wac, nil
    }
    
    

    and profile.go:24

    func ScanQr(params profile.ScanQrParams) middleware.Responder {
            qr := make(chan string)
            errCh := make(chan error)
    
            go func() {
                    sessionID := params.SessionID.String()
                    handler, err := wa.Login(qr, params.ProxyURL, sessionID) // <<========= profile.go:24
                    if err != nil {
                            errCh <- err
                    }
                    wa.Connections[sessionID] = handler
            }()
    
            select {
            case err := <-errCh:
                    errText := err.Error()
                    return profile.NewScanQrDefault(500).WithPayload(&models.Error{
                            Code:    500,
                            Message: &errText,
                    })
            case qrText := <-qr:
                    return profile.NewScanQrOK().WithPayload(&models.QRCode{
                            Base64: qrText,
                    })
    
            }
    
    }
    
    

    and the Login function which triggered by the QR scaner profile.go:24

    
    func Login(qr chan string, proxyURL *strfmt.URI, sessionID string) (*WaHandler, error) {
    
            var proxyURLString *string
            if proxyURL != nil {
                    temp := proxyURL.String()
                    proxyURLString = &temp
            }
    
            var wac, err = NewConn(proxyURLString) // <=========== main.go:182 
            if err != nil {
                    return nil, err
            }
            .....................
    }
    
    

    Well, how can we handle suchtype of memory problem?

    opened by beshoo 17
  • Sending Media File (audio, video, document. image)

    Sending Media File (audio, video, document. image)

    Hello i have compiled some of the Type that a certain media file to be sent but I can't seem to figure out what are the other ones for example in this repo you can send image by using this code

    This is the code that was currently in the project

    image, err := os.Open("image.jpg") // the path of the image
    fmt.Println(image)
    if err != nil {
    	fmt.Fprintf(os.Stderr, "error reading file: %v\n", err)
    	os.Exit(1)
    }
    
    msg := whatsapp.ImageMessage{
    	Info: whatsapp.MessageInfo{
    		RemoteJid: "###########@s.whatsapp.net",
    	},
    	Type:    "image/jpeg", // jpeg needs to be change if you used different extension
    	Caption: "Hello Gopher!",
    	Content: image,
    }
    
    err = wac.Send(msg)
    if err != nil {
    	fmt.Fprintf(os.Stderr, "error sending file: %v\n", err)
    	os.Exit(1)
    }
    

    and these are the msg that I compiled in order to send different types of media files

    For mp4

    msg := whatsapp.VideoMessage{
    	Info: whatsapp.MessageInfo{
    		RemoteJid: "###########@s.whatsapp.net",
    	},
    	Type:    "video/mp4",
    	Caption: "Hello Gopher!",
    	Content: video, // the code os.Open("video.mp4")
    }
    

    For ogg

    msg := whatsapp.AudioMessage{
    	Info: whatsapp.MessageInfo{
    		RemoteJid: "###########@s.whatsapp.net",
    	},
    	Type:    "audio/ogg; codecs=opus",
    	Content: audio, // the code os.Open("audio.ogg")
    }
    

    Hope somehow this will help other go-whatsapp devs here

    My concern is that i can't seem to figure out what is the type when sending these kinds of file

    1. audio (mp3)
    2. documents (docx/doc/pdf) any possible document

    My code for mp3

    msg := whatsapp.AudioMessage{
    	Info: whatsapp.MessageInfo{
    		RemoteJid: "###########@s.whatsapp.net",
    	},
    	Type:    "audio/mp3; codecs=opus", // tried removing `; codecs=opus` but nothing happens
    	Content: audio, // os.Open("audio.mp3")
    }
    

    This is the error message that I'm receiving when sending mp3 error sending file: message sending responded with %!d(float64=400)

    My code for document

    msg := whatsapp.DocumentMessage{
    	Info: whatsapp.MessageInfo{
    		RemoteJid: "###########@s.whatsapp.net",
    	},
    	Type:      "document/docx",
    	Thumbnail: thumbnail,
    	Content:   document, // os.Open("document.docx")
    }
    

    I can send the document. The problem is that when viewing it on the receiver phone i can't seem to open it. I believe also that i have a docx/pdf opener on the receiver phone since I can open pdf and docx file from that phone that was downloaded from the internet.

    opened by highness28 16
  • > error logging in: error during login: error decoding login resp: json: cannot unmarshal array into Go value of type map[string]interface {}

    > error logging in: error during login: error decoding login resp: json: cannot unmarshal array into Go value of type map[string]interface {}

    error logging in: error during login: error decoding login resp: json: cannot unmarshal array into Go value of type map[string]interface {} Originally posted by @hrizal in https://github.com/Rhymen/go-whatsapp/issues/170#issuecomment-501131636

    Using the latest version of go-whatsapp. I am not getting qrcode on terminal with your recommened package for printing on console. Please guide me how I can get the qrcode I've write this in main.go file and calling this function in main function. The print message in go routing is printing in the console but qrcode is not. I also used the sync package for waiting but nothing is happen.

    func startConnection() {
    	wac, err := whatsapp.NewConn(20 * time.Second)
    	if err != nil {
    		panic(err)
    	}
    
    	qrChan := make(chan string)
    	// Goroutine is too print qrcode for session login
    	go func() {
    		fmt.Println("Print Qrcode on Terminal Started Execution")
    
    		terminal := qrcodeTerminal.New()
    		terminal.Get(<-qrChan).Print()
    	}()
    
    	sess, loginErr := wac.Login(qrChan)
    	if loginErr != nil {
    		fmt.Println("error during login: ", loginErr)
    		return
    	}
    	fmt.Println("Login Session", sess)
    
    }
    

    And this is my go.mod file

    module github.com/.../goWhatsappModule2022
    
    go 1.19
    
    require (
    	github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f
    	github.com/Rhymen/go-whatsapp v0.1.1
    )
    
    require (
    	github.com/golang/protobuf v1.3.0 // indirect
    	github.com/gorilla/websocket v1.4.1 // indirect
    	github.com/mattn/go-colorable v0.1.1 // indirect
    	github.com/mattn/go-isatty v0.0.5 // indirect
    	github.com/pkg/errors v0.8.1 // indirect
    	github.com/skip2/go-qrcode v0.0.0-20190110000554-dc11ecdae0a9 // indirect
    	golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 // indirect
    	golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 // indirect
    )
    
    opened by gurlivleenkainth2000 2
  • Use this API to send messages

    Use this API to send messages

    Some time ago I used this library, and we developed this project [ https://github.com/luannsr12/whapi/ ]. I'll make it public in case anyone is interested in fixing it and using it. It seems to me that this has been abandoned.

    A algum tempo atrás eu usava essa biblioteca, e desenvolvemos este projeto [ https://github.com/luannsr12/whapi/ ]. Vou deixar publico caso alguém se interesse em corrigi-lo e usar. Me parece que isso foi abandonado.

    opened by luannsr12 0
  • I created an api but it has an error

    I created an api but it has an error

    Guys, I have an api, which uses this library, it's open for modification. I can't fix a te timeout error when requesting qrcode. https://github.com/workstash/whapi

    opened by luannsr12 0
  • Error after scan QR Code

    Error after scan QR Code

    my client version is 2, 3147, 10

    wac.SetClientVersion(2, 3147, 10)
    

    Rresponse from whatsapp server

    {"status":200,"ref":"[email protected]+sJmQkMQmYpm+e1wRB8NOAwqZCLWwy0iBbJXdgyzk4mcaOZG9DhA==","ttl":20000,"update":false,"curr":"2.2208.7","time":1647229304655.0}
    

    Error message:

    interface conversion: interface {} is nil, not map[string]interface {}
    
    opened by yogawa 6
Releases(v0.1.1)
Owner
Lucas Engelke
Lucas Engelke
Whatsmeow is a Go library for the WhatsApp web multidevice API.

whatsmeow whatsmeow is a Go library for the WhatsApp web multidevice API. This was initially forked from go-whatsapp (MIT license), but large parts of

Tulir Asokan 667 Nov 24, 2022
WhatsApp Web API

go-whatsapp Package rhymen/go-whatsapp implements the WhatsApp Web API to provide a clean interface for developers. Big thanks to all contributors of

Lucas Engelke 1.8k Nov 21, 2022
Golang API for Whatsapp API MultiDevice version

Go Whatsapp API Multi Device Version Required Mac OS: brew install vips export C

Aldino Kemal 51 Nov 28, 2022
Simple RESTful API for WhatsApp in Golang (using the Whatsmeow multi device library)

WUZAPI WuzAPI is an implementation of @tulir/whatsmeow library as a simple RESTful API service with multiple device support and concurrent sessions. W

Nicolas 16 Nov 23, 2022
WhatsAppExpenseTracker - Way to track expenses using whatsapp group

WhatsAppExpenseTracker Way to track expenses using whatsapp group One needs to c

Randeep Sharma 0 Jan 4, 2022
Simple-Weather-API - Simple weather api app created using golang and Open Weather API key

Simple Weather API Simple weather api app created using golang and Open Weather

Siva Prakash 3 Feb 6, 2022
Go library for the Spotify Web API

go-spotify Simple Go library for the Spotify Web API Installation go get github.com/rapito/go-spotify/spotify How-to-use Get Requests import "fmt

Robert Peralta 46 Nov 18, 2022
Backgammon Web API. Sophisticed neural net based multi-ply evalution engine for Backgammon moves

Backgammon Web API. Sophisticed neural net based multi-ply evalution engine for Backgammon moves.

Rami 2 Sep 6, 2022
Awspowertoggle - Web UI and API for quickly starting and stopping AWS environments

aws-power-toggle web UI and API for quickly starting and stopping AWS environmen

null 1 Feb 23, 2022
Go library for accessing the MyAnimeList API: http://myanimelist.net/modules.php?go=api

go-myanimelist go-myanimelist is a Go client library for accessing the MyAnimeList API. Project Status The MyAnimeList API has been stable for years a

Stratos Neiros 33 Sep 28, 2022
Go client for the YNAB API. Unofficial. It covers 100% of the resources made available by the YNAB API.

YNAB API Go Library This is an UNOFFICIAL Go client for the YNAB API. It covers 100% of the resources made available by the YNAB API. Installation go

Bruno Souza 55 Oct 6, 2022
An API client for the Notion API implemented in Golang

An API client for the Notion API implemented in Golang

Anatoly Nosov 343 Nov 9, 2022
lambda-go-api-proxy makes it easy to port APIs written with Go frameworks such as Gin to AWS Lambda and Amazon API Gateway.

aws-lambda-go-api-proxy makes it easy to run Golang APIs written with frameworks such as Gin with AWS Lambda and Amazon API Gateway.

Amazon Web Services - Labs 735 Nov 23, 2022
A API scanner written in GOLANG to scan files recursively and look for API keys and IDs.

GO FIND APIS _____ ____ ______ _____ _ _ _____ _____ _____ _____ / ____|/ __ \ | ____|_ _| \ | | __ \ /\ | __ \_

Sreekanth Sasi 3 Oct 25, 2021
The NVD API is an unofficial Go wrapper around the NVD API.

NVD API The NVD API is an unofficial Go wrapper around the NVD API. Supports: CVE CPE How to use The following shows how to basically use the wrapper

Lucas TESSON 5 Nov 2, 2022
A Wrapper Client for Google Spreadsheet API (Sheets API)

Senmai A Wrapper Client for Google Spreadsheet API (Sheets API) PREPARATION Service Account and Key File Create a service account on Google Cloud Plat

ytnobody / satoshi azuma 0 Nov 5, 2021
💾 Wolke API is the API behind Wolke image storage and processing aswell as user management

?? Wolke API Wolke API is the API behind Wolke image storage and processing aswell as user management Deploying To deploy Wolke Bot you'll need podman

wolke.casa 1 Dec 21, 2021
Upcoming mobiles api (UpMob API)

upcoming_mobiles_api (UpMob API) UpMob API scraps 91mobiles.com to get devices i

null 0 Dec 21, 2021
Arweave-api - Arweave API implementation in golang

Arweave API Go implementation of the Arweave API Todo A list of endpoints that a

Joshua Lawson 1 Jan 16, 2022