Documentation
¶
Index ¶
- type Bot
- func (b *Bot) Connected() bool
- func (b *Bot) HandleWebhook(body []byte)
- func (b *Bot) OnCallbackQuery(h func(*CallbackQuery))
- func (b *Bot) OnConnected(h func())
- func (b *Bot) OnDisconnected(h func(code int, reason string))
- func (b *Bot) OnError(h func(error))
- func (b *Bot) OnMessage(h func(*Message))
- func (b *Bot) Start()
- func (b *Bot) Stop()
- type BotOption
- type BotProfile
- type BotProfileResource
- type CallbackQuery
- type CarouselCard
- type Chat
- type ChatType
- type ChatsResource
- type ChatsResult
- type DeleteMessageParams
- type DeleteResult
- type EditMessageParams
- type EditMessageResult
- type ErrorCode
- type FileInput
- type GetChatsParams
- type InlineKeyboard
- type InlineKeyboardButton
- type KappelaError
- type Message
- type MessageStatus
- type MessageType
- type MessagesResource
- func (r *MessagesResource) Delete(ctx context.Context, params DeleteMessageParams) (*DeleteResult, error)
- func (r *MessagesResource) Edit(ctx context.Context, params EditMessageParams) (*EditMessageResult, error)
- func (r *MessagesResource) Send(ctx context.Context, params SendMessageParams) (*SendResult, error)
- func (r *MessagesResource) SendAudio(ctx context.Context, params SendMediaParams) (*SendMediaResult, error)
- func (r *MessagesResource) SendCarousel(ctx context.Context, params SendCarouselParams) (*SendCarouselResult, error)
- func (r *MessagesResource) SendDocument(ctx context.Context, params SendMediaParams) (*SendMediaResult, error)
- func (r *MessagesResource) SendPhoto(ctx context.Context, params SendMediaParams) (*SendMediaResult, error)
- func (r *MessagesResource) SendTyping(ctx context.Context, params SendTypingParams) (*TypingResult, error)
- func (r *MessagesResource) SendVideo(ctx context.Context, params SendMediaParams) (*SendMediaResult, error)
- type Participant
- type PrivacySetting
- type ReplyKeyboard
- type ReplySnapshot
- type ScrollKeyboard
- type SendCarouselParams
- type SendCarouselResult
- type SendMediaParams
- type SendMediaResult
- type SendMessageParams
- type SendResult
- type SendTypingParams
- type SetWebhookParams
- type TypingResult
- type User
- func (u *User) Connected() bool
- func (u *User) HandleWebhook(body []byte)
- func (u *User) OnCallbackQuery(h func(*CallbackQuery))
- func (u *User) OnConnected(h func())
- func (u *User) OnDisconnected(h func(code int, reason string))
- func (u *User) OnError(h func(error))
- func (u *User) OnMessage(h func(*Message))
- func (u *User) Start()
- func (u *User) Stop()
- type UserOption
- type UserProfile
- type UserProfileResource
- type WebhookDeleteResult
- type WebhookInfo
- type WebhookSetResult
- type WebhooksResource
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bot ¶
type Bot struct {
// Messages provides methods to send and manage messages.
Messages *MessagesResource
// Chats provides methods to list and iterate over chats.
Chats *ChatsResource
// Webhooks provides methods to manage webhooks.
Webhooks *WebhooksResource
// Profile provides access to the bot's own profile.
Profile *BotProfileResource
// contains filtered or unexported fields
}
Bot is the Kappela bot client. Authenticate with a token from BotMother.
Example:
bot := kappelas.NewBot("YOUR_BOT_TOKEN")
bot.OnMessage(func(msg *kappelas.Message) {
bot.Messages.Send(ctx, kappelas.SendMessageParams{
ChatID: msg.ChatID,
Text: "Echo: " + *msg.Text,
})
})
bot.OnCallbackQuery(func(cb *kappelas.CallbackQuery) {
bot.Messages.Send(ctx, kappelas.SendMessageParams{
ChatID: cb.ChatID,
Text: "Button clicked: " + cb.CallbackData,
})
})
bot.Start()
select {} // keep alive
func (*Bot) HandleWebhook ¶
HandleWebhook processes a webhook payload sent by Kappela to your server. Call this inside your HTTP handler and respond 200 immediately. The same OnMessage and OnCallbackQuery handlers fire for both WS and webhook events.
Example (net/http):
http.HandleFunc("/kappela-webhook", func(w http.ResponseWriter, r *http.Request) {
body, _ := io.ReadAll(r.Body)
bot.HandleWebhook(body)
w.WriteHeader(http.StatusOK)
})
func (*Bot) OnCallbackQuery ¶
func (b *Bot) OnCallbackQuery(h func(*CallbackQuery))
OnCallbackQuery registers a handler called when a user clicks an inline button.
func (*Bot) OnConnected ¶
func (b *Bot) OnConnected(h func())
OnConnected registers a handler called when the WebSocket connects (or reconnects).
func (*Bot) OnDisconnected ¶
OnDisconnected registers a handler called when the WebSocket disconnects.
type BotOption ¶
type BotOption func(*botConfig)
BotOption configures a Bot.
func WithBaseURL ¶
WithBaseURL overrides the API base URL (default: https://api.kappelas.com).
func WithMaxRetries ¶
WithMaxRetries sets the maximum number of HTTP retry attempts (default: 2).
func WithTimeout ¶
WithTimeout sets the HTTP request timeout (default: 30s).
func WithWSMaxRetries ¶
WithWSMaxRetries sets the maximum WebSocket reconnect attempts (default: 12).
type BotProfile ¶
type BotProfile struct {
UserID string `json:"user_id"`
Username string `json:"username"`
IsBot bool `json:"is_bot"`
About string `json:"about"`
Description string `json:"description"`
AvatarURL *string `json:"avatar_url"`
}
BotProfile is the profile returned for a bot account.
type BotProfileResource ¶
type BotProfileResource struct {
// contains filtered or unexported fields
}
BotProfileResource provides access to the bot's own profile.
func (*BotProfileResource) Get ¶
func (r *BotProfileResource) Get(ctx context.Context) (*BotProfile, error)
Get returns the bot's own profile.
type CallbackQuery ¶
type CallbackQuery struct {
ChatID int64 `json:"chat_id"`
SenderID string `json:"sender_id"`
SenderNom *string `json:"sender_nom"`
SenderUsername *string `json:"sender_username"`
CallbackData string `json:"callback_data"`
SentAt int64 `json:"sent_at"`
}
CallbackQuery is fired when a user clicks an inline button.
type CarouselCard ¶
type CarouselCard struct {
ID string `json:"id"`
Title string `json:"title"`
Subtitle *string `json:"subtitle,omitempty"`
ImageURL *string `json:"image_url,omitempty"`
ButtonText *string `json:"button_text,omitempty"`
}
CarouselCard is a single card inside a carousel message.
type Chat ¶
type Chat struct {
ChatID int64 `json:"chat_id"`
ID int64 `json:"id"`
Type ChatType `json:"type"`
Title *string `json:"title"`
Participants []Participant `json:"participants"`
LastMessageAt *string `json:"last_message_at"`
CreatedAt string `json:"created_at"`
CreatedBy string `json:"created_by"`
IsPinned bool `json:"is_pinned"`
IsPremium bool `json:"is_premium"`
IsPublic bool `json:"is_public"`
OnlyAdminsCanWrite bool `json:"only_admins_can_write"`
Labels []string `json:"labels"`
Description *string `json:"description"`
AvatarURL *string `json:"avatar_url"`
}
Chat represents a Kappela conversation.
type ChatsResource ¶
type ChatsResource struct {
// contains filtered or unexported fields
}
ChatsResource provides methods to access chats.
func (*ChatsResource) Iterate ¶
Iterate calls fn for every chat, handling pagination automatically. Return false from fn to stop iteration early.
Example:
err := bot.Chats.Iterate(ctx, 50, func(chat *kappelas.Chat) bool {
fmt.Println(chat.ChatID)
return true // continue
})
func (*ChatsResource) List ¶
func (r *ChatsResource) List(ctx context.Context, params GetChatsParams) (ChatsResult, error)
List returns a paginated list of chats accessible to this bot or user.
type ChatsResult ¶
ChatsResult is the paginated response from the list chats endpoint.
type DeleteMessageParams ¶
type DeleteMessageParams struct {
ChatID int64 `json:"chat_id"`
MessageID int64 `json:"message_id"`
}
DeleteMessageParams holds the parameters for deleting a message.
type DeleteResult ¶
type DeleteResult struct {
Deleted bool `json:"deleted"`
}
DeleteResult is returned by the deleteMessage endpoint.
type EditMessageParams ¶
type EditMessageParams struct {
ChatID int64 `json:"chat_id"`
MessageID int64 `json:"message_id"`
NewText string `json:"new_text,omitempty"`
NewExtraData json.RawMessage `json:"new_extra_data,omitempty"`
}
EditMessageParams holds the parameters for editing a message.
type EditMessageResult ¶
EditMessageResult is returned after editing a message.
type ErrorCode ¶
type ErrorCode string
ErrorCode is the machine-readable error code returned by the Kappela API.
const ( ErrCodeForbidden ErrorCode = "FORBIDDEN" ErrCodeNotFound ErrorCode = "NOT_FOUND" ErrCodeInvalidField ErrorCode = "INVALID_FIELD" ErrCodeMissingField ErrorCode = "MISSING_FIELD" ErrCodeInternalError ErrorCode = "INTERNAL_ERROR" ErrCodeConflict ErrorCode = "CONFLICT" ErrCodeMethodNotAllowed ErrorCode = "METHOD_NOT_ALLOWED" ErrCodeInvalidPath ErrorCode = "INVALID_PATH" ErrCodeUpstreamError ErrorCode = "UPSTREAM_ERROR" )
type GetChatsParams ¶
GetChatsParams holds the parameters for listing chats.
type InlineKeyboard ¶
type InlineKeyboard struct {
InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard"`
}
InlineKeyboard renders buttons attached to a message.
type InlineKeyboardButton ¶
type InlineKeyboardButton struct {
Text string `json:"text"`
CallbackData *string `json:"callback_data,omitempty"`
URL *string `json:"url,omitempty"`
}
InlineKeyboardButton is a button inside an inline keyboard.
type KappelaError ¶
type KappelaError struct {
// Message is the human-readable error description from the API.
Message string
// Code is the machine-readable error code.
Code ErrorCode
// Status is the HTTP status code.
Status int
// RequestID can be quoted when contacting support.
RequestID string
}
KappelaError is returned when the Kappela API responds with an error.
func (*KappelaError) Error ¶
func (e *KappelaError) Error() string
type Message ¶
type Message struct {
ID int64 `json:"id"`
ChatID int64 `json:"chat_id"`
SenderID *string `json:"sender_id"`
Type MessageType `json:"type"`
Text *string `json:"text"`
MediaID *string `json:"media_id"`
ExtraData json.RawMessage `json:"extra_data"`
Status MessageStatus `json:"status"`
EditedAt *int64 `json:"edited_at"`
DeletedAt *int64 `json:"deleted_at"`
CreatedAt int64 `json:"created_at"`
ReplyToID *int64 `json:"reply_to_id"`
ReplyToSnapshot *ReplySnapshot `json:"reply_to_snapshot"`
Mentions []string `json:"mentions"`
ForwardedFrom json.RawMessage `json:"forwarded_from"`
ExpiresAt *int64 `json:"expires_at"`
SenderName *string `json:"sender_name,omitempty"`
SenderAvatarURL *string `json:"sender_avatar_url,omitempty"`
ClientMsgID string `json:"client_msg_id,omitempty"`
Width *int `json:"width,omitempty"`
Height *int `json:"height,omitempty"`
}
Message represents a Kappela chat message.
type MessageStatus ¶
type MessageStatus string
MessageStatus is the delivery status of a message.
const ( MessageStatusSent MessageStatus = "sent" MessageStatusDelivered MessageStatus = "delivered" MessageStatusRead MessageStatus = "read" )
type MessageType ¶
type MessageType string
MessageType is the content type of a message.
const ( MessageTypeText MessageType = "text" MessageTypeImage MessageType = "image" MessageTypeVideo MessageType = "video" MessageTypeAudio MessageType = "audio" MessageTypeDocument MessageType = "document" MessageTypeSystem MessageType = "system" MessageTypePoll MessageType = "poll" MessageTypeSticker MessageType = "sticker" MessageTypeLocation MessageType = "location" MessageTypeContact MessageType = "contact" )
type MessagesResource ¶
type MessagesResource struct {
// contains filtered or unexported fields
}
MessagesResource provides methods to send and manage messages.
func (*MessagesResource) Delete ¶
func (r *MessagesResource) Delete(ctx context.Context, params DeleteMessageParams) (*DeleteResult, error)
Delete deletes a message sent by this bot or user.
func (*MessagesResource) Edit ¶
func (r *MessagesResource) Edit(ctx context.Context, params EditMessageParams) (*EditMessageResult, error)
Edit edits the text or inline keyboard of a message sent by this bot or user.
func (*MessagesResource) Send ¶
func (r *MessagesResource) Send(ctx context.Context, params SendMessageParams) (*SendResult, error)
Send sends a text message, with optional inline buttons or keyboard.
func (*MessagesResource) SendAudio ¶
func (r *MessagesResource) SendAudio(ctx context.Context, params SendMediaParams) (*SendMediaResult, error)
SendAudio sends an audio file.
func (*MessagesResource) SendCarousel ¶
func (r *MessagesResource) SendCarousel(ctx context.Context, params SendCarouselParams) (*SendCarouselResult, error)
SendCarousel sends a product or card carousel.
func (*MessagesResource) SendDocument ¶
func (r *MessagesResource) SendDocument(ctx context.Context, params SendMediaParams) (*SendMediaResult, error)
SendDocument sends a document or generic file.
func (*MessagesResource) SendPhoto ¶
func (r *MessagesResource) SendPhoto(ctx context.Context, params SendMediaParams) (*SendMediaResult, error)
SendPhoto sends a photo (image file).
func (*MessagesResource) SendTyping ¶
func (r *MessagesResource) SendTyping(ctx context.Context, params SendTypingParams) (*TypingResult, error)
SendTyping shows or hides the typing indicator in a chat. IsTyping defaults to true when not set.
func (*MessagesResource) SendVideo ¶
func (r *MessagesResource) SendVideo(ctx context.Context, params SendMediaParams) (*SendMediaResult, error)
SendVideo sends a video file.
type Participant ¶
type Participant struct {
ID string `json:"id"`
Nom string `json:"nom"`
IsBot bool `json:"is_bot"`
IsPremium bool `json:"is_premium"`
AvatarURL *string `json:"avatar_url"`
}
Participant is a member of a chat.
type PrivacySetting ¶
type PrivacySetting string
PrivacySetting is a user privacy configuration value.
const ( PrivacyEveryone PrivacySetting = "everyone" PrivacyContacts PrivacySetting = "contacts" PrivacyNobody PrivacySetting = "nobody" )
type ReplyKeyboard ¶
type ReplyKeyboard struct {
Keyboard [][]string `json:"keyboard"`
}
ReplyKeyboard renders a custom reply keyboard below the input field.
type ReplySnapshot ¶
type ReplySnapshot struct {
MessageID int64 `json:"message_id"`
SenderID *string `json:"sender_id"`
Type MessageType `json:"type"`
Text *string `json:"text"`
MediaID *string `json:"media_id"`
}
ReplySnapshot is a lightweight snapshot of the message being replied to.
type ScrollKeyboard ¶
type ScrollKeyboard struct {
ScrollKeyboard []string `json:"scroll_keyboard"`
}
ScrollKeyboard renders a horizontally scrollable keyboard.
type SendCarouselParams ¶
type SendCarouselParams struct {
ChatID int64 `json:"chat_id"`
Text string `json:"text,omitempty"`
Carousel []CarouselCard `json:"carousel"`
QuickReplyButtons []string `json:"quick_reply_buttons,omitempty"`
}
SendCarouselParams holds the parameters for sending a product carousel.
type SendCarouselResult ¶
type SendCarouselResult struct {
MessageID int64 `json:"message_id"`
CreatedAt int64 `json:"created_at"`
Type string `json:"type"`
}
SendCarouselResult is returned after sending a carousel.
type SendMediaParams ¶
type SendMediaParams struct {
ChatID int64
File FileInput
Caption string
ReplyToID *int64
DeletePrevious bool
// ReplyMarkup accepts InlineKeyboard, ReplyKeyboard, or ScrollKeyboard.
ReplyMarkup any
}
SendMediaParams holds the parameters for sending a photo, video, document, or audio.
type SendMediaResult ¶
type SendMediaResult struct {
MessageID int64 `json:"message_id"`
CreatedAt int64 `json:"created_at"`
MediaID string `json:"media_id"`
}
SendMediaResult is returned after sending a media message.
type SendMessageParams ¶
type SendMessageParams struct {
ChatID int64 `json:"chat_id"`
Text string `json:"text"`
// ReplyMarkup accepts InlineKeyboard, ReplyKeyboard, or ScrollKeyboard.
ReplyMarkup any `json:"reply_markup,omitempty"`
ReplyToID *int64 `json:"reply_to_id,omitempty"`
DeletePrevious bool `json:"delete_previous,omitempty"`
}
SendMessageParams holds the parameters for sending a text message.
type SendResult ¶
SendResult is returned after sending a text message.
type SendTypingParams ¶
type SendTypingParams struct {
ChatID int64 `json:"chat_id"`
IsTyping *bool `json:"is_typing,omitempty"`
}
SendTypingParams holds the parameters for the typing indicator. IsTyping defaults to true when nil (show indicator). Set to false to hide it.
type SetWebhookParams ¶
SetWebhookParams holds the parameters for registering a webhook.
type TypingResult ¶
type TypingResult struct {
Typing bool `json:"typing"`
}
TypingResult is returned by the sendTyping endpoint.
type User ¶
type User struct {
// Messages provides methods to send and manage messages.
Messages *MessagesResource
// Chats provides methods to list and iterate over chats.
Chats *ChatsResource
// Webhooks provides methods to manage webhooks.
Webhooks *WebhooksResource
// Profile provides access to your own profile.
Profile *UserProfileResource
// contains filtered or unexported fields
}
User is the Kappela personal automation client. Authenticate with a personal API key (sk_...) to send messages and receive events as yourself.
Example:
me := kappelas.NewUser("sk_...")
me.OnMessage(func(msg *kappelas.Message) {
fmt.Println("New message:", msg.Text)
})
me.Start()
select {}
func NewUser ¶
func NewUser(apiKey string, opts ...UserOption) *User
NewUser creates a User authenticated with the given personal API key.
func (*User) HandleWebhook ¶
HandleWebhook processes a webhook payload sent by Kappela to your server.
Example (net/http):
http.HandleFunc("/kappela-webhook", func(w http.ResponseWriter, r *http.Request) {
body, _ := io.ReadAll(r.Body)
me.HandleWebhook(body)
w.WriteHeader(http.StatusOK)
})
func (*User) OnCallbackQuery ¶
func (u *User) OnCallbackQuery(h func(*CallbackQuery))
OnCallbackQuery registers a handler called when a user clicks an inline button.
func (*User) OnConnected ¶
func (u *User) OnConnected(h func())
OnConnected registers a handler called when the WebSocket connects (or reconnects).
func (*User) OnDisconnected ¶
OnDisconnected registers a handler called when the WebSocket disconnects.
type UserOption ¶
type UserOption func(*userConfig)
UserOption configures a User.
func WithUserBaseURL ¶
func WithUserBaseURL(u string) UserOption
WithUserBaseURL overrides the API base URL for a User client.
func WithUserMaxRetries ¶
func WithUserMaxRetries(n int) UserOption
WithUserMaxRetries sets the maximum number of HTTP retry attempts for a User client.
func WithUserTimeout ¶
func WithUserTimeout(d time.Duration) UserOption
WithUserTimeout sets the HTTP request timeout for a User client.
func WithUserWSMaxRetries ¶
func WithUserWSMaxRetries(n int) UserOption
WithUserWSMaxRetries sets the maximum WebSocket reconnect attempts for a User client.
type UserProfile ¶
type UserProfile struct {
ID string `json:"id"`
Username string `json:"username"`
Nom string `json:"nom"`
IsBot bool `json:"is_bot"`
IsPremium bool `json:"is_premium"`
AvatarURL *string `json:"avatar_url"`
AllowGroupAdd PrivacySetting `json:"allow_group_add"`
AllowCalls PrivacySetting `json:"allow_calls"`
}
UserProfile is the profile returned for a personal account.
type UserProfileResource ¶
type UserProfileResource struct {
// contains filtered or unexported fields
}
UserProfileResource provides access to the user's own profile.
func (*UserProfileResource) Get ¶
func (r *UserProfileResource) Get(ctx context.Context) (*UserProfile, error)
Get returns your own profile.
type WebhookDeleteResult ¶
type WebhookDeleteResult struct {
Active bool `json:"active"`
}
WebhookDeleteResult is returned after removing a webhook.
type WebhookInfo ¶
type WebhookInfo struct {
Active bool `json:"active"`
URL *string `json:"url"`
CreatedAt *int64 `json:"created_at"`
}
WebhookInfo describes the current webhook configuration.
type WebhookSetResult ¶
WebhookSetResult is returned after registering a webhook.
type WebhooksResource ¶
type WebhooksResource struct {
// contains filtered or unexported fields
}
WebhooksResource provides methods to manage webhooks.
func (*WebhooksResource) Delete ¶
func (r *WebhooksResource) Delete(ctx context.Context) (*WebhookDeleteResult, error)
Delete removes the webhook. Events will no longer be delivered via HTTP POST.
func (*WebhooksResource) GetInfo ¶
func (r *WebhooksResource) GetInfo(ctx context.Context) (*WebhookInfo, error)
GetInfo returns the current webhook status and URL.
func (*WebhooksResource) Set ¶
func (r *WebhooksResource) Set(ctx context.Context, params SetWebhookParams) (*WebhookSetResult, error)
Set registers a webhook URL. Use this for production deployments.