[go: up one dir, main page]

Skip to content

How to send a file by uploading from the disk#

Installation#

Make sure that you have Go installed with a version of 1.20 or newer

go version

Create a module for your project if you didn't:

go mod init ModuleName

Installation:

go get github.com/green-api/whatsapp-api-client-golang-v2

Import#

import (
    greenapi "github.com/green-api/whatsapp-api-client-golang-v2"
)

Examples#

How to initialize an object#

GreenAPI := greenapi.GreenAPI{
        APIURL:           "https://api.green-api.com",
        MediaURL:         "https://media.green-api.com",
        IDInstance:       "1101000001",
        APITokenInstance: "d75b3a66374942c5b3c019c698abc2067e151558acbd412345",
    }

Note that keys can be obtained from environment variables:

IDInstance := os.Getenv("ID_INSTANCE")
APITokenInstance := os.Getenv("API_TOKEN_INSTANCE")

How to send a file by uploading from the disk#

To send a file, you need to give the path to the file.

Link to example: sendFileByUpload/main.go.

response, _ := GreenAPI.Sending().SendFileByUpload(
        "11001234567@c.us",
        "C:/Users/user/Desktop/Pictures/image.png",
        "image.png",
    )

Running the application#

go run main.go

Running the application#

go run main.go

List of examples#

Description Link to example
How to send a message sendMessage/main.go
How to send a file by uploading from the disk sendFileByUpload/main.go
How to send a file by URL sendFileByUrl/main.go
How to upload a file to an external drive uploadFile/main.go
How to send a poll sendPoll/main.go
How to check if there is a WhatsApp account on the phone number checkWhatsapp/main.go
How to set instance settings setSettings/main.go
How to create a group createGroup/main.go
How to send a text status sendTextStatus/main.go
How to receive an incoming notification receiveNotification/main.go
How to get all instances of the account partnerMethods/getInstances/main.go
How to create an instance partnerMethods/createInstance/main.go
How to delete an instance partnerMethods/deleteInstanceAccount/main.go