> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hypersender.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Send WhatsApp Messages with Go

> Send WhatsApp messages from Golang with the Hypersender WhatsApp API: text, images, files, video, voice, polls, locations, and contact cards.

Before you start, install the SDK and set your credentials as described in the [Go SDK installation guide](https://docs.hypersender.com/v2/packages-and-sdks/go/installation.md). This page is the reference for the SDK methods and parameters. Building a Golang WhatsApp bot? See [WhatsApp Webhooks in Go](https://docs.hypersender.com/v2/packages-and-sdks/go/whatsapp/whatsapp-webhooks.md) to receive and answer incoming messages.

## Overview

The Send Message module provides comprehensive methods for sending various message types, managing interactions, and controlling chat on WhatsApp. Build engaging, feature-rich messaging experiences with safe sending options, link previews, and more.

> [!NOTE]
>
> Every method takes a `context.Context` first, then the chat ID and other required values, then an optional options struct (pass `nil` when you don't need it). It returns the parsed JSON response as a `hypersender.Result` (a `map[string]any`) and a `*hypersender.Error` (with `StatusCode`, `Message`, and `Body`) when the request fails. The examples assume `ctx` is a `context.Context`, such as `context.Background()` or your request's context.

## Text Methods

Send various types of content to engage your audience with multimedia and interactive elements.

### Safe Send Text Message

Send text with the Go SDK's `SendTextSafe` method. See the [endpoint reference](https://docs.hypersender.com/v2/api-reference/whatsapp/send-messages/send-text-safe.md) for its request fields and response flow.

> [tab] Basic usage
>
> ```go theme={null}
> client := hypersender.NewClient()
>
> res, err := client.WhatsApp.SendTextSafe(ctx, "20123456789@c.us", "Hello from the Go SDK!", nil)
> if err != nil {
>     log.Fatal(err)
> }
>
> fmt.Println(res["queued_request_uuid"])
> ```

> [tab] Parameters
>
> | Parameter | Type | Required | Description |
> | - | - | - | - |
> | chatID | string | yes | The WhatsApp number to send the message to |
> | text | string | yes | The message content to send |
> | opts.ReplyTo | string | no | The ID of the message to reply to |
> | opts.LinkPreview | bool | no | Whether to show a link preview |
> | opts.LinkPreviewHighQuality | bool | no | Whether to show a high-quality link preview |

### Send Text Message

Send plain text messages with link preview (optional) [(learn more)](https://docs.hypersender.com/v2/api-reference/whatsapp/send-messages/send-text.md)

> [!WARNING]
>
> We highly recommend using the [`send-text-safe`](https://docs.hypersender.com/v2/api-reference/whatsapp/send-messages/send-text-safe) endpoint for regular messaging operations to maintain a more natural communication pattern, and keep your whatsapp number safe from being blocked.

> [tab] Basic usage
>
> ```go theme={null}
> client := hypersender.NewClient()
>
> res, err := client.WhatsApp.SendText(ctx, "20123456789@c.us", "Hello from the Go SDK!", &hypersender.SendTextOptions{
>     LinkPreview: true,
> })
> if err != nil {
>     log.Fatal(err)
> }
>
> fmt.Println(res["queued_request_uuid"])
> ```

> [tab] Parameters
>
> | Parameter | Type | Required | Description |
> | - | - | - | - |
> | chatID | string | yes | The WhatsApp number to send the message to |
> | text | string | yes | The message content to send |
> | opts.ReplyTo | string | no | The ID of the message to reply to |
> | opts.LinkPreview | bool | no | Whether to show a link preview |
> | opts.LinkPreviewHighQuality | bool | no | Whether to show a high-quality link preview |

> [!NOTE]
>
> Media methods take a `hypersender.Media`: either `hypersender.MediaURL(url)` (a publicly reachable URL) or `hypersender.MediaFile(filename, reader)` (any `io.Reader`, such as an `*os.File`). With `MediaFile`, the SDK uploads the file as multipart form data.

### Send Image Message

Send images to WhatsApp users via URL or local file. [(learn more)](https://docs.hypersender.com/v2/api-reference/whatsapp/send-messages/send-image.md)

> [tab] Basic Usage
>
> ```go theme={null}
> client := hypersender.NewClient()
>
> _, err := client.WhatsApp.SendImage(ctx, "20123456789@c.us",
>     hypersender.MediaURL("https://example.com/image.jpeg"),
>     &hypersender.MediaOptions{
>         Filename: "image.jpeg",
>         MimeType: "image/jpeg",
>         Caption:  "Check out this image!",
>     })
> if err != nil {
>     log.Fatal(err)
> }
>
> // Or upload a local file
> f, err := os.Open("image.jpeg")
> if err != nil {
>     log.Fatal(err)
> }
> defer f.Close()
>
> _, err = client.WhatsApp.SendImage(ctx, "20123456789@c.us",
>     hypersender.MediaFile("image.jpeg", f),
>     &hypersender.MediaOptions{Caption: "Check out this image!"})
> if err != nil {
>     log.Fatal(err)
> }
> ```

> [tab] Parameters
>
> | Parameter | Type | Required | Description |
> | - | - | - | - |
> | chatID | string | yes | The WhatsApp number to send the message to |
> | image | hypersender.Media | yes | `MediaURL(url)` for the URL of the image, or `MediaFile(filename, reader)` to upload a local file |
> | opts.Filename | string | no | The name of the file to send |
> | opts.MimeType | string | no | The MIME type of the file to send |
> | opts.Caption | string | no | The caption for the image |
> | opts.ReplyTo | string | no | The ID of the message to reply to |

### Send Video Message

Send videos to WhatsApp users via URL or local file. [(learn more)](https://docs.hypersender.com/v2/api-reference/whatsapp/send-messages/send-video.md)

> [tab] Basic Usage
>
> ```go theme={null}
> client := hypersender.NewClient()
>
> _, err := client.WhatsApp.SendVideo(ctx, "20123456789@c.us",
>     hypersender.MediaURL("https://example.com/video.mp4"),
>     &hypersender.MediaOptions{Caption: "Check out this video!"})
> if err != nil {
>     log.Fatal(err)
> }
> ```

> [tab] Parameters
>
> | Parameter | Type | Required | Description |
> | - | - | - | - |
> | chatID | string | yes | The WhatsApp number to send the message to |
> | video | hypersender.Media | yes | `MediaURL(url)` for the URL of the video, or `MediaFile(filename, reader)` to upload a local file |
> | opts.Filename | string | no | The name of the file to send |
> | opts.MimeType | string | no | The MIME type of the file to send |
> | opts.Caption | string | no | The caption for the video |
> | opts.ReplyTo | string | no | The ID of the message to reply to |

> [!WARNING]
>
> You can send videos only in mp4 formats - so make sure the url contains the correct extension
>
> Max allowed file size is `20MB`.

### Send Voice Message

Send voice messages to WhatsApp users via URL or local file. [(learn more)](https://docs.hypersender.com/v2/api-reference/whatsapp/send-messages/send-a-voice-message.md)

> [tab] Basic Usage
>
> ```go theme={null}
> client := hypersender.NewClient()
>
> _, err := client.WhatsApp.SendVoice(ctx, "20123456789@c.us",
>     hypersender.MediaURL("https://example.com/audio.opus"),
>     &hypersender.VoiceOptions{Caption: "Check out this audio!"})
> if err != nil {
>     log.Fatal(err)
> }
> ```

> [tab] Parameters
>
> | Parameter | Type | Required | Description |
> | - | - | - | - |
> | chatID | string | yes | The WhatsApp number to send the message to |
> | voice | hypersender.Media | yes | `MediaURL(url)` for the URL of the audio, or `MediaFile(filename, reader)` to upload a local file |
> | opts.Caption | string | no | The caption for the audio |
> | opts.ReplyTo | string | no | The ID of the message to reply to |

### Send Location Message

Send location messages to WhatsApp users. [(learn more)](https://docs.hypersender.com/v2/api-reference/whatsapp/send-messages/send-location.md)

> [tab] Basic Usage
>
> ```go theme={null}
> client := hypersender.NewClient()
>
> _, err := client.WhatsApp.SendLocation(ctx, "20123456789@c.us", 37.7749, -122.4194,
>     &hypersender.SendLocationOptions{Title: "San Francisco"})
> if err != nil {
>     log.Fatal(err)
> }
> ```

> [tab] Parameters
>
> | Parameter | Type | Required | Description |
> | - | - | - | - |
> | chatID | string | yes | The WhatsApp number to send the message to |
> | latitude | float64 | yes | The latitude of the location to send |
> | longitude | float64 | yes | The longitude of the location to send |
> | opts.Title | string | no | The title of the location |
> | opts.ReplyTo | string | no | The ID of the message to reply to |

### Send Poll Message

Send poll messages to WhatsApp users. [(learn more)](https://docs.hypersender.com/v2/api-reference/whatsapp/send-messages/send-poll.md)

> [tab] Basic Usage
>
> ```go theme={null}
> client := hypersender.NewClient()
>
> _, err := client.WhatsApp.SendPoll(ctx, "20123456789@c.us", "Sample Poll",
>     []string{"Option 1", "Option 2", "Option 3"},
>     &hypersender.SendPollOptions{MultipleAnswers: true})
> if err != nil {
>     log.Fatal(err)
> }
> ```

> [tab] Parameters
>
> | Parameter | Type | Required | Description |
> | - | - | - | - |
> | chatID | string | yes | The WhatsApp number to send the message to |
> | name | string | yes | The poll question |
> | options | \[]string | yes | The poll options |
> | opts.MultipleAnswers | bool | no | Whether users can pick more than one option (default: `false`) |
> | opts.ReplyTo | string | no | The ID of the message to reply to |

### Send Link Custom Preview

Send a text message with a custom link preview. [(learn more)](https://docs.hypersender.com/v2/api-reference/whatsapp/send-messages/send-link-custom-preview.md)

> [tab] Basic Usage
>
> ```go theme={null}
> client := hypersender.NewClient()
>
> _, err := client.WhatsApp.SendLinkCustomPreview(ctx, "20123456789@c.us",
>     "Check this out: https://example.com",
>     hypersender.LinkPreview{
>         Title:       "Example Title",
>         Description: "A short description for the preview card",
>         URL:         "https://example.com",
>         Image:       hypersender.MediaURL("https://example.com/image.jpg"),
>     },
>     &hypersender.SendLinkCustomPreviewOptions{HighQuality: true})
> if err != nil {
>     log.Fatal(err)
> }
> ```

> [tab] Parameters
>
> | Parameter | Type | Required | Description |
> | - | - | - | - |
> | chatID | string | yes | The WhatsApp chat ID to send the message to |
> | text | string | yes | The message text (can include a link) |
> | preview\.Title | string | yes | Title to display in the link preview |
> | preview\.Description | string | yes | Description to display in the link preview |
> | preview\.URL | string | yes | Link URL for the preview card |
> | preview\.Image | hypersender.Media | no | Optional. `MediaURL(url)` for a direct URL to the preview image, or `MediaFile(filename, reader)` to upload a local preview image |
> | opts.ReplyTo | string | no | Message ID to reply to |
> | opts.HighQuality | bool | no | Whether to use high-quality preview images |

### Send File Message

Send any file type via URL or local file. [(learn more)](https://docs.hypersender.com/v2/api-reference/whatsapp/send-messages/send-file.md)

> [tab] Basic Usage
>
> ```go theme={null}
> client := hypersender.NewClient()
>
> _, err := client.WhatsApp.SendFile(ctx, "20123456789@c.us",
>     hypersender.MediaURL("https://example.com/files/report.pdf"),
>     &hypersender.MediaOptions{
>         Filename: "report.pdf",
>         MimeType: "application/pdf",
>         Caption:  "Monthly report",
>     })
> if err != nil {
>     log.Fatal(err)
> }
>
> // Or upload a local file
> f, err := os.Open("report.pdf")
> if err != nil {
>     log.Fatal(err)
> }
> defer f.Close()
>
> _, err = client.WhatsApp.SendFile(ctx, "20123456789@c.us",
>     hypersender.MediaFile("report.pdf", f),
>     &hypersender.MediaOptions{Caption: "Monthly report"})
> if err != nil {
>     log.Fatal(err)
> }
> ```

> [tab] Parameters
>
> | Parameter | Type | Required | Description |
> | - | - | - | - |
> | chatID | string | yes | The WhatsApp chat ID to send the file to |
> | file | hypersender.Media | yes | `MediaURL(url)` for a direct URL of the file, or `MediaFile(filename, reader)` to upload a local file |
> | opts.Filename | string | no | File name to display to the recipient |
> | opts.MimeType | string | no | MIME type of the file |
> | opts.Caption | string | no | Optional caption for the file |
> | opts.ReplyTo | string | no | Message ID to reply to |

### Send Contact Card

Send contact cards (vCard) to WhatsApp users. [(learn more)](https://docs.hypersender.com/v2/api-reference/whatsapp/send-messages/send-contact-card.md)

> [tab] Basic Usage
>
> ```go theme={null}
> client := hypersender.NewClient()
>
> _, err := client.WhatsApp.SendContactCard(ctx, "20123456789@c.us", []hypersender.ContactCard{
>     {
>         VCard:        "BEGIN:VCARD\nVERSION:3.0\nFN:John Doe\nORG:Acme Inc\nTEL;type=CELL:+12025550123\nEND:VCARD",
>         FullName:     "John Doe",
>         Organization: "Acme Inc",
>         PhoneNumber:  "12025550123",
>         WhatsAppID:   "12025550123@c.us",
>     },
> })
> if err != nil {
>     log.Fatal(err)
> }
> ```

> [tab] Parameters
>
> | Parameter | Type | Required | Description |
> | - | - | - | - |
> | chatID | string | yes | The WhatsApp chat ID to send the contact card to |
> | contacts | \[]hypersender.ContactCard | yes | List of contact cards (see note below) |

> [!NOTE]
>
> Each `hypersender.ContactCard` supports the API's fields: `VCard`, `FullName`, `Organization`, `PhoneNumber`, `WhatsAppID`.
>
> You can send one or multiple contacts in a single message by including multiple items in the `contacts` slice.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.