Skip to main content

DeBox Bot Go SDK Guide

Source repository:

1. SDK capabilities

The SDK provides:

  • Bot init: NewBotAPI(apiKey, apiSecret)
  • Message sending: bot.Send(...)
  • Long polling updates: GetUpdates / GetUpdatesChan
  • Inline keyboard callbacks: InlineKeyboardMarkup + CallbackQuery
  • Message editing: NewEditMessageText + bot.Send(...)

Webhook is split into a standalone guide:

2. Receiving mode notes

This guide uses Long Polling. Before running it, clear any Webhook URL configured in BotMother; otherwise Long Polling is not a valid receiving path. For mode selection and switching, see the DeBox Bot Development Overview. For Webhook implementation, see DeBox Bot Go SDK Webhook.


3. Long polling usage (detailed SDK workflow)

3.1 Install

go get github.com/debox-pro/debox-chat-go-sdk

3.2 Credentials

The Bot details page in BotMother displays App Key and App Secret. Map them to the SDK parameters as follows:

  • App Key -> API_KEY (required)
  • App Secret -> API_SECRET (recommended)

See Credentials in the DeBox Bot Development Overview for the complete mapping and storage rules.

3.3 Init + first message

package main

import (
"log"

boxbotapi "github.com/debox-pro/debox-chat-go-sdk/boxbotapi"
)

func main() {
bot, err := boxbotapi.NewBotAPI("YOUR_APP_KEY", "YOUR_API_SECRET")
if err != nil {
log.Fatalf("init bot failed: %v", err)
}

msg := boxbotapi.NewMessage("cc0onr82", "group", "Hello from Go SDK")
msg.ParseMode = boxbotapi.ModeRichText

sent, err := bot.Send(msg)
if err != nil {
log.Fatalf("send failed: %v", err)
}
log.Printf("sent message_id=%s", sent.MessageID)
}
package main

import (
"context"
"log"

boxbotapi "github.com/debox-pro/debox-chat-go-sdk/boxbotapi"
)

func main() {
bot, err := boxbotapi.NewBotAPI("YOUR_APP_KEY", "YOUR_API_SECRET")
if err != nil {
log.Fatal(err)
}

boxbotapi.MessageListener = true

cfg := boxbotapi.NewUpdate(0)
cfg.Timeout = 30

ctx := context.Background()
updates := bot.GetUpdatesChan(cfg)

for {
select {
case <-ctx.Done():
bot.StopReceivingUpdates()
return
case upd := <-updates:
if upd.Message != nil {
log.Printf("from=%s chat=%s text=%s", upd.Message.From.UserId, upd.Message.Chat.ID, upd.Message.Text)
}
if upd.CallbackQuery != nil {
log.Printf("callback=%s", upd.CallbackQuery.Data)
}
}
}
}

3.5 Manual polling via GetUpdates

cfg := boxbotapi.NewUpdate(0)
cfg.Timeout = 30

updates, err := bot.GetUpdates(cfg)
if err != nil {
log.Printf("get updates failed: %v", err)
return
}
for _, upd := range updates {
if upd.Message != nil {
log.Println(upd.Message.Text)
}
}

3.6 Send multiple message types

m1 := boxbotapi.NewMessage(chatID, chatType, "*bold* _italic_")
m1.ParseMode = boxbotapi.ModeMarkdownV2
_, _ = bot.Send(m1)

m2 := boxbotapi.NewMessage(chatID, chatType, "<b>Hello</b> <a href=\"https://docs.debox.pro\">docs</a>")
m2.ParseMode = boxbotapi.ModeHTML
_, _ = bot.Send(m2)

m3 := boxbotapi.NewMessage(chatID, chatType, "https://example.com/a.png")
m3.ParseMode = boxbotapi.ModeImage
_, _ = bot.Send(m3)

Available parse modes:

  • boxbotapi.ModeRichText
  • boxbotapi.ModeText
  • boxbotapi.ModeMarkdown
  • boxbotapi.ModeMarkdownV2
  • boxbotapi.ModeHTML
  • boxbotapi.ModeImage
  • boxbotapi.ModeVideo
  • boxbotapi.ModeFile

For chat_id, chat_type, parse_mode, content, media URL, and length rules, see the OpenAPI message fields.

3.7 Inline keyboard + callback

markup := boxbotapi.NewInlineKeyboardMarkup(
boxbotapi.NewInlineKeyboardRow(
boxbotapi.NewInlineKeyboardButtonData("Details", "detail"),
boxbotapi.NewInlineKeyboardButtonURL("Open site", "https://debox.pro"),
),
)

msg := boxbotapi.NewMessage("cc0onr82", "group", "Pick one")
msg.ParseMode = boxbotapi.ModeRichText
msg.ReplyMarkup = markup
_, _ = bot.Send(msg)

Callback handler:

if upd.CallbackQuery != nil {
data := upd.CallbackQuery.Data
_ = data
}

3.8 Edit message

edit := boxbotapi.NewEditMessageText("cc0onr82", "group", "MESSAGE_ID", "edited text")
edit.ParseMode = boxbotapi.ModeRichText
_, err := bot.Send(edit)
if err != nil {
log.Printf("edit failed: %v", err)
}