> ## 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 SMS with Go: Android SMS Gateway

> Send, schedule, list, and delete SMS from Golang through your own Android phone and SIM card. The Hypersender SMS API works as an Android SMS gateway.

## Overview

Use the Hypersender Go SDK to send SMS through the Hypersender SMS app on your Android phone, list your messages, and delete them. Set `HYPERSENDER_SMS_API_KEY` and `HYPERSENDER_SMS_INSTANCE_ID` first, as described in [Installation](https://docs.hypersender.com/v2/packages-and-sdks/go/installation.md).

Every method returns the parsed JSON response body as a `hypersender.Result` (a `map[string]any`). If the API answers with an error, the method returns a `*hypersender.Error` with the `StatusCode`, `Message`, and `Body` of the response; check for it with `errors.As`. The examples assume `ctx` is a `context.Context`, such as `context.Background()`.

> [!NOTE]
>
> If the instance is offline, the API answers `403`. If the phone has no push registration, it answers `422` with the code `PHONE_PUSH_NOT_REGISTERED`. See the [SMS heartbeats guide](https://docs.hypersender.com/v2/hypersender/overview/sms/sms-heartbeats-guide.md) and [How it works](https://docs.hypersender.com/v2/hypersender/overview/sms/how-it-works.md).

## Methods

### Send SMS Message

Queue an SMS to be sent by your Android phone. [(learn more)](https://docs.hypersender.com/v2/api-reference/sms/messages/send-message.md)

> [tab] Basic Usage
>
> ```go theme={null}
> client := hypersender.NewClient()
>
> res, err := client.SMS.SendMessage(ctx, "+201001234567", "Hello, this is a test message!",
>     &hypersender.SendSMSOptions{
>         RequestID: "order-1042-confirmation",
>         // Optional fields
>         // ScheduleSendAt:           "2025-01-01 12:00:00",
>         // MaxSendAttempts:          3,
>         // MessageExpirationSeconds: 300,
>     })
> if err != nil {
>     log.Fatal(err)
> }
>
> data, _ := res["data"].(map[string]any)
> fmt.Println(data["id"], data["status"])
> ```

> [tab] Parameters
>
> | Parameter | Type | Required | Description |
> | - | - | - | - |
> | to | string | yes | The recipient's number, preferably in international format (for example `+201001234567`). Spaces, dashes, dots, and parentheses are removed. |
> | content | string | yes | The text of the SMS. Up to 1600 characters. |
> | opts.RequestID | string | no | Your own ID for this message, up to 255 characters. Sending again with the same `RequestID`, number, and text returns the first message with `200` instead of sending a second SMS. If you leave it out, a UUID is generated. |
> | opts.ScheduleSendAt | string | no | Send later, in `Y-m-d H:i:s` format. Must be in the future and less than 3 days away. |
> | opts.MaxSendAttempts | int | no | How many times to try sending if it fails, from 1 to 15. |
> | opts.MessageExpirationSeconds | int | no | Seconds the message stays valid. If the phone has not sent it by then, it is marked expired and never sent. Minimum 60. Useful for OTP codes. |

### List Messages

Get a paginated list of messages, with filters. [(learn more)](https://docs.hypersender.com/v2/api-reference/sms/messages/index-messages.md)

> [tab] Basic Usage
>
> ```go theme={null}
> client := hypersender.NewClient()
>
> res, err := client.SMS.ListMessages(ctx, nil)
> if err != nil {
>     log.Fatal(err)
> }
>
> messages, _ := res["data"].([]any)
> for _, item := range messages {
>     message, _ := item.(map[string]any)
>     fmt.Println(message["id"], message["status"], message["content"])
> }
> ```

> [tab] Basic Usage with Filters
>
> ```go theme={null}
> client := hypersender.NewClient()
>
> res, err := client.SMS.ListMessages(ctx, &hypersender.ListOptions{
>     PerPage: 50,
>     Page:    2,
>     Sort:    "-updated_at",
>     Include: "messageThread",
>     Filters: map[string]string{
>         "request_id": "order-1042-confirmation",
>         "status":     "delivered",
>         // other filters (check Parameters tab)
>     },
> })
> if err != nil {
>     log.Fatal(err)
> }
>
> meta, _ := res["meta"].(map[string]any)
> fmt.Println(meta["current_page"], meta["last_page"], meta["total"])
> ```

> [tab] Parameters
>
> All fields are optional; pass `nil` for none. Each key in `Filters` is sent as `filter[key]`.
>
> | Parameter | Type | Description |
> | - | - | - |
> | PerPage | int | Items per page (max 50) |
> | Page | int | Page number |
> | Sort | string | `created_at`, `updated_at`, `delivered_at`, `received_at`, `expired_at`, `failed_at`, or `schedule_send_at`. Add `-` for descending, for example `-updated_at`. |
> | Include | string | `messageThread` to add the thread to each message, `phone` to add the phone, or both separated by a comma |
> | Filters\["request\_id"] | string | Exact `request_id` you sent |
> | Filters\["message\_thread\_id"] | string | Exact thread ID |
> | Filters\["from\_phone\_number"] | string | Exact sender number |
> | Filters\["to\_phone\_number"] | string | Exact recipient number |
> | Filters\["content"] | string | Part of the message text |
> | Filters\["status"] | string | `pending`, `scheduled`, `sending`, `sent`, `delivered`, `failed`, `expired`, `received`, or `deleted` |
> | Filters\["type"] | string | `sent` (outgoing) or `received` (incoming) |
> | Filters\["delivered\_at"] | string | Date or range. A range is two dates separated by a comma, for example `2025-01-01 00:00:00,2025-01-01 23:59:59`. |
> | Filters\["received\_at"] | string | Date or range |
> | Filters\["expired\_at"] | string | Date or range |
> | Filters\["failed\_at"] | string | Date or range |
> | Filters\["schedule\_send\_at"] | string | Date or range |
> | Filters\["created\_at"] | string | Date or range |
> | Filters\["updated\_at"] | string | Date or range |

### Delete Message

Delete a message by its ID. [(learn more)](https://docs.hypersender.com/v2/api-reference/sms/messages/delete-sms-message.md)

> [tab] Basic Usage
>
> ```go theme={null}
> client := hypersender.NewClient()
>
> if _, err := client.SMS.DeleteMessage(ctx, "9e03fc6b-ce90-4399-a472-6b029857e15b"); err != nil {
>     log.Fatal(err)
> }
> ```

> [tab] Parameters
>
> | Parameter | Type | Required | Description |
> | - | - | - | - |
> | messageID | string | yes | The ID of the message to delete |


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