Whatsapp API send message GO (Golang)

How to Send a Message by WhatsApp API using GO

Whapi.Cloud provides a gateway to interact with customers through WhatsApp. This tutorial will help you learn how to send messages through the WhatsApp API using the Go Programming Language.

Getting Started

After registering on our platform, go to the channel page, which will be immediately available to you.

You will now need to link any number to the channel. To do this, use the QR code that is displayed inside the channel.

Open your WhatsApp mobile app, navigate to Settings -> Linked devices -> Link a device -> Scan QR code

Our service enables you to interact with the API without the need for an uninterrupted phone connection. Operate WhatsApp on up to four paired devices and one mobile device concurrently.

Now save the generated API-Key token on channel page:

Grab your token

How to Send WhatsApp API Message using GO, Example

To send a text message, you need to make a request to:

POST https://gate.whapi.cloud/messages/text

Test requests and sample code snippets

Here's how you can dispatch a WhatsApp message using Golang:

package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://gate.whapi.cloud/messages/text"

	payload := strings.NewReader("{\"typing_time\":10,\"to\":\"14409416972\",\"body\":\"Hello!\"}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("accept", "application/json")
	req.Header.Add("content-type", "application/json")
	req.Header.Add("authorization", "Bearer iNdBBvVS4sbBmwcPwcX1pzBDChVo2bcs")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}

The parameters are as follows:

  • to: The recipientโ€™s WhatsApp number in international format (e.g., 14409416972) or chatID for contact or group (e.g [email protected] or [email protected]).

  • body: The content of the message.

  • typing_time: The time in seconds when it is displayed that you are typing a message. Not a required parameter.

If you have any inquiries or would like to share your experiences with us, please feel free to reach out.

Get Started Free


Send Media Message

Additional endpoint for easy send media-file as message. Use request body as file and inpath parameters for send parameters. Media message can be one of the following types:

Send Image

Send Document

Send Audio

Send Voice

You can Send a ppt audio recording to the phone number or group, But WhatsApp is sensitive to this extension, you need to be in OGG format and the codecs should be the opus. Our API has an automatic video and audio converter for the necessary codecs compatible with WhatsApp. For more information, you can check out this article.

Send Video

Send GIF

Send Contact

Send Contact List

Send Location

Send Sticker

Last updated

Was this helpful?